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

PHPCSStandards / PHP_CodeSniffer / 17663621563

12 Sep 2025 03:25AM UTC coverage: 78.786%. Remained the same
17663621563

push

github

web-flow
Merge pull request #1243 from PHPCSStandards/phpcs-4.x/feature/155-normalize-some-code-style-rules-5

CS: normalize code style rules [5]

294 of 308 new or added lines in 191 files covered. (95.45%)

2354 existing lines in 130 files now uncovered.

19732 of 25045 relevant lines covered (78.79%)

96.47 hits per line

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

98.77
/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
            || $tokens[$stackPtr]['parenthesis_opener'] === null
3✔
59
            || $tokens[$stackPtr]['parenthesis_closer'] === null
3✔
60
        ) {
UNCOV
61
            return;
×
62
        }
63

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

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

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

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

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

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

129
                        if ($spaces !== 0) {
3✔
130
                            $error = 'Expected 0 spaces before semicolon; %s found';
3✔
131
                            $data  = [$spaces];
3✔
132
                            $fix   = $phpcsFile->addFixableError($error, $end, 'SpaceBeforeSemicolon', $data);
3✔
133
                            if ($fix === true) {
3✔
134
                                $phpcsFile->fixer->replaceToken(($end - 1), '');
3✔
135
                            }
136
                        }
137
                    }
138
                }//end if
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
                } elseif ($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
                } elseif ($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
    }
1✔
196

197

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

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

230
        return false;
3✔
231
    }
232

233

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

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

259

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

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

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

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

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

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

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

329
                    $phpcsFile->fixer->endChangeset();
3✔
330
                }//end if
331

332
                return;
3✔
333
            }//end if
334
        }//end if
335

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

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

356

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

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

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

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

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

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

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

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

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

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

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

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

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

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

492
                $lastLine = $tokens[$i]['line'];
3✔
493
            }//end if
494

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

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

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

520
            if ($tokens[$i]['code'] === T_ATTRIBUTE) {
3✔
521
                // Skip attributes as they have their own indentation rules.
522
                $i        = $tokens[$i]['attribute_closer'];
3✔
523
                $lastLine = $tokens[$i]['line'];
3✔
524
                continue;
3✔
525
            }
526
        }//end for
527
    }
1✔
528
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc