laminas-coding-standard
laminas-coding-standard copied to clipboard
Generic.Arrays.ArrayIndent & Generic.WhiteSpace.ScopeIndent conflict
Bug Report
Q | A |
---|---|
Version(s) | 2.0.0rc1 |
Summary
phpcbf loops until attempts limit (50) with rules Generic.Arrays.ArrayIndent & Generic.WhiteSpace.ScopeIndent then failed to fix. On big sources failed on time limit (10min)
Current behavior
$./vendor/bin/phpcbf test.php
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
test.php FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------
How to reproduce
Minimal source to reproduce:
<?php
function test()
{
query('
INSERT INTO table (column)
VALUES (:value)
', [
'value' => $value,
]);
}
Expected behavior
No error (all other rules applied)
Verbose output fragment
$./vendor/bin/phpcbf test.php -vvvv
---START FILE CONTENT---
1|<?php
2|
3|function test()
4|{
5| query('
6| INSERT INTO table (column)
7| VALUES (:value)
8| ', [
9| 'value' => $value,
10| ]);
11|}
12|
--- END FILE CONTENT ---
**** Generic.Arrays.ArrayIndent:137 has possible conflict with another sniff on loop 45; caused by the following change ****
**** replaced token 29 (T_WHITESPACE on line 10) "····]" => "]" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/2 violations remaining [made 47 passes]... * fixed 0 violations, starting loop 48 *
---START FILE CONTENT---
1|<?php
2|
3|function test()
4|{
5| query('
6| INSERT INTO table (column)
7| VALUES (:value)
8| ', [
9| 'value' => $value,
10| ]);
11|}
12|
--- END FILE CONTENT ---
Generic.Arrays.ArrayIndent:137 replaced token 29 (T_WHITESPACE on line 10) "····]" => "]"
=> Fixing file: 1/2 violations remaining [made 48 passes]... * fixed 1 violations, starting loop 49 *
---START FILE CONTENT---
1|<?php
2|
3|function test()
4|{
5| query('
6| INSERT INTO table (column)
7| VALUES (:value)
8| ', [
9| 'value' => $value,
10|]);
11|}
12|
--- END FILE CONTENT ---
**** Generic.WhiteSpace.ScopeIndent:1476 has possible conflict with another sniff on loop 47; caused by the following change ****
**** replaced token 29 (T_CLOSE_SHORT_ARRAY on line 10) "]" => "····]" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/2 violations remaining [made 49 passes]... * fixed 0 violations, starting loop 50 *
---START FILE CONTENT---
1|<?php
2|
3|function test()
4|{
5| query('
6| INSERT INTO table (column)
7| VALUES (:value)
8| ', [
9| 'value' => $value,
10|]);
11|}
12|
--- END FILE CONTENT ---
Generic.WhiteSpace.ScopeIndent:1476 replaced token 29 (T_CLOSE_SHORT_ARRAY on line 10) "]" => "····]"
=> Fixing file: 1/2 violations remaining [made 50 passes]... * fixed 1 violations, starting loop 51 *
*** Reached maximum number of loops with 1 violations left unfixed ***
ERROR in 217ms
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
test.php FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------
Time: 292ms; Memory: 10MB
TBH, I wouldn't know how to fix it either
Thank you for reporting this issue. However this is not something we can fix. I've opened a phpcs issue with the info you provided: https://github.com/squizlabs/PHP_CodeSniffer/issues/2905
I've been finding a solution for this, but I haven't found one. I've been disabling several rules which conflict in this case but disabling them caused other issues. The only way to fix this was writing it differently:
<?php
function test()
{
query(
'
INSERT INTO table (column)
VALUES (:value)
',
[
'value' => $value,
]
);
}