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

PHPCSStandards / PHP_CodeSniffer / 17690595468

13 Sep 2025 02:38AM UTC coverage: 78.779% (-0.007%) from 78.786%
17690595468

push

github

jrfnl
Merge branch 'master' into 4.x

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

2 existing lines in 2 files now uncovered.

19724 of 25037 relevant lines covered (78.78%)

96.5 hits per line

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

98.76
/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

42

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

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

62
        $openBracket  = $tokens[$stackPtr]['parenthesis_opener'];
3✔
63
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
64

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

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

89
        // Must be no space before the opening parenthesis. For closures, this is
90
        // enforced by the previous check because there is no content between the keywords
91
        // and the opening parenthesis.
92
        // Unfinished closures are tokenized as T_FUNCTION however, and can be excluded
93
        // by checking if the function has a name.
94
        if ($tokens[$stackPtr]['code'] === T_FUNCTION) {
3✔
95
            $methodProps = $phpcsFile->getMethodProperties($stackPtr);
3✔
96
            $methodName  = $phpcsFile->getDeclarationName($stackPtr);
3✔
97
            if ($methodName !== '') {
3✔
98
                if ($tokens[($openBracket - 1)]['content'] === $phpcsFile->eolChar) {
3✔
99
                    $spaces = 'newline';
3✔
100
                } elseif ($tokens[($openBracket - 1)]['code'] === T_WHITESPACE) {
3✔
101
                    $spaces = $tokens[($openBracket - 1)]['length'];
3✔
102
                } else {
103
                    $spaces = 0;
3✔
104
                }
105

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

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

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

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

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

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

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

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

195

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

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

228
        return false;
3✔
229
    }
230

231

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

253
        $sniff->checkClosures = true;
3✔
254
        $sniff->process($phpcsFile, $stackPtr);
3✔
255
    }
1✔
256

257

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

273
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
274
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
275
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
276
            if ($use !== false && isset($tokens[$use]['parenthesis_closer']) === true) {
3✔
277
                $closeBracket = $tokens[$use]['parenthesis_closer'];
3✔
278
            }
279
        }
280

281
        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
3✔
282
            return;
3✔
283
        }
284

285
        // The opening brace needs to be on the same line as the closing parenthesis.
286
        // There should only be one space between the closing parenthesis - or the end of the
287
        // return type - and the opening brace.
288
        $opener = $tokens[$stackPtr]['scope_opener'];
3✔
289
        if ($tokens[$opener]['line'] !== $tokens[$closeBracket]['line']) {
3✔
290
            $error = 'The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line';
3✔
291
            $code  = 'NewlineBeforeOpenBrace';
3✔
292

293
            $prev = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, ($opener - 1), $closeBracket, true);
3✔
294
            if ($tokens[$prev]['line'] === $tokens[$opener]['line']) {
3✔
295
                // End of the return type is not on the same line as the close parenthesis.
296
                $phpcsFile->addError($error, $opener, $code);
3✔
297
            } else {
298
                $fix = $phpcsFile->addFixableError($error, $opener, $code);
3✔
299
                if ($fix === true) {
3✔
300
                    $phpcsFile->fixer->beginChangeset();
3✔
301
                    $phpcsFile->fixer->addContent($prev, ' {');
3✔
302

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

308
                    if ($tokens[$prev]['line'] < $tokens[$opener]['line']
3✔
309
                        && $tokens[$next]['line'] > $tokens[$opener]['line']
3✔
310
                    ) {
311
                        // Clear the whole line.
312
                        for ($i = ($prev + 1); $i < $next; $i++) {
3✔
313
                            if ($tokens[$i]['line'] === $tokens[$opener]['line']) {
3✔
314
                                $phpcsFile->fixer->replaceToken($i, '');
3✔
315
                            }
316
                        }
317
                    } else {
318
                        // Just remove the opener.
319
                        $phpcsFile->fixer->replaceToken($opener, '');
3✔
320
                        if ($tokens[$next]['line'] === $tokens[$opener]['line']
3✔
321
                            && ($opener + 1) !== $next
3✔
322
                        ) {
323
                            $phpcsFile->fixer->replaceToken(($opener + 1), '');
3✔
324
                        }
325
                    }
326

327
                    $phpcsFile->fixer->endChangeset();
3✔
328
                }
329

330
                return;
3✔
331
            }
