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

PHPCSStandards / PHP_CodeSniffer / 8532137691

03 Apr 2024 02:02AM UTC coverage: 72.352% (+0.02%) from 72.328%
8532137691

push

github

jrfnl
File::getMethodProperties(): skip over closure use statements

This PR improves performance of the `File::getMethodProperties()` method and prevents incorrect return type information for closures `use` clauses containing invalid variable imports in the `use` clause (defensive coding).

Closure `use` statements can only import plain variables, not properties or other more complex variables.

As things were, when such "illegal" variables were imported in a closure `use`, the information for the return type could get mangled.
While this would be a parse error, for the purposes of static analysis, the `File::getMethodProperties()` method should still handle this correctly.

This commit updates the `File::getMethodProperties()` method to always skip over the complete `use` clause, which prevents the issue and improves performance as the same time (less token walking).

Includes unit tests.

6 of 7 new or added lines in 1 file covered. (85.71%)

4 existing lines in 3 files now uncovered.

17358 of 23991 relevant lines covered (72.35%)

55.3 hits per line

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

98.79
/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
     * The number of spaces code should be indented.
23
     *
24
     * @var integer
25
     */
26
    public $indent = 4;
27

28

29
    /**
30
     * Returns an array of tokens this test wants to listen for.
31
     *
32
     * @return array<int|string>
33
     */
34
    public function register()
3✔
35
    {
36
        return [
2✔
37
            T_FUNCTION,
3✔
38
            T_CLOSURE,
3✔
39
        ];
2✔
40

41
    }//end register()
42

43

44
    /**
45
     * Processes this test, when one of its tokens is encountered.
46
     *
47
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
48
     * @param int                         $stackPtr  The position of the current token
49
     *                                               in the stack passed in $tokens.
50
     *
51
     * @return void
52
     */
53
    public function process(File $phpcsFile, $stackPtr)
3✔
54
    {
55
        $tokens = $phpcsFile->getTokens();
3✔
56

57
        if (isset($tokens[$stackPtr]['parenthesis_opener']) === false
3✔
58
            || isset($tokens[$stackPtr]['parenthesis_closer']) === false
3✔
59
            || $tokens[$stackPtr]['parenthesis_opener'] === null
3✔
60
            || $tokens[$stackPtr]['parenthesis_closer'] === null
3✔
61
        ) {
62
            return;
×
63
        }
64

65
        $openBracket  = $tokens[$stackPtr]['parenthesis_opener'];
3✔
66
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
67

68
        if (strtolower($tokens[$stackPtr]['content']) === 'function') {
3✔
69
            // Must be one space after the FUNCTION keyword.
70
            if ($tokens[($stackPtr + 1)]['content'] === $phpcsFile->eolChar) {
3✔
71
                $spaces = 'newline';
3✔
72
            } else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
3✔
73
                $spaces = $tokens[($stackPtr + 1)]['length'];
3✔
74
            } else {
75
                $spaces = 0;
3✔
76
            }
77

78
            if ($spaces !== 1) {
3✔
79
                $error = 'Expected 1 space after FUNCTION keyword; %s found';
3✔
80
                $data  = [$spaces];
3✔
81
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterFunction', $data);
3✔
82
                if ($fix === true) {
3✔
83
                    if ($spaces === 0) {
3✔
84
                        $phpcsFile->fixer->addContent($stackPtr, ' ');
3✔
85
                    } else {
86
                        $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
3✔
87
                    }
88
                }
89
            }
90
        }//end if
91

92
        // Must be no space before the opening parenthesis. For closures, this is
93
        // enforced by the previous check because there is no content between the keywords
94
        // and the opening parenthesis.
95
        // Unfinished closures are tokenized as T_FUNCTION however, and can be excluded
96
        // by checking for the scope_opener.
97
        $methodProps = $phpcsFile->getMethodProperties($stackPtr);
