Closed
Description
$ composer show | grep -P 'coding-standard|php_codesniffer'
doctrine/coding-standard 7.0.2 The Doctrine Coding Standard is a ...
slevomat/coding-standard 6.1.5 Slevomat Coding Standard for PHP_C...
squizlabs/php_codesniffer 3.5.4 PHP_CodeSniffer tokenizes PHP, Jav...
Consider the following code example:
<?php
declare(strict_types=1);
$foo =
[
'bar' =>
[
],
];
The following violations are reported:
------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------
8 | ERROR | [x] Empty array declaration must have no space between the parentheses
| | (Squiz.Arrays.ArrayDeclaration.SpaceInEmptyArray)
9 | ERROR | [x] Array close brace not indented correctly; expected 3 spaces but found 4
| | (Generic.Arrays.ArrayIndent.CloseBraceIncorrect)
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------
An attempt to auto-fix the file fails:
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
test.php FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------
And introduces another violation (both lines 8 and 9 are now indented using 3 spaces instead of 4):
<?php
declare(strict_types=1);
$foo =
[
'bar' =>
[
],
];
An attempt to fix the modified file also fails. Note that fixing the file using --standard=Squiz
(as per the reported violations) succeeds:
$ phpcbf --standard=Squiz test.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
/home/morozov/Projects/dbal/test.php 4 1
----------------------------------------------------------------------
A TOTAL OF 4 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
<?php
declare(strict_types=1);
$foo = [
'bar' => [],
];