332
        }
333

334
        $prev = $tokens[($opener - 1)];
3✔
335
        if ($prev['code'] !== T_WHITESPACE) {
3✔
336
            $length = 0;
3✔
337
        } else {
338
            $length = strlen($prev['content']);
3✔
339
        }
340

341
        if ($length !== 1) {
3✔
342
            $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✔
343
            $fix   = $phpcsFile->addFixableError($error, ($opener - 1), 'SpaceBeforeOpenBrace', [$length]);
3✔
344
            if ($fix === true) {
3✔
345
                if ($length === 0) {
3✔
346
                    $phpcsFile->fixer->addContentBefore($opener, ' ');
3✔
347
                } else {
348
                    $phpcsFile->fixer->replaceToken(($opener - 1), ' ');
3✔
349
                }
350
            }
351
        }
352
    }
1✔
353

354

355
    /**
356
     * Processes multi-line argument list declarations.
357
     *
358
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
359
     * @param int                         $stackPtr  The position of the current token
360
     *                                               in the stack passed in $tokens.
361
     * @param int                         $indent    The number of spaces code should be indented.
362
     * @param string                      $type      The type of the token the brackets
363
     *                                               belong to.
364
     *
365
     * @return void
366
     */
367
    public function processArgumentList(File $phpcsFile, int $stackPtr, int $indent, string $type = 'function')
3✔
368
    {
369
        $tokens = $phpcsFile->getTokens();
3✔
370

371
        // We need to work out how far indented the function
372
        // declaration itself is, so we can work out how far to
373
        // indent parameters.
374
        $functionIndent = 0;
3✔
375
        for ($i = ($stackPtr - 1); $i >= 0; $i--) {
3✔
376
            if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
3✔
377
                break;
3✔
378
            }
379
        }
380

381
        // Move $i back to the line the function is or to 0.
382
        $i++;
3✔
383

384
        if ($tokens[$i]['code'] === T_WHITESPACE) {
3✔
385
            $functionIndent = $tokens[$i]['length'];
3✔
386
        }
387

388
        // The closing parenthesis must be on a new line, even
389
        // when checking abstract function definitions.
390
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
3✔
391
        $prev         = $phpcsFile->findPrevious(
3✔
392
            T_WHITESPACE,
3✔
393
            ($closeBracket - 1),
3✔
394
            null,
3✔
395
            true
3✔
396
        );
2✔
397

398
        if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']
3✔
399
            && $tokens[$prev]['line'] === $tokens[$closeBracket]['line']
3✔
400
        ) {
401
            $error = 'The closing parenthesis of a multi-line ' . $type . ' declaration must be on a new line';
3✔
402
            $fix   = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketLine');
3✔
403
            if ($fix === true) {
3✔
404
                $phpcsFile->fixer->addNewlineBefore($closeBracket);
3✔
405
            }
406
        }
407

408
        // If this is a closure and is using a USE statement, the closing
409
        // parenthesis we need to look at from now on is the closing parenthesis
410
        // of the USE statement.
411
        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
3✔
412
            $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
3✔
413
            if ($use !== false && isset($tokens[$use]['parenthesis_closer']) === true) {
3✔
414
                $closeBracket = $tokens[$use]['parenthesis_closer'];
3✔
415

416
                $prev = $phpcsFile->findPrevious(
3✔
417
                    T_WHITESPACE,
3✔
418
                    ($closeBracket - 1),
3✔
419
                    null,
3✔
420
                    true
3✔
421
                );
2✔
422

423
                if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']
3✔
424
                    && $tokens[$prev]['line'] === $tokens[$closeBracket]['line']
3✔
425
                ) {
426
                    $error = 'The closing parenthesis of a multi-line use declaration must be on a new line';
3✔
427
                    $fix   = $phpcsFile->addFixableError($error, $closeBracket, 'UseCloseBracketLine');
3✔
428
                    if ($fix === true) {
3✔
429
                        $phpcsFile->fixer->addNewlineBefore($closeBracket);
3✔
430
                    }
431
                }
432
            }
433
        }
434

