Closed
Description
Originally, this issue was found when using the Doctrine Coding Standard but as it turned out in slevomat/coding-standard#913, it’s reproducible with PHP_CodeSniffer as well.
Consider the following code example and standard configuration:
<?php
$foo =
[
'bar' =>
[
],
];
<?xml version="1.0"?>
<ruleset>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="ignoreIndentationTokens" type="array">
<element value="T_COMMENT"/>
<element value="T_DOC_COMMENT_OPEN_TAG"/>
</property>
</properties>
</rule>
<rule ref="Generic.Arrays.ArrayIndent"/>
</ruleset>
The following violations are reported:
-----------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------
7 | ERROR | [x] Array close brace not indented correctly; expected 3 spaces but found 4
-----------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------
An attempt to auto-fix the file fails:
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
/home/morozov/Projects/dbal/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 6 and 7 are now indented using 3 spaces instead of 4):
<?php
$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
$foo = [
'bar' => [],
];