3✔
98
        if ($tokens[$stackPtr]['code'] === T_FUNCTION
3✔
99
            && (isset($tokens[$stackPtr]['scope_opener']) === true || $methodProps['has_body'] === false)
3✔
100
        ) {
101
            if ($tokens[($openBracket - 1)]['content'] === $phpcsFile->eolChar) {
3✔
102
                $spaces = 'newline';
3✔
103
            } else if ($tokens[($openBracket - 1)]['code'] === T_WHITESPACE) {
3✔
104
                $spaces = $tokens[($openBracket - 1)]['length'];
3✔
105
            } else {
106
                $spaces = 0;
3✔
107
            }
108

109
            if ($spaces !== 0) {
3✔
110
                $error = 'Expected 0 spaces before opening parenthesis; %s found';
3✔
111
                $data  = [$spaces];
3✔
112
                $fix   = $phpcsFile->addFixableError($error, $openBracket, 'SpaceBeforeOpenParen', $data);
3✔
113
                if ($fix === true) {
3✔
114
                    $phpcsFile->fixer->replaceToken(($openBracket - 1), '');
3✔
115
                }
116
            }
117

118
            // Must be no space before semicolon in abstract/interface methods.
119
            if ($methodProps['has_body'] === false) {
3✔
120
                $end = $phpcsFile->findNext(T_SEMICOLON, $closeBracket);
3✔
121
                if ($end !== false) {
3✔
122
                    if ($tokens[($end - 1)]['content'] === $phpcsFile->eolChar) {
3✔
123
                        $spaces = 'newline';
3✔
124
                    } else if ($tokens[($end - 1)]['code'] === T_WHITESPACE) {
3✔
125
                        $spaces = $tokens[($end - 1)]['length'];
3✔
126
                    } else {
127
                        $spaces = 0;
3✔
128
                    }
129

130
                    if ($spaces !== 0) {
3✔
131
                        $error = 'Expected 0 spaces before semicolon; %s found';
3✔
132
                        $data  = [$spaces];
3✔
133
                        $fix   = $phpcsFile->addFixableError($error, $end, 'SpaceBeforeSemicolon', $data);
3✔
134
                        if ($fix === true) {
3✔
135
                            $phpcsFile->fixer->replaceToken(($end - 1), '');
3✔
136
                        }
137
                    }
138
                }
139
            }//end if
140
        }//end if
141

142
        // Must be one space before and after USE keyword for closures.
143
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
144
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
145
            if ($use !== false) {
3✔
146
                if ($tokens[($use + 1)]['code'] !== T_WHITESPACE) {
3✔
147
                    $length = 0;
3✔
148
                } else if ($tokens[($use + 1)]['content'] === "\t") {
3✔
UNCOV
149
                    $length = '\t';
×
150
                } else {
151
                    $length = $tokens[($use + 1)]['length'];
3✔
152
                }
153

154
                if ($length !== 1) {
3✔
155
                    $error = 'Expected 1 space after USE keyword; found %s';
3✔
156
                    $data  = [$length];
3✔
157
                    $fix   = $phpcsFile->addFixableError($error, $use, 'SpaceAfterUse', $data);
3✔
158
                    if ($fix === true) {
3✔
159
                        if ($length === 0) {
3✔
160
                            $phpcsFile->fixer->addContent($use, ' ');
3✔
161
                        } else {
162
                            $phpcsFile->fixer->replaceToken(($use + 1), ' ');
3✔
163
                        }
164
                    }
165
                }
166

167
                if ($tokens[($use - 1)]['code'] !== T_WHITESPACE) {
3✔
168
                    $length = 0;
3✔
169
                } else if ($tokens[($use - 1)]['content'] === "\t") {
3✔
UNCOV
170
                    $length = '\t';
×
171
                } else {
172
                    $length = $tokens[($use - 1)]['length'];
3✔
173
                }
174

175
                if ($length !== 1) {
3✔
176
                    $error = 'Expected 1 space before USE keyword; found %s';
3✔
177
                    $data  = [$length];
3✔
178
                    $fix   = $phpcsFile->addFixableError($error, $use, 'SpaceBeforeUse', $data);
3✔
179
                    if ($fix === true) {
3✔
180
                        if ($length === 0) {
3✔
181
                            $phpcsFile->fixer->addContentBefore($use, ' ');
3✔
182
                        } else {
183
                            $phpcsFile->fixer->replaceToken(($use - 1), ' ');
3✔
184
                        }
185
                    }
186
                }
187
            }//end if
188
        }//end if
189

190
        if ($this->isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens) === true) {
3✔
191
            $this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
3✔
192
        } else {
193
            $this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
3✔
194
        }
195

196
    }//end process()
1✔
197

198

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

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

233
        return false;
3✔
234

