Skip to content

Commit e0f2ca7

Browse files
done
1 parent 0e8f7c1 commit e0f2ca7

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

src/CLI/Command/Check.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
110110
$useBaseline = (string) $input->getOption(self::USE_BASELINE_PARAM);
111111
$skipBaseline = (bool) $input->getOption(self::SKIP_BASELINE_PARAM);
112112
$ignoreBaselineLinenumbers = (bool) $input->getOption(self::IGNORE_BASELINE_LINENUMBERS_PARAM);
113+
$phpVersion = $input->getOption('target-php-version');
113114
$format = $input->getOption(self::FORMAT_PARAM);
114-
$onlyErrors = Printer::FORMAT_JSON === $format || Printer::FORMAT_GITLAB === $format;
115115

116116
// we write everything on STDERR apart from the list of violations which goes on STDOUT
117+
// this allows to pipe the output of this command to a file while showing output on the terminal
117118
$stdOut = $output;
118119
$output = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
119120

121+
/** @var string|null $phpVersion */
122+
$targetPhpVersion = TargetPhpVersion::create($phpVersion);
123+
124+
$progress = $verbose ? new DebugProgress($output) : new ProgressBarProgress($output);
125+
120126
if (true !== $skipBaseline && !$useBaseline && file_exists(self::DEFAULT_BASELINE_FILENAME)) {
121127
$useBaseline = self::DEFAULT_BASELINE_FILENAME;
122128
}
@@ -131,12 +137,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131137

132138
$generateBaseline = $input->getOption(self::GENERATE_BASELINE_PARAM);
133139

134-
/** @var string|null $phpVersion */
135-
$phpVersion = $input->getOption('target-php-version');
136-
$targetPhpVersion = TargetPhpVersion::create($phpVersion);
137-
138-
$progress = $verbose ? new DebugProgress($output) : new ProgressBarProgress($output);
139-
140140
$this->printHeadingLine($output);
141141

142142
$rulesFilename = $this->getConfigFilename($input);
@@ -148,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
148148
$this->readRules($config, $rulesFilename);
149149

150150
$runner = new Runner($stopOnFailure);
151-
$runner->run($config, $progress, $targetPhpVersion, $onlyErrors);
151+
$runner->run($config, $progress, $targetPhpVersion);
152152

153153
$violations = $runner->getViolations();
154154
$violations->sort();
@@ -255,8 +255,4 @@ private function getConfigFilename(InputInterface $input): string
255255

256256
return $filename;
257257
}
258-
259-
private function printNoViolationsDetectedMessage(OutputInterface $output, bool $onlyErrors = false, string $format = Printer::FORMAT_TEXT): void
260-
{
261-
}
262258
}

src/CLI/Runner.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,22 @@ public function __construct(bool $stopOnFailure = false)
3030
$this->parsingErrors = new ParsingErrors();
3131
}
3232

33-
public function run(Config $config, Progress $progress, TargetPhpVersion $targetPhpVersion, bool $onlyErrors): void
33+
public function run(Config $config, Progress $progress, TargetPhpVersion $targetPhpVersion): void
3434
{
3535
/** @var FileParser $fileParser */
3636
$fileParser = FileParserFactory::createFileParser($targetPhpVersion, $config->isParseCustomAnnotationsEnabled());
3737

3838
/** @var ClassSetRules $classSetRule */
3939
foreach ($config->getClassSetRules() as $classSetRule) {
40-
if (!$onlyErrors) {
41-
$progress->startFileSetAnalysis($classSetRule->getClassSet());
42-
}
40+
$progress->startFileSetAnalysis($classSetRule->getClassSet());
4341

4442
try {
45-
$this->check($classSetRule, $progress, $fileParser, $this->violations, $this->parsingErrors, $onlyErrors);
43+
$this->check($classSetRule, $progress, $fileParser, $this->violations, $this->parsingErrors);
4644
} catch (FailOnFirstViolationException $e) {
4745
return;
4846
}
4947

50-
if (!$onlyErrors) {
51-
$progress->endFileSetAnalysis($classSetRule->getClassSet());
52-
}
48+
$progress->endFileSetAnalysis($classSetRule->getClassSet());
5349
}
5450
}
5551

@@ -58,16 +54,13 @@ public function check(
5854
Progress $progress,
5955
Parser $fileParser,
6056
Violations $violations,
61-
ParsingErrors $parsingErrors,
62-
bool $onlyErrors = false
57+
ParsingErrors $parsingErrors
6358
): void {
6459
/** @var SplFileInfo $file */
6560
foreach ($classSetRule->getClassSet() as $file) {
6661
$fileViolations = new Violations();
6762

68-
if (!$onlyErrors) {
69-
$progress->startParsingFile($file->getRelativePathname());
70-
}
63+
$progress->startParsingFile($file->getRelativePathname());
7164

7265
$fileParser->parse($file->getContents(), $file->getRelativePathname());
7366
$parsedErrors = $fileParser->getParsingErrors();
@@ -91,9 +84,7 @@ public function check(
9184

9285
$violations->merge($fileViolations);
9386

94-
if (!$onlyErrors) {
95-
$progress->endParsingFile($file->getRelativePathname());
96-
}
87+
$progress->endParsingFile($file->getRelativePathname());
9788
}
9889
}
9990

0 commit comments

Comments
 (0)