• 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

90.04
/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php
1
<?php
2
/**
3
 * Checks the declaration of the class and its inheritance is correct.
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\PSR2\Sniffs\Classes;
11

12
use PHP_CodeSniffer\Files\File;
13
use PHP_CodeSniffer\Standards\PEAR\Sniffs\Classes\ClassDeclarationSniff as PEARClassDeclarationSniff;
14
use PHP_CodeSniffer\Util\Tokens;
15

16
class ClassDeclarationSniff extends PEARClassDeclarationSniff
17
{
18

19
    /**
20
     * Modifier keywords which can be used in class declarations.
21
     *
22
     * @var array<int|string, int|string>
23
     */
24
    private const CLASS_MODIFIERS = [
25
        T_ABSTRACT => T_ABSTRACT,
26
        T_FINAL    => T_FINAL,
27
        T_READONLY => T_READONLY,
28
    ];
29

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

37

38
    /**
39
     * Processes this test, when one of its tokens is encountered.
40
     *
41
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
42
     * @param int                         $stackPtr  The position of the current token
43
     *                                               in the stack passed in $tokens.
44
     *
45
     * @return void
46
     */
47
    public function process(File $phpcsFile, int $stackPtr)
3✔
48
    {
49
        // We want all the errors from the PEAR standard, plus some of our own.
50
        parent::process($phpcsFile, $stackPtr);
3✔
51

52
        // Just in case.
53
        $tokens = $phpcsFile->getTokens();
3✔
54
        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
3✔
55
            return;
×
56
        }
57

58
        $this->processOpen($phpcsFile, $stackPtr);
3✔
59
        $this->processClose($phpcsFile, $stackPtr);
3✔
60
    }
1✔
61

62

63
    /**
64
     * Processes the opening section of a class declaration.
65
     *
66
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
67
     * @param int                         $stackPtr  The position of the current token
68
     *                                               in the stack passed in $tokens.
69
     *
70
     * @return void
71
     */
72
    public function processOpen(File $phpcsFile, int $stackPtr)
3✔
73
    {
74
        $tokens       = $phpcsFile->getTokens();
3✔
75
        $stackPtrType = strtolower($tokens[$stackPtr]['content']);
3✔
76

77
        // Check alignment of the keyword and braces.
78
        $prevNonSpace = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
3✔
79
        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, ($stackPtr - 1), null, true);
3✔
80

81
        if (isset(self::CLASS_MODIFIERS[$tokens[$prevNonEmpty]['code']]) === true) {
3✔
82
            $spaces    = 0;
3✔
83
            $errorCode = 'SpaceBeforeKeyword';
3✔
84
            if ($tokens[$prevNonEmpty]['line'] !== $tokens[$stackPtr]['line']) {
3✔
85
                $spaces    = 'newline';
3✔
86
                $errorCode = 'NewlineBeforeKeyword';
3✔
87
            } elseif ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) {
3✔
88
                $spaces = $tokens[($stackPtr - 1)]['length'];
3✔
89
            }
90

91
            if ($spaces !== 1) {
3✔
92
                $error = 'Expected 1 space between %s and %s keywords; %s found';
3✔
93
                $data  = [
2✔
94
                    strtolower($tokens[$prevNonEmpty]['content']),
3✔
95
                    $stackPtrType,
3✔
96
                    $spaces,
3✔
97
                ];
2✔
98

99
                if ($prevNonSpace !== $prevNonEmpty) {
3✔
100
                    // Comment found between modifier and class keyword. Do not auto-fix.
101
                    $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
3✔
102
                } else {
103
                    $fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data);
3✔
104
                    if ($fix === true) {
3✔
105
                        if ($spaces === 0) {
3✔
UNCOV
106
                            $phpcsFile->fixer->addContentBefore($stackPtr, ' ');
×
107
                        } else {
108
                            $phpcsFile->fixer->beginChangeset();
3✔
109
                            $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' ');
3✔
110
                            for ($i = ($stackPtr - 2); $i > $prevNonSpace; $i--) {
3✔
111
                                $phpcsFile->fixer->replaceToken($i, ' ');
3✔
112
                            }
113

114
                            $phpcsFile->fixer->endChangeset();
3✔
115
                        }
116
                    }
117
                }
118
            }//end if
119
        }//end if
120

121
        // We'll need the indent of the class/interface declaration for later.
122
        $classIndent = 0;
3✔
123
        for ($i = ($stackPtr - 1); $i > 0; $i--) {
3✔
124
            if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) {
3✔
125
                continue;
3✔
126
            }
127

128
            // We changed lines.