235
    }//end isMultiLineDeclaration()
236

237

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

259
        $sniff->checkClosures = true;
3✔
260
        $sniff->process($phpcsFile, $stackPtr);
3✔
261

262
    }//end processSingleLineDeclaration()
1✔
263

264

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

280
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
281
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
282
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
283
            if ($use !== false) {
3✔
284
                $open         = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
3✔
285
                $closeBracket = $tokens[$open]['parenthesis_closer'];
3✔
286
            }
287
        }
288

289
        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
3✔
290
            return;
3✔
291
        }
292

293
        // The opening brace needs to be on the same line as the closing parenthesis.
294
        // There should only be one space between the closing parenthesis - or the end of the
295
        // return type - and the opening brace.
296
        $opener = $tokens[$stackPtr]['scope_opener'];
3✔
297
        if ($tokens[$opener]['line'] !== $tokens[$closeBracket]['line']) {
3✔
298
            $error = 'The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line';
3✔
299
            $code  = 'NewlineBeforeOpenBrace';
3✔
300

301
            $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), $closeBracket, true);
3✔
302
            if ($tokens[$prev]['line'] === $tokens[$opener]['line']) {
3✔
303
                // End of the return type is not on the same line as the close parenthesis.
304
                $phpcsFile->addError($error, $opener, $code);
3✔
305
            } else {
306
                $fix = $phpcsFile->addFixableError($error, $opener, $code);
3✔
307
                if ($fix === true) {
3✔
308
                    $phpcsFile->fixer->beginChangeset();
3✔
309
                    $phpcsFile->fixer->addContent($prev, ' {');
3✔
310

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

316
                    if ($tokens[$prev]['line'] < $tokens[$opener]['line']
3✔
317
                        && $tokens[$next]['line'] > $tokens[$opener]['line']
3✔
318
                    ) {
319
                        // Clear the whole line.
320
                        for ($i = ($prev + 1); $i < $next; $i++) {
3✔
321
                            if ($tokens[$i]['line'] === $tokens[$opener]['line']) {
3✔
322
                                $phpcsFile->fixer->replaceToken($i, '');
3✔
323
                            }
324
                        }
325
                    } else {
326
                        // Just remove the opener.
327
                        $phpcsFile->fixer->replaceToken($opener, '');
3✔
328
                        if ($tokens[$next]['line'] === $tokens[$opener]['line']
3✔
329
                            && ($opener + 1) !== $next
3✔
330
                        ) {
331
                            $phpcsFile->fixer->replaceToken(($opener + 1), '');
3✔
332
                        }
333
                    }
334

335
                    $phpcsFile->fixer->endChangeset();
3✔
336
                }//end if
337

338
                return;
3✔
339
            }//end if
340
        }//end if
341

342
        $prev = $tokens[($opener - 1)];
3✔
343
        if ($prev['code'] !== T_WHITESPACE) {
3✔
344
            $length = 0;
3✔
345
        } else {
346
            $length = strlen($prev['content']);
3✔
347
        }
348

349
        if ($length !== 1) {
3✔
350
            $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✔
351
            $fix   = $phpcsFile->addFixableError($error, ($opener - 1), 'SpaceBeforeOpenBrace', [$length]);
3✔
352
            if ($fix === true) {
3✔
353
                if ($length === 0) {
3✔
354
                    $phpcsFile->fixer->addContentBefore($opener, ' ');
3✔
355
                } else {
356
                    $phpcsFile->fixer->replaceToken(($opener - 1), ' ');
3✔
357
                }
358
            }
359
        }
360

361
    }//end processMultiLineDeclaration()
1✔
362

363

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

380
        // We need to work out how far indented the function
381
        // declaration itself is, so we can work out how far to
382
        // indent parameters.
383
        $functionIndent = 0;
3✔
384
        for ($i = ($stackPtr - 1); $i >= 0; $i--) {
3✔
385
            if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
3✔
386
                break;
3✔
387
            }
388
        }
389

390
        // Move $i back to the line the function is or to 0.
391
        $i++;
3✔
392

393
        if ($tokens[$i]['code'] === T_WHITESPACE) {
3✔
394
            $functionIndent = $tokens[$i]['length'];
3✔
395
        }
396

397
        // The closing parenthesis must be on a new line, even
398
        // when checking abstract function definitions.
