• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPCSStandards / PHP_CodeSniffer / 13506314473

24 Feb 2025 07:34PM UTC coverage: 78.585% (+0.1%) from 78.468%
13506314473

Pull #812

github

web-flow
Merge 6ed9ac8b2 into bf2b64d00
Pull Request #812: Tests/Tokenizer: improve switch keyword tests

24737 of 31478 relevant lines covered (78.59%)

66.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.04
/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
1
<?php
2
/**
3
 * Ensure single and multi-line function declarations are defined correctly.
4
 *
5
 * @author    Greg Sherwood <gsherwood@squiz.net>
6
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
7
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
 */
9

10
namespace PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions;
11

12
use PHP_CodeSniffer\Files\File;
13
use PHP_CodeSniffer\Sniffs\Sniff;
14
use PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\OpeningFunctionBraceBsdAllmanSniff;
15
use PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\OpeningFunctionBraceKernighanRitchieSniff;
16
use PHP_CodeSniffer\Util\Tokens;
17

18
class FunctionDeclarationSniff implements Sniff
19
{
20

21
    /**
22
     * A list of tokenizers this sniff supports.
23
     *
24
     * @var array
25
     */
26
    public $supportedTokenizers = [
27
        'PHP',
28
        'JS',
29
    ];
30

31
    /**
32
     * The number of spaces code should be indented.
33
     *
34
     * @var integer
35
     */
36
    public $indent = 4;
37

38

39
    /**
40
     * Returns an array of tokens this test wants to listen for.
41
     *
42
     * @return array<int|string>
43
     */
44
    public function register()
3✔
45
    {
46
        return [
1✔
47
            T_FUNCTION,
3✔
48
            T_CLOSURE,
3✔
49
        ];
2✔
50

51
    }//end register()
52

53

54
    /**
55
     * Processes this test, when one of its tokens is encountered.
56
     *
57
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
58
     * @param int                         $stackPtr  The position of the current token
59
     *                                               in the stack passed in $tokens.
60
     *
61
     * @return void
62
     */
63
    public function process(File $phpcsFile, $stackPtr)
3✔
64
    {
65
        $tokens = $phpcsFile->getTokens();
3✔
66

67
        if (isset($tokens[$stackPtr]['parenthesis_opener']) === false
3✔
68
            || isset($tokens[$stackPtr]['parenthesis_closer']) === false
3✔
69
            || $tokens[$stackPtr]['parenthesis_opener'] === null
3✔
70
            || $tokens[$stackPtr]['parenthesis_closer'] === null
3✔
71
        ) {
1✔
72
            return;
×
73
        }
74

75
        $openBracket  = $tokens[$stackPtr]['parenthesis_opener'];
3✔
76
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
77

78
        if (strtolower($tokens[$stackPtr]['content']) === 'function') {
3✔
79
            // Must be one space after the FUNCTION keyword.
80
            if ($tokens[($stackPtr + 1)]['content'] === $phpcsFile->eolChar) {
3✔
81
                $spaces = 'newline';
3✔
82
            } else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
3✔
83
                $spaces = $tokens[($stackPtr + 1)]['length'];
3✔
84
            } else {
1✔
85
                $spaces = 0;
3✔
86
            }
87

88
            if ($spaces !== 1) {
3✔
89
                $error = 'Expected 1 space after FUNCTION keyword; %s found';
3✔
90
                $data  = [$spaces];
3✔
91
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterFunction', $data);
3✔
92
                if ($fix === true) {
3✔
93
                    if ($spaces === 0) {
3✔
94
                        $phpcsFile->fixer->addContent($stackPtr, ' ');
3✔
95
                    } else {
1✔
96
                        $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
3✔
97
                    }
98
                }
1✔
99
            }
1✔
100
        }//end if
1✔
101

102
        // Must be no space before the opening parenthesis. For closures, this is
103
        // enforced by the previous check because there is no content between the keywords
104
        // and the opening parenthesis.
105
        // Unfinished closures are tokenized as T_FUNCTION however, and can be excluded
106
        // by checking if the function has a name.
107
        $methodProps = $phpcsFile->getMethodProperties($stackPtr);
3✔
108
        $methodName  = $phpcsFile->getDeclarationName($stackPtr);
3✔
109
        if ($tokens[$stackPtr]['code'] === T_FUNCTION && $methodName !== null) {
3✔
110
            if ($tokens[($openBracket - 1)]['content'] === $phpcsFile->eolChar) {
3✔
111
                $spaces = 'newline';
3✔
112
            } else if ($tokens[($openBracket - 1)]['code'] === T_WHITESPACE) {
3✔
113
                $spaces = $tokens[($openBracket - 1)]['length'];
3✔
114
            } else {
1✔
115
                $spaces = 0;
3✔
116
            }
117

118
            if ($spaces !== 0) {
3✔
119
                $error = 'Expected 0 spaces before opening parenthesis; %s found';
3✔
120
                $data  = [$spaces];
3✔
121
                $fix   = $phpcsFile->addFixableError($error, $openBracket, 'SpaceBeforeOpenParen', $data);
3✔
122
                if ($fix === true) {
3✔
123
                    $phpcsFile->fixer->replaceToken(($openBracket - 1), '');
3✔
124
                }
1✔
125
            }
1✔
126

127
            // Must be no space before semicolon in abstract/interface methods.
128
            if ($methodProps['has_body'] === false) {
3✔
129
                $end = $phpcsFile->findNext(T_SEMICOLON, $closeBracket);
3✔
130
                if ($end !== false) {
3✔
131
                    if ($tokens[($end - 1)]['content'] === $phpcsFile->eolChar) {
3✔
132
                        $spaces = 'newline';
3✔
133
                    } else if ($tokens[($end - 1)]['code'] === T_WHITESPACE) {
3✔
134
                        $spaces = $tokens[($end - 1)]['length'];
3✔
135
                    } else {
1✔
136
                        $spaces = 0;
3✔
137
                    }
138

139
                    if ($spaces !== 0) {
3✔
140
                        $error = 'Expected 0 spaces before semicolon; %s found';
3✔
141
                        $data  = [$spaces];
3✔
142
                        $fix   = $phpcsFile->addFixableError($error, $end, 'SpaceBeforeSemicolon', $data);
3✔
143
                        if ($fix === true) {
3✔
144
                            $phpcsFile->fixer->replaceToken(($end - 1), '');
3✔
145
                        }
1✔
146
                    }
1✔
147
                }
1✔
148
            }//end if
1✔
149
        }//end if
1✔
150

151
        // Must be one space before and after USE keyword for closures.
152
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
153
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
154
            if ($use !== false) {
3✔
155
                if ($tokens[($use + 1)]['code'] !== T_WHITESPACE) {
3✔
156
                    $length = 0;
3✔
157
                } else if ($tokens[($use + 1)]['content'] === "\t") {
3✔
158
                    $length = '\t';
×
159
                } else {
160
                    $length = $tokens[($use + 1)]['length'];
3✔
161
                }
162

163
                if ($length !== 1) {
3✔
164
                    $error = 'Expected 1 space after USE keyword; found %s';
3✔
165
                    $data  = [$length];
3✔
166
                    $fix   = $phpcsFile->addFixableError($error, $use, 'SpaceAfterUse', $data);
3✔
167
                    if ($fix === true) {
3✔
168
                        if ($length === 0) {
3✔
169
                            $phpcsFile->fixer->addContent($use, ' ');
3✔
170
                        } else {
1✔
171
                            $phpcsFile->fixer->replaceToken(($use + 1), ' ');
3✔
172
                        }
173
                    }
1✔
174
                }
1✔
175

176
                if ($tokens[($use - 1)]['code'] !== T_WHITESPACE) {
3✔
177
                    $length = 0;
3✔
178
                } else if ($tokens[($use - 1)]['content'] === "\t") {
3✔
179
                    $length = '\t';
×
180
                } else {
181
                    $length = $tokens[($use - 1)]['length'];
3✔
182
                }
183

184
                if ($length !== 1) {
3✔
185
                    $error = 'Expected 1 space before USE keyword; found %s';
3✔
186
                    $data  = [$length];
3✔
187
                    $fix   = $phpcsFile->addFixableError($error, $use, 'SpaceBeforeUse', $data);
3✔
188
                    if ($fix === true) {
3✔
189
                        if ($length === 0) {
3✔
190
                            $phpcsFile->fixer->addContentBefore($use, ' ');
3✔
191
                        } else {
1✔
192
                            $phpcsFile->fixer->replaceToken(($use - 1), ' ');
3✔
193
                        }
194
                    }
1✔
195
                }
1✔
196
            }//end if
1✔
197
        }//end if
