Skip to content

Commit b9abd9b

Browse files
authored
Merge pull request #115 from mmarynich/feature/fix-phpcsfixer
Take into account the particularities of PHP-CS-FIXER V2
2 parents 15ad85a + 105b4ab commit b9abd9b

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ public function __construct(OutputInterface $output, PhpCsFixerToolProcessorInte
4545
private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage)
4646
{
4747
if (true === $psr0) {
48-
$this->executeTool($files, 'PSR0', $options, $errorMessage);
48+
$this->executeTool($files, '@PSR0', $options, $errorMessage);
4949
}
5050

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

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

5959
if (true === $symfony) {
60-
$this->executeTool($files, 'SYMFONY', $options, $errorMessage);
60+
$this->executeTool($files, '@Symfony', $options, $errorMessage);
6161
}
6262
}
6363

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

7779
$errors = [];

src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ private function processTool($file, $level, $options)
4949
$arguments = [
5050
'php',
5151
$this->toolPathFinder->find('php-cs-fixer'),
52-
'--dry-run',
5352
'fix',
5453
$file,
55-
'--level='.$level,
54+
'--dry-run',
55+
'--rules='.$level,
5656
];
5757

5858
if (null !== $options) {

src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function itShouldThrowsException()
4444
$errors = null;
4545
foreach ($phpFiles as $file) {
4646
$errorText = 'ERROR';
47-
$this->shouldProcessPhpCsFixerTool($file, 'PSR0', $phpCsFixerOptions->value(), $errorText);
47+
$this->shouldProcessPhpCsFixerTool($file, '@PSR0', $phpCsFixerOptions->value(), $errorText);
4848
$errors .= $errorText;
4949
}
5050

@@ -78,7 +78,7 @@ public function itShouldWorksFine()
7878
$this->shouldWriteOutput($outputMessagePsr0->getMessage());
7979

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

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

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

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

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

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

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

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

111111
$this->shouldWriteLnOutput($outputMessageSymfony->getSuccessfulMessage());

0 commit comments

Comments
 (0)