129
            if ($tokens[($i + 1)]['code'] === T_WHITESPACE) {
3✔
130
                $classIndent = $tokens[($i + 1)]['length'];
3✔
131
            }
132

133
            break;
3✔
134
        }
135

136
        $className    = null;
3✔
137
        $checkSpacing = true;
3✔
138

139
        if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) {
3✔
140
            $className = $phpcsFile->findNext(T_STRING, $stackPtr);
3✔
141
        } else {
142
            // Ignore the spacing check if this is a simple anon class.
UNCOV
143
            $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
×
144
            if ($next === $tokens[$stackPtr]['scope_opener']
×
145
                && $tokens[$next]['line'] > $tokens[$stackPtr]['line']
×
146
            ) {
UNCOV
147
                $checkSpacing = false;
×
148
            }
149
        }
150

151
        if ($checkSpacing === true) {
3✔
152
            // Spacing of the keyword.
153
            if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
3✔
UNCOV
154
                $gap = 0;
×
155
            } elseif ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) {
3✔
156
                $gap = 'newline';
3✔
157
            } else {
158
                $gap = $tokens[($stackPtr + 1)]['length'];
3✔
159
            }
160

161
            if ($gap !== 1) {
3✔
162
                $error = 'Expected 1 space after %s keyword; %s found';
3✔
163
                $data  = [
2✔
164
                    $stackPtrType,
3✔
165
                    $gap,
3✔
166
                ];
2✔
167

168
                $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword', $data);
3✔
169
                if ($fix === true) {
3✔
170
                    if ($gap === 0) {
3✔
UNCOV
171
                        $phpcsFile->fixer->addContent($stackPtr, ' ');
×
172
                    } else {
173
                        $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
3✔
174
                    }
175
                }
176
            }
177
        }//end if
178

179
        // Check after the class/interface name.
180
        if ($className !== null
3✔
181
            && $tokens[($className + 2)]['line'] === $tokens[$className]['line']
3✔
182
        ) {
183
            $gap = $tokens[($className + 1)]['content'];
3✔
184
            if (strlen($gap) !== 1) {
3✔
UNCOV
185
                $found = strlen($gap);
×
186
                $error = 'Expected 1 space after %s name; %s found';
×
187
                $data  = [
UNCOV
188
                    $stackPtrType,
×
189
                    $found,
×
190
                ];
191

UNCOV
192
                $fix = $phpcsFile->addFixableError($error, $className, 'SpaceAfterName', $data);
×
193
                if ($fix === true) {
×
194
                    $phpcsFile->fixer->replaceToken(($className + 1), ' ');
×
195
                }
196
            }
197
        }
198

199
        $openingBrace = $tokens[$stackPtr]['scope_opener'];
3✔
200

201
        // Check positions of the extends and implements keywords.
202
        $compareToken = $stackPtr;
3✔
203
        $compareType  = 'name';
3✔
204
        if ($tokens[$stackPtr]['code'] === T_ANON_CLASS) {
3✔
UNCOV
205
            if (isset($tokens[$stackPtr]['parenthesis_opener']) === true) {
×
206
                $compareToken = $tokens[$stackPtr]['parenthesis_closer'];
×
207
                $compareType  = 'closing parenthesis';
×
208
            } else {
UNCOV
209
                $compareType = 'keyword';
×
210
            }
211
        }
212