1✔
198

199
        if ($this->isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens) === true) {
3✔
200
            $this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
3✔
201
        } else {
1✔
202
            $this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
3✔
203
        }
204

205
    }//end process()
2✔
206

207

208
    /**
209
     * Determine if this is a multi-line function declaration.
210
     *
211
     * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
212
     * @param int                         $stackPtr    The position of the current token
213
     *                                                 in the stack passed in $tokens.
214
     * @param int                         $openBracket The position of the opening bracket
215
     *                                                 in the stack passed in $tokens.
216
     * @param array                       $tokens      The stack of tokens that make up
217
     *                                                 the file.
218
     *
219
     * @return bool
220
     */
221
    public function isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens)
3✔
222
    {
223
        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
3✔
224
        if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
3✔
225
            return true;
3✔
226
        }
227

228
        // Closures may use the USE keyword and so be multi-line in this way.
229
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
230
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
231
            if ($use !== false) {
3✔
232
                // If the opening and closing parenthesis of the use statement
233
                // are also on the same line, this is a single line declaration.
234
                $open  = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
3✔
235
                $close = $tokens[$open]['parenthesis_closer'];
3✔
236
                if ($tokens[$open]['line'] !== $tokens[$close]['line']) {
3✔
237
                    return true;
3✔
238
                }
239
            }
