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

PHPCSStandards / PHP_CodeSniffer / 17690095598

13 Sep 2025 01:53AM UTC coverage: 78.501% (-0.006%) from 78.507%
17690095598

Pull #1251

github

web-flow
Merge 69eab3fa8 into 66b2fa9f8
Pull Request #1251: Assorted minor fixes

4 of 5 new or added lines in 4 files covered. (80.0%)

2 existing lines in 2 files now uncovered.

25304 of 32234 relevant lines covered (78.5%)

74.7 hits per line

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

99.03
/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
        ) {
1✔
UNCOV
70
            return;
×
71
        }
72

73
        $openBracket  = $tokens[$stackPtr]['parenthesis_opener'];
3✔
74
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
75

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

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

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

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

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

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

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

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

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

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

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

203
    }//end process()
2✔
204

205

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

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

240
        return false;
3✔
241

242
    }//end isMultiLineDeclaration()
243

244

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

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

269
    }//end processSingleLineDeclaration()
2✔
270

271

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

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

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

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

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

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

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

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

345
                return;
3✔
346
            }//end if
347
        }//end if
1✔
348

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

356
        if ($length !== 1) {
3✔
357
            $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✔
358
            $fix   = $phpcsFile->addFixableError($error, ($opener - 1), 'SpaceBeforeOpenBrace', [$length]);
3✔
359
            if ($fix === true) {
3✔
360
                if ($length === 0) {
3✔
361
                    $phpcsFile->fixer->addContentBefore($opener, ' ');
3✔
362
                } else {
1✔
363
                    $phpcsFile->fixer->replaceToken(($opener - 1), ' ');
3✔
364
                }
365
            }
1✔
366
        }
1✔
367

368
    }//end processMultiLineDeclaration()
2✔
369

370

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

543
    }//end processArgumentList()
2✔
544

545

546
}//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

© 2025 Coveralls, Inc