Commit 432e5b9
committed
Squiz/FunctionDeclarationArgumentSpacing: improve
The fixer for the `SpacingAfterVariadic` 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 variadic 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:190 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:190 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:190 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:190 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:190
Q: Squiz.Functions.FunctionDeclarationArgumentSpacing:192 replaced token 9 (T_WHITESPACE on line 4) "\n\n" => "\n"
Q: Squiz.Functions.FunctionDeclarationArgumentSpacing:192 replaced token 10 (T_WHITESPACE on line 5) "\n " => " "
Q: Squiz.Functions.FunctionDeclarationArgumentSpacing:192 replaced token 11 (T_WHITESPACE on line 6) " $param" => "$param"
A: Squiz.Functions.FunctionDeclarationArgumentSpacing:195 replaced token 9 (T_WHITESPACE on line 4) "\n\n" => "\n"
A: Squiz.Functions.FunctionDeclarationArgumentSpacing:195 replaced token 10 (T_WHITESPACE on line 5) "\n " => " "
A: Squiz.Functions.FunctionDeclarationArgumentSpacing:195 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>SpacingAfterVariadic fixer1 parent 1700601 commit 432e5b9
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 | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | | - | |
| 198 | + | |
194 | 199 | | |
195 | 200 | | |
196 | 201 | | |
| |||
0 commit comments