Skip to content

Commit 301a791

Browse files
committed
Add functionality
1 parent b35457e commit 301a791

File tree

1 file changed

+54
-20
lines changed

1 file changed

+54
-20
lines changed

src/Console/FixCommand.php

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ class FixCommand extends Command
3939
*/
4040
protected $longVersion;
4141

42+
/**
43+
*
44+
* @var Fixer
45+
*/
46+
protected $fixerService;
47+
48+
4249
public function __construct()
4350
{
4451
parent::__construct();
@@ -50,15 +57,59 @@ public function __construct()
5057
$this->longVersion = $this->fixerApplication->getLongVersion();
5158
}
5259

60+
61+
5362
public function handle()
5463
{
55-
$this->setVerbosity($this->output->getVerbosity());
64+
try {
65+
$this->verbocityAndValidation();
66+
} catch (InvalidConfigurationException $exception) {
67+
$this->error($exception->getMessage());
68+
return 1;
69+
}
70+
71+
$this->writePreamble();
72+
73+
$this->fixerService->fixFiles();
74+
$this->fixerService->printLegend();
75+
$this->fixerService->report($this->verbosity, $this->output);
5676

77+
$this->info('Completed');
78+
}
79+
80+
protected function verbocityAndValidation()
81+
{
82+
$this->setVerbosity($this->output->getVerbosity());
5783
if (null !== $this->option('config') && null !== $this->option('rules')) {
5884
throw new InvalidConfigurationException('Passing both `--config` and `--rules` options is not allowed.');
5985
}
86+
}
6087

61-
$cli_input = [
88+
protected function getFixerService(): Fixer
89+
{
90+
if ($this->fixerService === null) {
91+
$this->fixerService = new Fixer($this->output, $this->composeCliInput());
92+
}
93+
94+
return $this->fixerService;
95+
}
96+
protected function writePreamble()
97+
{
98+
if (OutputInterface::VERBOSITY_VERBOSE <= $this->verbosity) {
99+
$this->info($this->longVersion);
100+
$this->writeln($this->getFixerService()->getPhpRuntimeMessage());
101+
}
102+
103+
$this->writeln($this->getFixerService()->getLoadedConfigMessage());
104+
105+
if ($this->getFixerService()->isUsingCache() && $this->getFixerService()->cacheFileExists()) {
106+
$this->writeln($this->getFixerService()->getCacheFileMessage());
107+
}
108+
}
109+
110+
protected function composeCliInput()
111+
{
112+
return [
62113
'allow-risky' => $this->option('allow-risky'),
63114
'config' => $this->option('config'),
64115
'dry-run' => $this->option('dry-run'),
@@ -73,25 +124,8 @@ public function handle()
73124
'verbosity' => $this->verbosity,
74125
'show-progress' => $this->option('show-progress'),
75126
];
76-
77-
$fixerService = new Fixer($this->input, $this->output, $cli_input);
78-
79-
if (OutputInterface::VERBOSITY_VERBOSE <= $this->verbosity) {
80-
$this->info($this->longVersion);
81-
$this->writeln($fixerService->getPhpRuntimeMessage());
82-
}
83-
84-
$this->writeln($fixerService->getLoadedConfigMessage());
85-
86-
if ($fixerService->isUsingCache() && $fixerService->cacheFileExists()) {
87-
$this->writeln($fixerService->getCacheFileMessage());
88-
}
89-
90-
91-
$this->info('Completed');
92127
}
93-
94-
public function writeln($messages, int $type = SymfonyStyle::OUTPUT_NORMAL)
128+
protected function writeln($messages, int $type = SymfonyStyle::OUTPUT_NORMAL)
95129
{
96130
$this->output->writeln($messages, $type);
97131
}

0 commit comments

Comments
 (0)