399
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
400
        $prev         = $phpcsFile->findPrevious(
3✔
401
            T_WHITESPACE,
3✔
402
            ($closeBracket - 1),
3✔
403
            null,
3✔
404
            true
3✔
405
        );
2✔
406

407
        if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']
3✔
408
            && $tokens[$prev]['line'] === $tokens[$closeBracket]['line']
3✔
409
        ) {
410
            $error = 'The closing parenthesis of a multi-line '.$type.' declaration must be on a new line';
3✔
411
            $fix   = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketLine');
3✔
412
            if ($fix === true) {
3✔
413
                $phpcsFile->fixer->addNewlineBefore($closeBracket);
3✔
414
            }
415
        }
416

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

426
                $prev = $phpcsFile->findPrevious(
3✔
427
                    T_WHITESPACE,
3✔
428
                    ($closeBracket - 1),
3✔
429
                    null,
3✔
430
                    true
3✔
431
                );
2✔
432

433
                if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']
3✔
434
                    && $tokens[$prev]['line'] === $tokens[$closeBracket]['line']
3✔
435
                ) {
436
                    $error = 'The closing parenthesis of a multi-line use declaration must be on a new line';
3✔
437
                    $fix   = $phpcsFile->addFixableError($error, $closeBracket, 'UseCloseBracketLine');
3✔
438
                    if ($fix === true) {
3✔
439
                        $phpcsFile->fixer->addNewlineBefore($closeBracket);
3✔
440
                    }
441
                }
442
            }//end if
443
        }//end if
444

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

462
                // We changed lines, so this should be a whitespace indent token.
463
                $foundIndent = 0;
3✔
464
                if ($tokens[$i]['code'] === T_WHITESPACE
3✔
465
                    && $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
3✔
466
                ) {
467
                    // This is an empty line, so don't check the indent.
468
                    $foundIndent = $expectedIndent;
3✔
469

470
                    $error = 'Blank lines are not allowed in a multi-line '.$type.' declaration';
3✔
471
                    $fix   = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
3✔
472
                    if ($fix === true) {
3✔
473
                        $phpcsFile->fixer->replaceToken($i, '');
3✔
474
                    }
475
                } else if ($tokens[$i]['code'] === T_WHITESPACE) {
3✔
476
                    $foundIndent = $tokens[$i]['length'];
3✔
477
                } else if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
3✔
478
                    $foundIndent = $tokens[$i]['length'];
3✔
479
                    ++$expectedIndent;
3✔
480
                }
481

482
                if ($expectedIndent !== $foundIndent) {
3✔
483
                    $error = 'Multi-line '.$type.' declaration not indented correctly; expected %s spaces but found %s';
3✔
484
                    $data  = [
2✔
485
                        $expectedIndent,
3✔
486
                        $foundIndent,
3✔
487
                    ];
2✔
488

489
                    $fix = $phpcsFile->addFixableError($error, $i, 'Indent', $data);
3✔
490
                    if ($fix === true) {
3✔
491
                        $spaces = str_repeat(' ', $expectedIndent);
3✔
492
                        if ($foundIndent === 0) {
3✔
493
                            $phpcsFile->fixer->addContentBefore($i, $spaces);
3✔
494
                        } else {
495
                            $phpcsFile->fixer->replaceToken($i, $spaces);
3✔
496
                        }
497
                    }
498
                }
499

500
                $lastLine = $tokens[$i]['line'];
3✔
501
            }//end if
502

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

516
            if ($tokens[$i]['code'] === T_ARRAY || $tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
3✔
517
                // Skip arrays as they have their own indentation rules.
518
                if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
3✔
519
                    $i = $tokens[$i]['bracket_closer'];
3✔
520
                } else {
521
                    $i = $tokens[$i]['parenthesis_closer'];
3✔
522
                }
523

524
                $lastLine = $tokens[$i]['line'];
3✔
525
                continue;
3✔
526
            }
527

528
            if ($tokens[$i]['code'] === T_ATTRIBUTE) {
3✔
529
                // Skip attributes as they have their own indentation rules.
530
                $i        = $tokens[$i]['attribute_closer'];
3✔
531
                $lastLine = $tokens[$i]['line'];
3✔
532
                continue;
3✔
533
            }
534
        }//end for
535

536
    }//end processArgumentList()
1✔
537

538

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