From 4b6dbfbd935e8cd713087a16caa6bc7d7e031559 Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Wed, 19 Sep 2018 12:15:33 +0200 Subject: [PATCH 1/6] Interchange command name and parameters --- .../PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php b/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php index 133e14d..f2a19c1 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php @@ -49,9 +49,9 @@ private function processTool($file, $level, $options) $arguments = [ 'php', $this->toolPathFinder->find('php-cs-fixer'), - '--dry-run', 'fix', $file, + '--dry-run', '--level='.$level, ]; From 0243011a71872c72ecb0056099bfcbfd19845a4e Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Wed, 19 Sep 2018 12:18:23 +0200 Subject: [PATCH 2/6] Option "--level" was replaced by "--rules" in v2 of PHP-CS-Fixer Error: The "--level" option does not exist. --- .../PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php b/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php index f2a19c1..2a50578 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php @@ -52,7 +52,7 @@ private function processTool($file, $level, $options) 'fix', $file, '--dry-run', - '--level='.$level, + '--rules='.$level, ]; if (null !== $options) { From 054c5581587be9b872fb34793b56adcc350dd7a6 Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Wed, 19 Sep 2018 12:26:15 +0200 Subject: [PATCH 3/6] Names of coding standards should prefixed by "@" in v2 of PHP-CS-Fixer Error: In ConfigurationResolver.php line 755: The rules contain unknown fixers: "PSR2". --- .../PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php index a4caf4a..b69d231 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php @@ -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); } } From 950e8d31f4bbab526e4513d6c0b78388e9a1f887 Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Wed, 19 Sep 2018 12:30:13 +0200 Subject: [PATCH 4/6] Name of coding standard "SYMFONY" was renamed to "@Symfony" in v2 of PHP-CS-Fixer Error: In RuleSet.php line 375: Set "@SYMFONY" does not exist. --- .../PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php index b69d231..8a7b72f 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php @@ -57,7 +57,7 @@ private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, } if (true === $symfony) { - $this->executeTool($files, '@SYMFONY', $options, $errorMessage); + $this->executeTool($files, '@Symfony', $options, $errorMessage); } } From 877cc5b12a4209d3ae7c5d63ea4c4a4834a8beea Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Wed, 19 Sep 2018 12:48:47 +0200 Subject: [PATCH 5/6] Fix output message for PHP-CS-FIXER --- .../PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php index 8a7b72f..8dd53e7 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php @@ -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 = []; From 105b4abf4f690c4d5ea59bbc28baeb56ea624a57 Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Wed, 19 Sep 2018 12:49:38 +0200 Subject: [PATCH 6/6] Update tests for PHP-CS-Fixer --- .../Tests/Behaviour/PhpCsFixerToolHandlerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php b/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php index 5d7c4f0..ff8ea5b 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php @@ -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; } @@ -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()); @@ -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()); @@ -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());