1✔
240
        }
1✔
241

242
        return false;
3✔
243

244
    }//end isMultiLineDeclaration()
245

246

247
    /**
248
     * Processes single-line declarations.
249
     *
250
     * Just uses the Generic BSD-Allman brace sniff.
251
     *
252
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
253
     * @param int                         $stackPtr  The position of the current token
254
     *                                               in the stack passed in $tokens.
255
     * @param array                       $tokens    The stack of tokens that make up
256
     *                                               the file.
257
     *
258
     * @return void
259
     */
260
    public function processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens)
3✔
261
    {
262
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
263
            $sniff = new OpeningFunctionBraceKernighanRitchieSniff();
3✔
264
        } else {
1✔
265
            $sniff = new OpeningFunctionBraceBsdAllmanSniff();
3✔
266
        }
267

268
        $sniff->checkClosures = true;
3✔
269
        $sniff->process($phpcsFile, $stackPtr);
3✔
270

271
    }//end processSingleLineDeclaration()
2✔
272

273

274
    /**
275
     * Processes multi-line declarations.
276
     *
277
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
278
     * @param int                         $stackPtr  The position of the current token
279
     *                                               in the stack passed in $tokens.
280
     * @param array                       $tokens    The stack of tokens that make up
281
     *                                               the file.
282
     *
283
     * @return void
284
     */
285
    public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens)
3✔
286
    {
287
        $this->processArgumentList($phpcsFile, $stackPtr, $this->indent);
3✔
288

289
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
290
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
291
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
292
            if ($use !== false) {
3✔
293
                $open         = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
3✔
294
                $closeBracket = $tokens[$open]['parenthesis_closer'];
3✔
295
            }
1✔
296
        }
1✔
297

298
        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
3✔
299
            return;
3✔
300
        }
301

302
        // The opening brace needs to be on the same line as the closing parenthesis.
303
        // There should only be one space between the closing parenthesis - or the end of the
304
        // return type - and the opening brace.
305
        $opener = $tokens[$stackPtr]['scope_opener'];
3✔
306
        if ($tokens[$opener]['line'] !== $tokens[$closeBracket]['line']) {
3✔
307
            $error = 'The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line';
3✔
308
            $code  = 'NewlineBeforeOpenBrace';
3✔
309

310
            $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), $closeBracket, true);
3✔
311
            if ($tokens[$prev]['line'] === $tokens[$opener]['line']) {
3✔
312
                // End of the return type is not on the same line as the close parenthesis.
313
                $phpcsFile->addError($error, $opener, $code);
3✔
314
            } else {
1✔
315
                $fix = $phpcsFile->addFixableError($error, $opener, $code);
3✔
316
                if ($fix === true) {
3✔
317
                    $phpcsFile->fixer->beginChangeset();
3✔
318
                    $phpcsFile->fixer->addContent($prev, ' {');
3✔
319

320
                    // If the opener is on a line by itself, removing it will create
321
                    // an empty line, so remove the entire line instead.
322
                    $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($opener - 1), $closeBracket, true);
3✔
323
                    $next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true);
3✔
324

325
                    if ($tokens[$prev]['line'] < $tokens[$opener]['line']
3✔
326
                        && $tokens[$next]['line'] > $tokens[$opener]['line']
3✔
327
                    ) {
1✔
328
                        // Clear the whole line.
329
                        for ($i = ($prev + 1); $i < $next; $i++) {
3✔
330
                            if ($tokens[$i]['line'] === $tokens[$opener]['line']) {
3✔
331
                                $phpcsFile->fixer->replaceToken($i, '');
3✔
332
                            }
1✔
333
                        }
1✔
334
                    } else {
1✔
335
                        // Just remove the opener.
336
                        $phpcsFile->fixer->replaceToken($opener, '');
3✔
337
                        if ($tokens[$next]['line'] === $tokens[$opener]['line']
3✔
338
                            && ($opener + 1) !== $next
3✔
339
                        ) {
1✔
340
                            $phpcsFile->fixer->replaceToken(($opener + 1), '');
3✔
341
                        }
1✔
342
                    }
