-
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Labels
Description
Describe the bug
I have a ruleset with Generic.Formatting.SpaceBeforeCast and Generic.WhiteSpace.ArbitraryParenthesesSpacing and they are entering what appears to be an infinite loop due to conflicting with each other while running phpcbf
.
Code sample
<?php
$thing = (rand(1, 100) % 2) ? ((string)$something) : 'else';
Custom ruleset
<?xml version="1.0"?>
<ruleset name="My Custom Standard">
<description>If you are using a custom ruleset, please enter the relevant part here.</description>
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing" />
<rule ref="Generic.Formatting.SpaceBeforeCast" />
</ruleset>
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcbf -vv test.php ...
- See error message displayed
Output
Processing ruleset /home/username/public_html/my-project/.phpcs.xml
=> set config value ignore_warnings_on_exit: 1
Processing rule "Generic.Formatting.SpaceBeforeCast"
=> /home/username/public_html/my-project/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Formatting/SpaceBeforeCastSniff.php
Processing rule "Generic.WhiteSpace.ArbitraryParenthesesSpacing"
=> /home/username/public_html/my-project/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php
=> set command line value --extensions=php
=> set command line value --basepath=.
=> Ruleset processing complete; included 2 sniffs and excluded 0
Creating file list... DONE (1 files in queue)
Changing into directory .
Processing test.php
*** START PHP TOKENIZING ***
Process token [0]: T_OPEN_TAG => <?php\n
Process token [1]: T_WHITESPACE => \n
Process token [2]: T_VARIABLE => $thing
Process token [3]: T_WHITESPACE => ·
Process token 4 : T_EQUAL => =
Process token [5]: T_WHITESPACE => ·
Process token 6 : T_OPEN_PARENTHESIS => (
Process token [7]: T_STRING => rand
Process token 8 : T_OPEN_PARENTHESIS => (
Process token [9]: T_LNUMBER => 1
Process token 10 : T_COMMA => ,
Process token [11]: T_WHITESPACE => ·
Process token [12]: T_LNUMBER => 100
Process token 13 : T_CLOSE_PARENTHESIS => )
Process token [14]: T_WHITESPACE => ·
Process token 15 : T_MODULUS => %
Process token [16]: T_WHITESPACE => ·
Process token [17]: T_LNUMBER => 2
Process token 18 : T_CLOSE_PARENTHESIS => )
Process token [19]: T_WHITESPACE => ·
Process token 20 : T_NONE => ?
* token 20 changed from ? to T_INLINE_THEN
Process token [21]: T_WHITESPACE => ·
Process token 22 : T_OPEN_PARENTHESIS => (
Process token [23]: T_STRING_CAST => (string)
Process token [24]: T_VARIABLE => $something
Process token 25 : T_CLOSE_PARENTHESIS => )
Process token [26]: T_WHITESPACE => ·
Process token 27 : T_COLON => :
* token changed from T_COLON to T_INLINE_ELSE
Process token [28]: T_WHITESPACE => ·
Process token [29]: T_CONSTANT_ENCAPSED_STRING => 'else'
Process token 30 : T_SEMICOLON => ;
Process token [31]: T_WHITESPACE => \n
*** END PHP TOKENIZING ***
*** START TOKEN MAP ***
=> Found unowned parenthesis opener at 6
=> Found unowned parenthesis opener at 8
=> Found unowned parenthesis closer at 13 for 8
=> Found unowned parenthesis closer at 18 for 6
=> Found unowned parenthesis opener at 22
=> Found unowned parenthesis closer at 25 for 22
*** END TOKEN MAP ***
*** START SCOPE MAP ***
*** END SCOPE MAP ***
*** START LEVEL MAP ***
Process token 0 on line 1 [col:1;len:5;lvl:0;]: T_OPEN_TAG => <?php\n
Process token 1 on line 2 [col:1;len:0;lvl:0;]: T_WHITESPACE => \n
Process token 2 on line 3 [col:1;len:6;lvl:0;]: T_VARIABLE => $thing
Process token 3 on line 3 [col:7;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 4 on line 3 [col:8;len:1;lvl:0;]: T_EQUAL => =
Process token 5 on line 3 [col:9;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 6 on line 3 [col:10;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 7 on line 3 [col:11;len:4;lvl:0;]: T_STRING => rand
Process token 8 on line 3 [col:15;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 9 on line 3 [col:16;len:1;lvl:0;]: T_LNUMBER => 1
Process token 10 on line 3 [col:17;len:1;lvl:0;]: T_COMMA => ,
Process token 11 on line 3 [col:18;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 12 on line 3 [col:19;len:3;lvl:0;]: T_LNUMBER => 100
Process token 13 on line 3 [col:22;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 14 on line 3 [col:23;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 15 on line 3 [col:24;len:1;lvl:0;]: T_MODULUS => %
Process token 16 on line 3 [col:25;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 17 on line 3 [col:26;len:1;lvl:0;]: T_LNUMBER => 2
Process token 18 on line 3 [col:27;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 19 on line 3 [col:28;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 20 on line 3 [col:29;len:1;lvl:0;]: T_INLINE_THEN => ?
Process token 21 on line 3 [col:30;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 22 on line 3 [col:31;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 23 on line 3 [col:32;len:8;lvl:0;]: T_STRING_CAST => (string)
Process token 24 on line 3 [col:40;len:10;lvl:0;]: T_VARIABLE => $something
Process token 25 on line 3 [col:50;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 26 on line 3 [col:51;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 27 on line 3 [col:52;len:1;lvl:0;]: T_INLINE_ELSE => :
Process token 28 on line 3 [col:53;len:1;lvl:0;]: T_WHITESPACE => ·
Process token 29 on line 3 [col:54;len:6;lvl:0;]: T_CONSTANT_ENCAPSED_STRING => 'else'
Process token 30 on line 3 [col:60;len:1;lvl:0;]: T_SEMICOLON => ;
Process token 31 on line 3 [col:61;len:0;lvl:0;]: T_WHITESPACE => \n
*** END LEVEL MAP ***
*** START ADDITIONAL PHP PROCESSING ***
*** END ADDITIONAL PHP PROCESSING ***
[PHP => 32 tokens in 3 lines]...
DONE in 10ms (1 fixable violations)
=> Fixing file: 1/1 violations remaining
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 1 pass]...
* fixed 1 violations, starting loop 2 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 2 passes]...
* fixed 1 violations, starting loop 3 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 1; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 3 passes]...
* fixed 0 violations, starting loop 4 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 4 passes]...
* fixed 1 violations, starting loop 5 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 3; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 5 passes]...
* fixed 0 violations, starting loop 6 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 6 passes]...
* fixed 1 violations, starting loop 7 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 5; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 7 passes]...
* fixed 0 violations, starting loop 8 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 8 passes]...
* fixed 1 violations, starting loop 9 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 7; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 9 passes]...
* fixed 0 violations, starting loop 10 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 10 passes]...
* fixed 1 violations, starting loop 11 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 9; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 11 passes]...
* fixed 0 violations, starting loop 12 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 12 passes]...
* fixed 1 violations, starting loop 13 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 11; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 13 passes]...
* fixed 0 violations, starting loop 14 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 14 passes]...
* fixed 1 violations, starting loop 15 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 13; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 15 passes]...
* fixed 0 violations, starting loop 16 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 16 passes]...
* fixed 1 violations, starting loop 17 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 15; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 17 passes]...
* fixed 0 violations, starting loop 18 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 18 passes]...
* fixed 1 violations, starting loop 19 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 17; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 19 passes]...
* fixed 0 violations, starting loop 20 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 20 passes]...
* fixed 1 violations, starting loop 21 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 19; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 21 passes]...
* fixed 0 violations, starting loop 22 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 22 passes]...
* fixed 1 violations, starting loop 23 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 21; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 23 passes]...
* fixed 0 violations, starting loop 24 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 24 passes]...
* fixed 1 violations, starting loop 25 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 23; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 25 passes]...
* fixed 0 violations, starting loop 26 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 26 passes]...
* fixed 1 violations, starting loop 27 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 25; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 27 passes]...
* fixed 0 violations, starting loop 28 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 28 passes]...
* fixed 1 violations, starting loop 29 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 27; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 29 passes]...
* fixed 0 violations, starting loop 30 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 30 passes]...
* fixed 1 violations, starting loop 31 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 29; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 31 passes]...
* fixed 0 violations, starting loop 32 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 32 passes]...
* fixed 1 violations, starting loop 33 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 31; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 33 passes]...
* fixed 0 violations, starting loop 34 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 34 passes]...
* fixed 1 violations, starting loop 35 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 33; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 35 passes]...
* fixed 0 violations, starting loop 36 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 36 passes]...
* fixed 1 violations, starting loop 37 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 35; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 37 passes]...
* fixed 0 violations, starting loop 38 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 38 passes]...
* fixed 1 violations, starting loop 39 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 37; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 39 passes]...
* fixed 0 violations, starting loop 40 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 40 passes]...
* fixed 1 violations, starting loop 41 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 39; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 41 passes]...
* fixed 0 violations, starting loop 42 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 42 passes]...
* fixed 1 violations, starting loop 43 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 41; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 43 passes]...
* fixed 0 violations, starting loop 44 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 44 passes]...
* fixed 1 violations, starting loop 45 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 43; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 45 passes]...
* fixed 0 violations, starting loop 46 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 46 passes]...
* fixed 1 violations, starting loop 47 *
**** Generic.Formatting.SpaceBeforeCast:53 has possible conflict with another sniff on loop 45; caused by the following change ****
**** replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 47 passes]...
* fixed 0 violations, starting loop 48 *
Generic.Formatting.SpaceBeforeCast:53 replaced token 23 (T_STRING_CAST on line 3) "(string)" => "·(string)"
=> Fixing file: 1/1 violations remaining [made 48 passes]...
* fixed 1 violations, starting loop 49 *
**** Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 has possible conflict with another sniff on loop 47; caused by the following change ****
**** replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 49 passes]...
* fixed 0 violations, starting loop 50 *
Generic.WhiteSpace.ArbitraryParenthesesSpacing:176 replaced token 23 (T_WHITESPACE on line 3) "·(string)" => "(string)"
=> Fixing file: 1/1 violations remaining [made 50 passes]...
* fixed 1 violations, starting loop 51 *
*** Reached maximum number of loops with 1 violations left unfixed ***
Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).
ERROR in 60ms
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
----------------------------------------------------------------------
Time: 88ms; Memory: 4MB
Expected behavior
At the very least, one rule should trump the other and then perhaps an additional pass of phpcbf
might need to be ran.
Versions (please complete the following information)
Operating System | RHEL 8 |
PHP version | 8.3.21 |
PHP_CodeSniffer version | 3.13.0 |
Standard | Custom rules |
Install type | Composer (global/local) |
Additional context
N/A
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.