213
        foreach (['extends', 'implements'] as $keywordType) {
3✔
214
            $keyword = $phpcsFile->findNext(constant('T_' . strtoupper($keywordType)), ($compareToken + 1), $openingBrace);
3✔
215
            if ($keyword !== false) {
3✔
216
                if ($tokens[$keyword]['line'] !== $tokens[$compareToken]['line']) {
3✔
217
                    $error = 'The ' . $keywordType . ' keyword must be on the same line as the %s ' . $compareType;
3✔
218
                    $data  = [$stackPtrType];
3✔
219
                    $fix   = $phpcsFile->addFixableError($error, $keyword, ucfirst($keywordType) . 'Line', $data);
3✔
220
                    if ($fix === true) {
3✔
221
                        $phpcsFile->fixer->beginChangeset();
3✔
222
                        $comments = [];
3✔
223

224
                        for ($i = ($compareToken + 1); $i < $keyword; ++$i) {
3✔
225
                            if ($tokens[$i]['code'] === T_COMMENT) {
3✔
226
                                $comments[] = trim($tokens[$i]['content']);
3✔
227
                            }
228

229
                            if ($tokens[$i]['code'] === T_WHITESPACE
3✔
230
                                || $tokens[$i]['code'] === T_COMMENT
3✔
231
                            ) {
232
                                $phpcsFile->fixer->replaceToken($i, ' ');
3✔
233
                            }
234
                        }
235

236
                        $phpcsFile->fixer->addContent($compareToken, ' ');
3✔
237
                        if (empty($comments) === false) {
3✔
238
                            $i = $keyword;
3✔
239
                            while ($tokens[($i + 1)]['line'] === $tokens[$keyword]['line']) {
3✔
240
                                ++$i;
3✔
241
                            }
242

243
                            $phpcsFile->fixer->addContentBefore($i, ' ' . implode(' ', $comments));
3✔
244
                        }
245

246
                        $phpcsFile->fixer->endChangeset();
3✔
247
                    }//end if
248
                } else {
249
                    // Check the whitespace before. Whitespace after is checked
250
                    // later by looking at the whitespace before the first class name
251
                    // in the list.
252
                    $gap = $tokens[($keyword - 1)]['length'];
3✔
253
                    if ($gap !== 1) {
3✔
254
                        $error = 'Expected 1 space before ' . $keywordType . ' keyword; %s found';
3✔
255
                        $data  = [$gap];
3✔
256
                        $fix   = $phpcsFile->addFixableError($error, $keyword, 'SpaceBefore' . ucfirst($keywordType), $data);
3✔
257
                        if ($fix === true) {
3✔
258
                            $phpcsFile->fixer->replaceToken(($keyword - 1), ' ');
3✔
259
                        }
260
                    }
261
                }//end if
262
            }//end if
263
        }//end foreach
264

265
        // Check each of the extends/implements class names. If the extends/implements
266
        // keyword is the last content on the line, it means we need to check for
267
        // the multi-line format, so we do not include the class names
268
        // from the extends/implements list in the following check.
269
        // Note that classes can only extend one other class, so they can't use a
270
        // multi-line extends format, whereas an interface can extend multiple
271
        // other interfaces, and so uses a multi-line extends format.
272
        if ($tokens[$stackPtr]['code'] === T_INTERFACE) {
3✔
273
            $keywordTokenType = T_EXTENDS;
3✔
274
        } else {
275
            $keywordTokenType = T_IMPLEMENTS;
3✔
276
        }
277

278
        $implements          = $phpcsFile->findNext($keywordTokenType, ($stackPtr + 1), $openingBrace);
3✔
279
        $multiLineImplements = false;
3✔
280
        if ($implements !== false) {
3✔
281
            $prev = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, ($openingBrace - 1), $implements, true);
3✔
282
            if ($tokens[$prev]['line'] !== $tokens[$implements]['line']) {
3✔
283
                $multiLineImplements = true;
3✔
284
            }
285
        }
286

287
        $find = Tokens::NAME_TOKENS;
3✔
288
        $find[$keywordTokenType] = $keywordTokenType;
3✔
289

290
        if ($className !== null) {
3✔
291
            $start = $className;
3✔
UNCOV
292
        } elseif (isset($tokens[$stackPtr]['parenthesis_closer']) === true) {
×
293
            $start = $tokens[$stackPtr]['parenthesis_closer'];
×
294
        } else {
UNCOV
295
            $start = $stackPtr;
×
296
        }
297

298
        $classNames = [];
3✔
299
        $nextClass  = $phpcsFile->findNext($find, ($start + 2), ($openingBrace - 1));
3✔
300
        while ($nextClass !== false) {
3✔
301
            $classNames[] = $nextClass;
3✔
302
            $nextClass    = $phpcsFile->findNext($find, ($nextClass + 1), ($openingBrace - 1));
3✔
303
        }
304

305
        $classCount         = count($classNames);
3✔
306
        $checkingImplements = false;
3✔
307
        $implementsToken    = null;
