Skip to content

Commit

Permalink
Merge pull request #115 from mmarynich/feature/fix-phpcsfixer
Browse files Browse the repository at this point in the history
Take into account the particularities of PHP-CS-FIXER V2
  • Loading branch information
bruli authored Sep 20, 2018
2 parents 15ad85a + 105b4ab commit b9abd9b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public function __construct(OutputInterface $output, PhpCsFixerToolProcessorInte
private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage)
{
if (true === $psr0) {
$this->executeTool($files, 'PSR0', $options, $errorMessage);
$this->executeTool($files, '@PSR0', $options, $errorMessage);
}

if (true === $psr1) {
$this->executeTool($files, 'PSR1', $options, $errorMessage);
$this->executeTool($files, '@PSR1', $options, $errorMessage);
}

if (true === $psr2) {
$this->executeTool($files, 'PSR2', $options, $errorMessage);
$this->executeTool($files, '@PSR2', $options, $errorMessage);
}

if (true === $symfony) {
$this->executeTool($files, 'SYMFONY', $options, $errorMessage);
$this->executeTool($files, '@Symfony', $options, $errorMessage);
}
}

Expand All @@ -71,7 +71,9 @@ private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options,
*/
private function executeTool(array $files, $level, $options, $errorMessage)
{
$outputMessage = new PreCommitOutputWriter(sprintf('Checking %s code style with PHP-CS-FIXER', $level));
$outputMessage = new PreCommitOutputWriter(
sprintf('Checking %s code style with PHP-CS-FIXER', str_replace('@', '', $level))
);
$this->output->write($outputMessage->getMessage());

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ private function processTool($file, $level, $options)
$arguments = [
'php',
$this->toolPathFinder->find('php-cs-fixer'),
'--dry-run',
'fix',
$file,
'--level='.$level,
'--dry-run',
'--rules='.$level,
];

if (null !== $options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function itShouldThrowsException()
$errors = null;
foreach ($phpFiles as $file) {
$errorText = 'ERROR';
$this->shouldProcessPhpCsFixerTool($file, 'PSR0', $phpCsFixerOptions->value(), $errorText);
$this->shouldProcessPhpCsFixerTool($file, '@PSR0', $phpCsFixerOptions->value(), $errorText);
$errors .= $errorText;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ public function itShouldWorksFine()
$this->shouldWriteOutput($outputMessagePsr0->getMessage());

foreach ($phpFiles as $file) {
$this->shouldProcessPhpCsFixerTool($file, 'PSR0', $phpCsFixerOptions->value(), null);
$this->shouldProcessPhpCsFixerTool($file, '@PSR0', $phpCsFixerOptions->value(), null);
}

$this->shouldWriteLnOutput($outputMessagePsr0->getSuccessfulMessage());
Expand All @@ -87,7 +87,7 @@ public function itShouldWorksFine()
$this->shouldWriteOutput($outputMessagePsr1->getMessage());

foreach ($phpFiles as $file) {
$this->shouldProcessPhpCsFixerTool($file, 'PSR1', $phpCsFixerOptions->value(), null);
$this->shouldProcessPhpCsFixerTool($file, '@PSR1', $phpCsFixerOptions->value(), null);
}

$this->shouldWriteLnOutput($outputMessagePsr1->getSuccessfulMessage());
Expand All @@ -96,16 +96,16 @@ public function itShouldWorksFine()
$this->shouldWriteOutput($outputMessagePsr2->getMessage());

foreach ($phpFiles as $file) {
$this->shouldProcessPhpCsFixerTool($file, 'PSR2', $phpCsFixerOptions->value(), null);
$this->shouldProcessPhpCsFixerTool($file, '@PSR2', $phpCsFixerOptions->value(), null);
}

$this->shouldWriteLnOutput($outputMessagePsr2->getSuccessfulMessage());

$outputMessageSymfony = new PreCommitOutputWriter('Checking SYMFONY code style with PHP-CS-FIXER');
$outputMessageSymfony = new PreCommitOutputWriter('Checking Symfony code style with PHP-CS-FIXER');
$this->shouldWriteOutput($outputMessageSymfony->getMessage());

foreach ($phpFiles as $file) {
$this->shouldProcessPhpCsFixerTool($file, 'SYMFONY', $phpCsFixerOptions->value(), null);
$this->shouldProcessPhpCsFixerTool($file, '@Symfony', $phpCsFixerOptions->value(), null);
}

$this->shouldWriteLnOutput($outputMessageSymfony->getSuccessfulMessage());
Expand Down

0 comments on commit b9abd9b

Please sign in to comment.