343

344
                    $phpcsFile->fixer->endChangeset();
3✔
345
                }//end if
1✔
346

347
                return;
3✔
348
            }//end if
349
        }//end if
1✔
350

351
        $prev = $tokens[($opener - 1)];
3✔
352
        if ($prev['code'] !== T_WHITESPACE) {
3✔
353
            $length = 0;
3✔
354
        } else {
1✔
355
            $length = strlen($prev['content']);
3✔
356
        }
357

358
        if ($length !== 1) {
3✔
359
            $error = 'There must be a single space between the closing parenthesis/return type and the opening brace of a multi-line function declaration; found %s spaces';
3✔
360
            $fix   = $phpcsFile->addFixableError($error, ($opener - 1), 'SpaceBeforeOpenBrace', [$length]);
3✔
361
            if ($fix === true) {
3✔
362
                if ($length === 0) {
3✔
363
                    $phpcsFile->fixer->addContentBefore($opener, ' ');
3✔
364
                } else {
1✔
365
                    $phpcsFile->fixer->replaceToken(($opener - 1), ' ');
3✔
366
                }
367
            }
1✔
368
        }
1✔
369

370
    }//end processMultiLineDeclaration()
2✔
371

372

373
    /**
374
     * Processes multi-line argument list declarations.
375
     *
376
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
377
     * @param int                         $stackPtr  The position of the current token
378
     *                                               in the stack passed in $tokens.
379
     * @param int                         $indent    The number of spaces code should be indented.
380
     * @param string                      $type      The type of the token the brackets
381
     *                                               belong to.
382
     *
383
     * @return void
384
     */
385
    public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='function')
3✔
386
    {
387
        $tokens = $phpcsFile->getTokens();
3✔
388

389
        // We need to work out how far indented the function
390
        // declaration itself is, so we can work out how far to
391
        // indent parameters.
392
        $functionIndent = 0;
3✔
393
        for ($i = ($stackPtr - 1); $i >= 0; $i--) {
3✔
394
            if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
3✔
395
                break;
3✔
396
            }
397
        }
1✔
398

399
        // Move $i back to the line the function is or to 0.
400
        $i++;
3✔
401

402
        if ($tokens[$i]['code'] === T_WHITESPACE) {
3✔
403
            $functionIndent = $tokens[$i]['length'];
3✔
404
        }
1✔
405

406
        // The closing parenthesis must be on a new line, even
407
        // when checking abstract function definitions.
408
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
409
        $prev         = $phpcsFile->findPrevious(
3✔
410
            T_WHITESPACE,
3✔
411
            ($closeBracket - 1),
3✔
412
            null,
3✔
413
            true
2✔
414
        );
2✔
415

416
        if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']
3✔
417
            && $tokens[$prev]['line'] === $tokens[$closeBracket]['line']
3✔
418
        ) {
1✔
419
            $error = 'The closing parenthesis of a multi-line '.$type.' declaration must be on a new line';
3✔
420
            $fix   = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketLine');
3✔
421
            if ($fix === true) {
3✔
422
                $phpcsFile->fixer->addNewlineBefore($closeBracket);
3✔
423
            }
1✔
424
        }
1✔
425

426
        // If this is a closure and is using a USE statement, the closing
427
        // parenthesis we need to look at from now on is the closing parenthesis
428
        // of the USE statement.
429
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
430
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
431
            if ($use !== false) {
3✔
432
                $open         = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
3✔
433
                $closeBracket = $tokens[$open]['parenthesis_closer'];
3✔
434

435
                $prev = $phpcsFile->findPrevious(
3✔
436
                    T_WHITESPACE,
3✔
437
                    ($closeBracket - 1),
3✔
438
                    null,
3✔
439
                    true
2✔
440
                );
2✔
441

442
                if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']
3✔
443
                    && $tokens[$prev]['line'] === $tokens[$closeBracket]['line']
3✔
444
                ) {
1✔
445
                    $error = 'The closing parenthesis of a multi-line use declaration must be on a new line';
3✔
446
                    $fix   = $phpcsFile->addFixableError($error, $closeBracket, 'UseCloseBracketLine');
3✔
447
                    if ($fix === true) {
3✔
448
                        $phpcsFile->fixer->addNewlineBefore($closeBracket);
3✔
449
                    }
1✔
450
                }