435
        // Each line between the parenthesis should be indented 4 spaces.
436
        $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
3✔
437
        $lastLine    = $tokens[$openBracket]['line'];
3✔
438
        for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
3✔
439
            if ($tokens[$i]['line'] !== $lastLine) {
3✔
440
                if ($i === $tokens[$stackPtr]['parenthesis_closer']
3✔
441
                    || ($tokens[$i]['code'] === T_WHITESPACE
3✔
442
                    && (($i + 1) === $closeBracket
3✔
443
                    || ($i + 1) === $tokens[$stackPtr]['parenthesis_closer']))
3✔
444
                ) {
445
                    // Closing braces need to be indented to the same level
446
                    // as the function.
447
                    $expectedIndent = $functionIndent;
3✔
448
                } else {
449
                    $expectedIndent = ($functionIndent + $indent);
3✔
450
                }
451

452
                // We changed lines, so this should be a whitespace indent token.
453
                $foundIndent = 0;
3✔
454
                if ($tokens[$i]['code'] === T_WHITESPACE
3✔
455
                    && $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
3✔
456
                ) {
457
                    $error = 'Blank lines are not allowed in a multi-line ' . $type . ' declaration';
3✔
458
                    $fix   = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
3✔
459
                    if ($fix === true) {
3✔
460
                        $phpcsFile->fixer->replaceToken($i, '');
3✔
461
                    }
462

463
                    // This is an empty line, so don't check the indent.
464
                    continue;
3✔
465
                } elseif ($tokens[$i]['code'] === T_WHITESPACE) {
3✔
466
                    $foundIndent = $tokens[$i]['length'];
3✔
467
                } elseif ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
3✔
468
                    $foundIndent = $tokens[$i]['length'];
3✔
469
                    ++$expectedIndent;
3✔
470
                }
471

472
                if ($expectedIndent !== $foundIndent) {
3✔
473
                    $error = 'Multi-line ' . $type . ' declaration not indented correctly; expected %s spaces but found %s';
3✔
474
                    $data  = [
2✔
475
                        $expectedIndent,
3✔
476
                        $foundIndent,
3✔
477
                    ];
2✔
478

479
                    $fix = $phpcsFile->addFixableError($error, $i, 'Indent', $data);
3✔
480
                    if ($fix === true) {
3✔
481
                        $spaces = str_repeat(' ', $expectedIndent);
3✔
482
                        if ($foundIndent === 0) {
3✔
483
                            $phpcsFile->fixer->addContentBefore($i, $spaces);
3✔
484
                        } else {
485
                            $phpcsFile->fixer->replaceToken($i, $spaces);
3✔
486
                        }
487
                    }
488
                }
489

490
                $lastLine = $tokens[$i]['line'];
3✔
491
            }
492

493
            if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
3✔
494
                && isset($tokens[$i]['parenthesis_closer']) === true
3✔
495
            ) {
496
                $prevNonEmpty = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, ($i - 1), null, true);
3✔
497
                if ($tokens[$prevNonEmpty]['code'] !== T_USE) {
3✔
498
                    // Since PHP 8.1, a default value can contain a class instantiation.
499
                    // Skip over these "function calls" as they have their own indentation rules.
500
                    $i        = $tokens[$i]['parenthesis_closer'];
3✔
501
                    $lastLine = $tokens[$i]['line'];
3✔
502
                    continue;
3✔
503
                }
504
            }
505

506
            if ($tokens[$i]['code'] === T_ARRAY || $tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
3✔
507
                // Skip arrays as they have their own indentation rules.
508
                if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
3✔
509
                    $i = $tokens[$i]['bracket_closer'];
3✔
510
                } else {
511
                    $i = $tokens[$i]['parenthesis_closer'];
3✔
512
                }
513

514
                $lastLine = $tokens[$i]['line'];
3✔
515
                continue;
3✔
516
            }
517

518
            if ($tokens[$i]['code'] === T_ATTRIBUTE) {
3✔
519
                // Skip attributes as they have their own indentation rules.
520
                $i        = $tokens[$i]['attribute_closer'];
3✔
521
                $lastLine = $tokens[$i]['line'];
3✔
522
                continue;
3✔
523
            }
524
        }
525
    }
1✔
526
}
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