3✔
308
        foreach ($classNames as $n => $className) {
3✔
309
            if ($tokens[$className]['code'] === $keywordTokenType) {
3✔
310
                $checkingImplements = true;
3✔
311
                $implementsToken    = $className;
3✔
312

313
                continue;
3✔
314
            }
315

316
            if ($checkingImplements === true && $multiLineImplements === true) {
3✔
317
                $prev = $phpcsFile->findPrevious(
3✔
318
                    T_WHITESPACE,
3✔
319
                    ($className - 1),
3✔
320
                    $implements,
3✔
321
                    true
3✔
322
                );
2✔
323

324
                if ($prev === $implementsToken && $tokens[$className]['line'] !== ($tokens[$prev]['line'] + 1)) {
3✔
325
                    if ($keywordTokenType === T_EXTENDS) {
3✔
UNCOV
326
                        $error = 'The first item in a multi-line extends list must be on the line following the extends keyword';
×
327
                        $fix   = $phpcsFile->addFixableError($error, $className, 'FirstExtendsInterfaceSameLine');
×
328
                    } else {
329
                        $error = 'The first item in a multi-line implements list must be on the line following the implements keyword';
3✔
330
                        $fix   = $phpcsFile->addFixableError($error, $className, 'FirstInterfaceSameLine');
3✔
331
                    }
332

333
                    if ($fix === true) {
3✔
334
                        $phpcsFile->fixer->beginChangeset();
3✔
335
                        for ($i = ($prev + 1); $i < $className; $i++) {
3✔
336
                            if ($tokens[$i]['code'] !== T_WHITESPACE) {
3✔
UNCOV
337
                                break;
×
338
                            }
339

340
                            $phpcsFile->fixer->replaceToken($i, '');
3✔
341
                        }
342

343
                        $phpcsFile->fixer->addNewline($prev);
3✔
344
                        $phpcsFile->fixer->endChangeset();
3✔
345
                    }
346
                } elseif ((isset(Tokens::COMMENT_TOKENS[$tokens[$prev]['code']]) === false
3✔
347
                    && $tokens[$prev]['line'] !== ($tokens[$className]['line'] - 1))
3✔
348
                    || $tokens[$prev]['line'] === $tokens[$className]['line']
3✔
349
                ) {
350
                    if ($keywordTokenType === T_EXTENDS) {
3✔
351
                        $error = 'Only one interface may be specified per line in a multi-line extends declaration';
3✔
352
                        $fix   = $phpcsFile->addFixableError($error, $className, 'ExtendsInterfaceSameLine');
3✔
353
                    } else {
354
                        $error = 'Only one interface may be specified per line in a multi-line implements declaration';
3✔
355
                        $fix   = $phpcsFile->addFixableError($error, $className, 'InterfaceSameLine');
3✔
356
                    }
357

358
                    if ($fix === true) {
3✔
359
                        $phpcsFile->fixer->beginChangeset();
3✔
360
                        for ($i = ($prev + 1); $i < $className; $i++) {
3✔
361
                            if ($tokens[$i]['code'] !== T_WHITESPACE) {
3✔
UNCOV
362
                                break;
×
363
                            }
364

365
                            $phpcsFile->fixer->replaceToken($i, '');
3✔
366
                        }
367

368
                        $phpcsFile->fixer->addNewline($prev);
3✔
369
                        $phpcsFile->fixer->endChangeset();
3✔
370
                    }
371
                } else {
372
                    $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($className - 1), $implements);
3✔
373
                    if ($tokens[$prev]['line'] !== $tokens[$className]['line']) {
3✔
374
                        $found = 0;
3✔
375
                    } else {
376
                        $found = $tokens[$prev]['length'];
3✔
377
                    }
378

379
                    $expected = ($classIndent + $this->indent);
3✔
380
                    if ($found !== $expected) {
3✔
381
                        $error = 'Expected %s spaces before interface name; %s found';
3✔
382
                        $data  = [
2✔
383
                            $expected,
3✔
384
                            $found,
3✔
385
                        ];
2✔
386
                        $fix   = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongIndent', $data);
3✔
387
                        if ($fix === true) {
3✔
388
                            $padding = str_repeat(' ', $expected);
3✔
389
                            if ($found === 0) {
3✔
390
                                $phpcsFile->fixer->addContent($prev, $padding);
3✔
391
                            } else {
392
                                $phpcsFile->fixer->replaceToken($prev, $padding);
3✔
393
                            }
394
                        }
395
                    }
396
                }//end if
397
            } else {
398
                if ($tokens[($className - 1)]['code'] === T_COMMA) {
3✔
399
                    $error = 'Expected 1 space before "%s"; 0 found';
3✔
400
                    $data  = [$tokens[$className]['content']];
3✔
401
                    $fix   = $phpcsFile->addFixableError($error, ($nextComma + 1), 'NoSpaceBeforeName', $data);
3✔
402
                    if ($fix === true) {
3✔
403
                        $phpcsFile->fixer->addContentBefore(($nextComma + 1), ' ');
3✔
404
                    }
405
                } else {
406
                    $prev = ($className - 1);
3✔
407

408
                    $last    = $phpcsFile->findPrevious(T_WHITESPACE, $prev, null, true);
3✔
409
                    $content = $phpcsFile->getTokensAsString(($last + 1), ($prev - $last));
3✔
410
                    if ($content !== ' ') {
3✔
411
                        $found = strlen($content);
3✔
412

413
                        $error = 'Expected 1 space before "%s"; %s found';
3✔
414
                        $data  = [
2✔
415
                            $tokens[$className]['content'],
3✔
416
                            $found,
3✔
417
                        ];
2✔
418

419
                        $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeName', $data);
3✔
420
                        if ($fix === true) {
3✔
421
                            if ($tokens[$prev]['code'] === T_WHITESPACE) {
3✔
422
                                $phpcsFile->fixer->beginChangeset();
3✔
423
                                $phpcsFile->fixer->replaceToken($prev, ' ');
3✔
424
                                while ($tokens[--$prev]['code'] === T_WHITESPACE) {
3✔
425
                                    $phpcsFile->fixer->replaceToken($prev, ' ');
3✔
426
                                }
427

428
                                $phpcsFile->fixer->endChangeset();
3✔
429
                            } else {
UNCOV
430
                                $phpcsFile->fixer->addContent($prev, ' ');
×
431
                            }
432
                        }
433
                    }//end if
434
                }//end if
435
            }//end if