1✔
451
            }//end if
1✔
452
        }//end if
1✔
453

454
        // Each line between the parenthesis should be indented 4 spaces.
455
        $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
3✔
456
        $lastLine    = $tokens[$openBracket]['line'];
3✔
457
        for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
3✔
458
            if ($tokens[$i]['line'] !== $lastLine) {
3✔
459
                if ($i === $tokens[$stackPtr]['parenthesis_closer']
3✔
460
                    || ($tokens[$i]['code'] === T_WHITESPACE
3✔
461
                    && (($i + 1) === $closeBracket
3✔
462
                    || ($i + 1) === $tokens[$stackPtr]['parenthesis_closer']))
3✔
463
                ) {
1✔
464
                    // Closing braces need to be indented to the same level
465
                    // as the function.
466
                    $expectedIndent = $functionIndent;
3✔
467
                } else {
1✔
468
                    $expectedIndent = ($functionIndent + $indent);
3✔
469
                }
470

471
                // We changed lines, so this should be a whitespace indent token.
472
                $foundIndent = 0;
3✔
473
                if ($tokens[$i]['code'] === T_WHITESPACE
3✔
474
                    && $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
3✔
475
                ) {
1✔
476
                    $error = 'Blank lines are not allowed in a multi-line '.$type.' declaration';
3✔
477
                    $fix   = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
3✔
478
                    if ($fix === true) {
3✔
479
                        $phpcsFile->fixer->replaceToken($i, '');
3✔
480
                    }
1✔
481

482
                    // This is an empty line, so don't check the indent.
483
                    continue;
3✔
484
                } else if ($tokens[$i]['code'] === T_WHITESPACE) {
3✔
485
                    $foundIndent = $tokens[$i]['length'];
3✔
486
                } else if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
3✔
487
                    $foundIndent = $tokens[$i]['length'];
3✔
488
                    ++$expectedIndent;
3✔
489
                }
1✔
490

491
                if ($expectedIndent !== $foundIndent) {
3✔
492
                    $error = 'Multi-line '.$type.' declaration not indented correctly; expected %s spaces but found %s';
3✔
493
                    $data  = [
1✔
494
                        $expectedIndent,
3✔
495
                        $foundIndent,
3✔
496
                    ];
2✔
497

498
                    $fix = $phpcsFile->addFixableError($error, $i, 'Indent', $data);
3✔
499
                    if ($fix === true) {
3✔
500
                        $spaces = str_repeat(' ', $expectedIndent);
3✔
501
                        if ($foundIndent === 0) {
3✔
502
                            $phpcsFile->fixer->addContentBefore($i, $spaces);
3✔
503
                        } else {
1✔
504
                            $phpcsFile->fixer->replaceToken($i, $spaces);
3✔
505
                        }
506
                    }
1✔
507
                }
1✔
508

509
                $lastLine = $tokens[$i]['line'];
3✔
510
            }//end if
1✔
511

512
            if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
3✔
513
                && isset($tokens[$i]['parenthesis_closer']) === true
3✔
514
            ) {
1✔
515
                $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
3✔
516
                if ($tokens[$prevNonEmpty]['code'] !== T_USE) {
3✔
517
                    // Since PHP 8.1, a default value can contain a class instantiation.
518
                    // Skip over these "function calls" as they have their own indentation rules.
519
                    $i        = $tokens[$i]['parenthesis_closer'];
3✔
520
                    $lastLine = $tokens[$i]['line'];
3✔
521
                    continue;
3✔
522
                }
523
            }
1✔
524

525
            if ($tokens[$i]['code'] === T_ARRAY || $tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
3✔
526
                // Skip arrays as they have their own indentation rules.
527
                if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
3✔
528
                    $i = $tokens[$i]['bracket_closer'];
3✔
529
                } else {
1✔
530
                    $i = $tokens[$i]['parenthesis_closer'];
3✔
531
                }
532

533
                $lastLine = $tokens[$i]['line'];
3✔
534
                continue;
3✔
535
            }
536

537
            if ($tokens[$i]['code'] === T_ATTRIBUTE) {
3✔
538
                // Skip attributes as they have their own indentation rules.
539
                $i        = $tokens[$i]['attribute_closer'];
3✔
540
                $lastLine = $tokens[$i]['line'];
3✔
541
                continue;
3✔
542
            }
543
        }//end for
1✔
544

545
    }//end processArgumentList()
2✔
546

547

548
}//end class
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc