Commit 30319c4
committed
Squiz/FunctionDeclarationArgumentSpacing: improve
The fixer for the `SpacingAfterReference` error code would only handle one whitespace token at a time, which is inefficient and could also lead to more complex fixer conflicts.
This commit changes the fixer to handle all whitespace tokens after a reference token in one go.
For the test code sample added in the previous commit, this means the difference between the fixer needing 5 loops (including one skipped loop due to possible conflicts) versus 2 loops.
<details>
<summary>Old:</summary>
```
=> Fixing file: 1/1 violations remaining
Squiz.Functions.FunctionDeclarationArgumentSpacing:164 replaced token 9 (T_WHITESPACE on line 4) "\n\n" => "\n"
=> Fixing file: 1/1 violations remaining [made 1 pass]...
* fixed 1 violations, starting loop 2 *
Squiz.Functions.FunctionDeclarationArgumentSpacing:164 replaced token 9 (T_WHITESPACE on line 4) "\n " => " "
=> Fixing file: 1/1 violations remaining [made 2 passes]...
* fixed 1 violations, starting loop 3 *
**** Squiz.Functions.FunctionDeclarationArgumentSpacing:164 has possible conflict with another sniff on loop 1; caused by the following change ****
**** replaced token 9 (T_WHITESPACE on line 4) " $param" => "$param" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/1 violations remaining [made 3 passes]...
* fixed 0 violations, starting loop 4 *
Squiz.Functions.FunctionDeclarationArgumentSpacing:164 replaced token 9 (T_WHITESPACE on line 4) " $param" => "$param"
=> Fixing file: 1/1 violations remaining [made 4 passes]...
* fixed 1 violations, starting loop 5 *
=> Fixing file: 0/1 violations remaining [made 5 passes]...
```
</details>
<details>
<summary>New:</summary>
```
=> Fixing file: 1/1 violations remaining
=> Changeset started by Squiz.Functions.FunctionDeclarationArgumentSpacing:164
Q: Squiz.Functions.FunctionDeclarationArgumentSpacing:166 replaced token 9 (T_WHITESPACE on line 4) "\n \n" => " \n"
Q: Squiz.Functions.FunctionDeclarationArgumentSpacing:166 replaced token 10 (T_WHITESPACE on line 5) " \n " => " "
Q: Squiz.Functions.FunctionDeclarationArgumentSpacing:166 replaced token 11 (T_WHITESPACE on line 6) " $param" => "$param"
A: Squiz.Functions.FunctionDeclarationArgumentSpacing:169 replaced token 9 (T_WHITESPACE on line 4) "\n \n" => " \n"
A: Squiz.Functions.FunctionDeclarationArgumentSpacing:169 replaced token 10 (T_WHITESPACE on line 5) " \n " => " "
A: Squiz.Functions.FunctionDeclarationArgumentSpacing:169 replaced token 11 (T_WHITESPACE on line 6) " $param" => "$param"
=> Changeset ended: 3 changes applied
=> Fixing file: 3/1 violations remaining [made 1 pass]...
* fixed 3 violations, starting loop 2 *
=> Fixing file: 0/1 violations remaining [made 2 passes]...
```
</details>SpacingAfterReference fixer1 parent 399b1b3 commit 30319c4
File tree
1 file changed
+7
-2
lines changed- src/Standards/Squiz/Sniffs/Functions
1 file changed
+7
-2
lines changedLines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
166 | 171 | | |
167 | | - | |
| 172 | + | |
168 | 173 | | |
169 | 174 | | |
170 | 175 | | |
| |||
0 commit comments