436

437
            if ($checkingImplements === true
3✔
438
                && $tokens[($className + 1)]['code'] !== T_COMMA
3✔
439
            ) {
440
                if ($n !== ($classCount - 1)) {
3✔
441
                    // This is not the last class name, and the comma
442
                    // is not where we expect it to be.
443
                    if ($tokens[($className + 2)]['code'] !== $keywordTokenType) {
3✔
444
                        $error = 'Expected 0 spaces between "%s" and comma; %s found';
3✔
445
                        $data  = [
2✔
446
                            $tokens[$className]['content'],
3✔
447
                            $tokens[($className + 1)]['length'],
3✔
448
                        ];
2✔
449

450
                        $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeComma', $data);
3✔
451
                        if ($fix === true) {
3✔
452
                            $phpcsFile->fixer->replaceToken(($className + 1), '');
3✔
453
                        }
454
                    }
455
                }
456

457
                $nextComma = $phpcsFile->findNext(T_COMMA, $className);
3✔
458
            } else {
459
                $nextComma = ($className + 1);
3✔
460
            }//end if
461
        }//end foreach
462
    }
1✔
463

464

465
    /**
466
     * Processes the closing section of a class declaration.
467
     *
468
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
469
     * @param int                         $stackPtr  The position of the current token
470
     *                                               in the stack passed in $tokens.
471
     *
472
     * @return void
473
     */
474
    public function processClose(File $phpcsFile, int $stackPtr)
3✔
475
    {
476
        $tokens = $phpcsFile->getTokens();
3✔
477

478
        // Check that the closing brace comes right after the code body.
479
        $closeBrace  = $tokens[$stackPtr]['scope_closer'];
3✔
480
        $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true);
3✔
481
        if ($prevContent !== $tokens[$stackPtr]['scope_opener']
3✔
482
            && $tokens[$prevContent]['line'] !== ($tokens[$closeBrace]['line'] - 1)
3✔
483
        ) {
484
            $error = 'The closing brace for the %s must go on the next line after the body';
3✔
485
            $data  = [$tokens[$stackPtr]['content']];
3✔
486
            $fix   = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data);
3✔
487

488
            if ($fix === true) {
3✔
489
                $phpcsFile->fixer->beginChangeset();
3✔
490
                for ($i = ($prevContent + 1); $tokens[$i]['line'] !== $tokens[$closeBrace]['line']; $i++) {
3✔
491
                    $phpcsFile->fixer->replaceToken($i, '');
3✔
492
                }
493

494
                if (strpos($tokens[$prevContent]['content'], $phpcsFile->eolChar) === false) {
3✔
495
                    $phpcsFile->fixer->addNewline($prevContent);
3✔
496
                }
497

498
                $phpcsFile->fixer->endChangeset();
3✔
499
            }
500
        }//end if
501

502
        if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) {
3✔
503
            // Check the closing brace is on it's own line, but allow
504
            // for comments like "//end class".
505
            $ignoreTokens   = Tokens::PHPCS_ANNOTATION_TOKENS;
3✔
506
            $ignoreTokens[] = T_WHITESPACE;
3✔
507
            $ignoreTokens[] = T_COMMENT;
3✔
508
            $ignoreTokens[] = T_SEMICOLON;
3✔
509
            $nextContent    = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true);
3✔
510
            if ($tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']) {
3✔
511
                $type  = strtolower($tokens[$stackPtr]['content']);
3✔
512
                $error = 'Closing %s brace must be on a line by itself';
3✔
513
                $data  = [$type];
3✔
514
                $phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data);
3✔
515
            }
516
        }
517
    }
1✔
518
}
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