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

keradus / PHP-CS-Fixer / 14008489983

22 Mar 2025 12:21PM UTC coverage: 94.866%. First build
14008489983

push

github

web-flow
Merge branch 'master' into Preg_types

36 of 47 new or added lines in 13 files covered. (76.6%)

28143 of 29666 relevant lines covered (94.87%)

43.2 hits per line

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

96.98
/src/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixer.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Fixer\LanguageConstruct;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
19
use PhpCsFixer\Fixer\ConfigurableFixerTrait;
20
use PhpCsFixer\FixerConfiguration\AllowedValueSubset;
21
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
22
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
23
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
24
use PhpCsFixer\FixerDefinition\CodeSample;
25
use PhpCsFixer\FixerDefinition\FixerDefinition;
26
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
27
use PhpCsFixer\Preg;
28
use PhpCsFixer\Tokenizer\CT;
29
use PhpCsFixer\Tokenizer\Token;
30
use PhpCsFixer\Tokenizer\Tokens;
31

32
/**
33
 * @author Andreas Möller <am@localheinz.com>
34
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
35
 *
36
 * @implements ConfigurableFixerInterface<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration>
37
 *
38
 * @phpstan-type _AutogeneratedInputConfiguration array{
39
 *  constructs_contain_a_single_space?: list<'yield_from'>,
40
 *  constructs_followed_by_a_single_space?: list<'abstract'|'as'|'attribute'|'break'|'case'|'catch'|'class'|'clone'|'comment'|'const'|'const_import'|'continue'|'do'|'echo'|'else'|'elseif'|'enum'|'extends'|'final'|'finally'|'for'|'foreach'|'function'|'function_import'|'global'|'goto'|'if'|'implements'|'include'|'include_once'|'instanceof'|'insteadof'|'interface'|'match'|'named_argument'|'namespace'|'new'|'open_tag_with_echo'|'php_doc'|'php_open'|'print'|'private'|'protected'|'public'|'readonly'|'require'|'require_once'|'return'|'static'|'switch'|'throw'|'trait'|'try'|'type_colon'|'use'|'use_lambda'|'use_trait'|'var'|'while'|'yield'|'yield_from'>,
41
 *  constructs_preceded_by_a_single_space?: list<'as'|'else'|'elseif'|'use_lambda'>,
42
 * }
43
 * @phpstan-type _AutogeneratedComputedConfiguration array{
44
 *  constructs_contain_a_single_space: list<'yield_from'>,
45
 *  constructs_followed_by_a_single_space: list<'abstract'|'as'|'attribute'|'break'|'case'|'catch'|'class'|'clone'|'comment'|'const'|'const_import'|'continue'|'do'|'echo'|'else'|'elseif'|'enum'|'extends'|'final'|'finally'|'for'|'foreach'|'function'|'function_import'|'global'|'goto'|'if'|'implements'|'include'|'include_once'|'instanceof'|'insteadof'|'interface'|'match'|'named_argument'|'namespace'|'new'|'open_tag_with_echo'|'php_doc'|'php_open'|'print'|'private'|'protected'|'public'|'readonly'|'require'|'require_once'|'return'|'static'|'switch'|'throw'|'trait'|'try'|'type_colon'|'use'|'use_lambda'|'use_trait'|'var'|'while'|'yield'|'yield_from'>,
46
 *  constructs_preceded_by_a_single_space: list<'as'|'else'|'elseif'|'use_lambda'>,
47
 * }
48
 */
49
final class SingleSpaceAroundConstructFixer extends AbstractFixer implements ConfigurableFixerInterface
50
{
51
    /** @use ConfigurableFixerTrait<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration> */
52
    use ConfigurableFixerTrait;
53

54
    /**
55
     * @var array<string, null|int>
56
     */
57
    private static array $tokenMapContainASingleSpace = [
58
        // for now, only one case - but we are ready to extend it, when we learn about new cases to cover
59
        'yield_from' => T_YIELD_FROM,
60
    ];
61

62
    /**
63
     * @var array<string, null|int>
64
     */
65
    private static array $tokenMapPrecededByASingleSpace = [
66
        'as' => T_AS,
67
        'else' => T_ELSE,
68
        'elseif' => T_ELSEIF,
69
        'use_lambda' => CT::T_USE_LAMBDA,
70
    ];
71

72
    /**
73
     * @var array<string, null|int>
74
     */
75
    private static array $tokenMapFollowedByASingleSpace = [
76
        'abstract' => T_ABSTRACT,
77
        'as' => T_AS,
78
        'attribute' => CT::T_ATTRIBUTE_CLOSE,
79
        'break' => T_BREAK,
80
        'case' => T_CASE,
81
        'catch' => T_CATCH,
82
        'class' => T_CLASS,
83
        'clone' => T_CLONE,
84
        'comment' => T_COMMENT,
85
        'const' => T_CONST,
86
        'const_import' => CT::T_CONST_IMPORT,
87
        'continue' => T_CONTINUE,
88
        'do' => T_DO,
89
        'echo' => T_ECHO,
90
        'else' => T_ELSE,
91
        'elseif' => T_ELSEIF,
92
        'enum' => null,
93
        'extends' => T_EXTENDS,
94
        'final' => T_FINAL,
95
        'finally' => T_FINALLY,
96
        'for' => T_FOR,
97
        'foreach' => T_FOREACH,
98
        'function' => T_FUNCTION,
99
        'function_import' => CT::T_FUNCTION_IMPORT,
100
        'global' => T_GLOBAL,
101
        'goto' => T_GOTO,
102
        'if' => T_IF,
103
        'implements' => T_IMPLEMENTS,
104
        'include' => T_INCLUDE,
105
        'include_once' => T_INCLUDE_ONCE,
106
        'instanceof' => T_INSTANCEOF,
107
        'insteadof' => T_INSTEADOF,
108
        'interface' => T_INTERFACE,
109
        'match' => null,
110
        'named_argument' => CT::T_NAMED_ARGUMENT_COLON,
111
        'namespace' => T_NAMESPACE,
112
        'new' => T_NEW,
113
        'open_tag_with_echo' => T_OPEN_TAG_WITH_ECHO,
114
        'php_doc' => T_DOC_COMMENT,
115
        'php_open' => T_OPEN_TAG,
116
        'print' => T_PRINT,
117
        'private' => T_PRIVATE,
118
        'protected' => T_PROTECTED,
119
        'public' => T_PUBLIC,
120
        'readonly' => null,
121
        'require' => T_REQUIRE,
122
        'require_once' => T_REQUIRE_ONCE,
123
        'return' => T_RETURN,
124
        'static' => T_STATIC,
125
        'switch' => T_SWITCH,
126
        'throw' => T_THROW,
127
        'trait' => T_TRAIT,
128
        'try' => T_TRY,
129
        'type_colon' => CT::T_TYPE_COLON,
130
        'use' => T_USE,
131
        'use_lambda' => CT::T_USE_LAMBDA,
132
        'use_trait' => CT::T_USE_TRAIT,
133
        'var' => T_VAR,
134
        'while' => T_WHILE,
135
        'yield' => T_YIELD,
136
        'yield_from' => T_YIELD_FROM,
137
    ];
138

139
    /**
140
     * @var array<string, int>
141
     */
142
    private array $fixTokenMapFollowedByASingleSpace = [];
143

144
    /**
145
     * @var array<string, int>
146
     */
147
    private array $fixTokenMapContainASingleSpace = [];
148

149
    /**
150
     * @var array<string, int>
151
     */
152
    private array $fixTokenMapPrecededByASingleSpace = [];
153

154
    public function getDefinition(): FixerDefinitionInterface
155
    {
156
        return new FixerDefinition(
3✔
157
            'Ensures a single space after language constructs.',
3✔
158
            [
3✔
159
                new CodeSample(
3✔
160
                    '<?php
3✔
161

162
throw  new  \Exception();
163
'
3✔
164
                ),
3✔
165
                new CodeSample(
3✔
166
                    '<?php
3✔
167

168
function foo() { yield  from  baz(); }
169
',
3✔
170
                    [
3✔
171
                        'constructs_contain_a_single_space' => [
3✔
172
                            'yield_from',
3✔
173
                        ],
3✔
174
                        'constructs_followed_by_a_single_space' => [
3✔
175
                            'yield_from',
3✔
176
                        ],
3✔
177
                    ]
3✔
178
                ),
3✔
179

180
                new CodeSample(
3✔
181
                    '<?php
3✔
182

183
$foo = function& ()use($bar) {
184
};
185
',
3✔
186
                    [
3✔
187
                        'constructs_preceded_by_a_single_space' => [
3✔
188
                            'use_lambda',
3✔
189
                        ],
3✔
190
                        'constructs_followed_by_a_single_space' => [
3✔
191
                            'use_lambda',
3✔
192
                        ],
3✔
193
                    ]
3✔
194
                ),
3✔
195
                new CodeSample(
3✔
196
                    '<?php
3✔
197

198
echo  "Hello!";
199
',
3✔
200
                    [
3✔
201
                        'constructs_followed_by_a_single_space' => [
3✔
202
                            'echo',
3✔
203
                        ],
3✔
204
                    ]
3✔
205
                ),
3✔
206
                new CodeSample(
3✔
207
                    '<?php
3✔
208

209
yield  from  baz();
210
',
3✔
211
                    [
3✔
212
                        'constructs_followed_by_a_single_space' => [
3✔
213
                            'yield_from',
3✔
214
                        ],
3✔
215
                    ]
3✔
216
                ),
3✔
217
            ]
3✔
218
        );
3✔
219
    }
220

221
    /**
222
     * {@inheritdoc}
223
     *
224
     * Must run before BracesFixer, FunctionDeclarationFixer.
225
     * Must run after ArraySyntaxFixer, ModernizeStrposFixer.
226
     */
227
    public function getPriority(): int
228
    {
229
        return 36;
1✔
230
    }
231

232
    public function isCandidate(Tokens $tokens): bool
233
    {
234
        $tokenKinds = [
400✔
235
            ...array_values($this->fixTokenMapContainASingleSpace),
400✔
236
            ...array_values($this->fixTokenMapPrecededByASingleSpace),
400✔
237
            ...array_values($this->fixTokenMapFollowedByASingleSpace),
400✔
238
        ];
400✔
239

240
        return $tokens->isAnyTokenKindsFound($tokenKinds);
400✔
241
    }
242

243
    protected function configurePostNormalisation(): void
244
    {
245
        if (\defined('T_MATCH')) { // @TODO: drop condition when PHP 8.0+ is required
415✔
246
            self::$tokenMapFollowedByASingleSpace['match'] = T_MATCH;
415✔
247
        }
248

249
        if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required
415✔
250
            self::$tokenMapFollowedByASingleSpace['readonly'] = T_READONLY;
415✔
251
        }
252

253
        if (\defined('T_ENUM')) { // @TODO: drop condition when PHP 8.1+ is required
415✔
254
            self::$tokenMapFollowedByASingleSpace['enum'] = T_ENUM;
415✔
255
        }
256

257
        $this->fixTokenMapContainASingleSpace = [];
415✔
258

259
        foreach ($this->configuration['constructs_contain_a_single_space'] as $key) {
415✔
260
            if (null !== self::$tokenMapContainASingleSpace[$key]) {
415✔
261
                $this->fixTokenMapContainASingleSpace[$key] = self::$tokenMapContainASingleSpace[$key];
415✔
262
            }
263
        }
264

265
        $this->fixTokenMapPrecededByASingleSpace = [];
415✔
266

267
        foreach ($this->configuration['constructs_preceded_by_a_single_space'] as $key) {
415✔
268
            if (null !== self::$tokenMapPrecededByASingleSpace[$key]) {
415✔
269
                $this->fixTokenMapPrecededByASingleSpace[$key] = self::$tokenMapPrecededByASingleSpace[$key];
415✔
270
            }
271
        }
272

273
        $this->fixTokenMapFollowedByASingleSpace = [];
415✔
274

275
        foreach ($this->configuration['constructs_followed_by_a_single_space'] as $key) {
415✔
276
            if (null !== self::$tokenMapFollowedByASingleSpace[$key]) {
415✔
277
                $this->fixTokenMapFollowedByASingleSpace[$key] = self::$tokenMapFollowedByASingleSpace[$key];
415✔
278
            }
279
        }
280

281
        if (isset($this->fixTokenMapFollowedByASingleSpace['public'])) {
415✔
282
            $this->fixTokenMapFollowedByASingleSpace['constructor_public'] = CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC;
415✔
283
        }
284

285
        if (isset($this->fixTokenMapFollowedByASingleSpace['protected'])) {
415✔
286
            $this->fixTokenMapFollowedByASingleSpace['constructor_protected'] = CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED;
415✔
287
        }
288

289
        if (isset($this->fixTokenMapFollowedByASingleSpace['private'])) {
415✔
290
            $this->fixTokenMapFollowedByASingleSpace['constructor_private'] = CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE;
415✔
291
        }
292
    }
293

294
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
295
    {
296
        $tokenKindsContainASingleSpace = array_values($this->fixTokenMapContainASingleSpace);
399✔
297

298
        for ($index = $tokens->count() - 1; $index > 0; --$index) {
399✔
299
            if ($tokens[$index]->isGivenKind($tokenKindsContainASingleSpace)) {
397✔
300
                $token = $tokens[$index];
6✔
301

302
                if (
303
                    $token->isGivenKind(T_YIELD_FROM)
6✔
304
                    && 'yield from' !== strtolower($token->getContent())
6✔
305
                ) {
306
                    $tokens[$index] = new Token([T_YIELD_FROM, Preg::replace(
6✔
307
                        '/\s+/',
6✔
308
                        ' ',
6✔
309
                        $token->getContent()
6✔
310
                    )]);
6✔
311
                }
312
            }
313
        }
314

315
        $tokenKindsPrecededByASingleSpace = array_values($this->fixTokenMapPrecededByASingleSpace);
399✔
316

317
        for ($index = $tokens->count() - 1; $index > 0; --$index) {
399✔
318
            if ($tokens[$index]->isGivenKind($tokenKindsPrecededByASingleSpace)) {
397✔
319
                if (!$this->isFullLineCommentBefore($tokens, $index)) {
29✔
320
                    $tokens->ensureWhitespaceAtIndex($index - 1, 1, ' ');
27✔
321
                }
322
            }
323
        }
324

325
        $tokenKindsFollowedByASingleSpace = array_values($this->fixTokenMapFollowedByASingleSpace);
399✔
326

327
        for ($index = $tokens->count() - 2; $index >= 0; --$index) {
399✔
328
            $token = $tokens[$index];
397✔
329

330
            if (!$token->isGivenKind($tokenKindsFollowedByASingleSpace)) {
397✔
331
                continue;
397✔
332
            }
333

334
            $whitespaceTokenIndex = $index + 1;
380✔
335

336
            if ($tokens[$whitespaceTokenIndex]->equalsAny([',', ':', ';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE], [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE]])) {
380✔
337
                continue;
5✔
338
            }
339

340
            if (
341
                $token->isGivenKind(T_STATIC)
375✔
342
                && !$tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind([T_FN, T_FUNCTION, T_NS_SEPARATOR, T_STRING, T_VARIABLE, CT::T_ARRAY_TYPEHINT, CT::T_NULLABLE_TYPE])
375✔
343
            ) {
344
                continue;
2✔
345
            }
346

347
            if ($token->isGivenKind(T_OPEN_TAG)) {
373✔
348
                if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && !str_contains($tokens[$whitespaceTokenIndex]->getContent(), "\n") && !str_contains($token->getContent(), "\n")) {
21✔
349
                    $tokens->clearAt($whitespaceTokenIndex);
2✔
350
                }
351

352
                continue;
21✔
353
            }
354

355
            if ($token->isGivenKind(T_CLASS) && $tokens[$tokens->getNextMeaningfulToken($index)]->equals('(')) {
368✔
356
                continue;
2✔
357
            }
358

359
            if ($token->isGivenKind([T_EXTENDS, T_IMPLEMENTS]) && $this->isMultilineExtendsOrImplementsWithMoreThanOneAncestor($tokens, $index)) {
366✔
360
                continue;
2✔
361
            }
362

363
            if ($token->isGivenKind(T_RETURN) && $this->isMultiLineReturn($tokens, $index)) {
364✔
364
                continue;
9✔
365
            }
366

367
            if ($token->isGivenKind(T_CONST) && $this->isMultilineCommaSeparatedConstant($tokens, $index)) {
355✔
368
                continue;
2✔
369
            }
370

371
            if ($token->isComment() || $token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
353✔
372
                if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && str_contains($tokens[$whitespaceTokenIndex]->getContent(), "\n")) {
4✔
373
                    continue;
4✔
374
                }
375
            }
376

377
            if ($tokens[$whitespaceTokenIndex]->isWhitespace() && str_contains($tokens[$whitespaceTokenIndex]->getContent(), "\n")) {
353✔
378
                $nextNextToken = $tokens[$whitespaceTokenIndex + 1];
82✔
379
                if (\defined('T_ATTRIBUTE')) { // @TODO: drop condition and else when PHP 8.0+ is required
82✔
380
                    if ($nextNextToken->isGivenKind(T_ATTRIBUTE)) {
82✔
381
                        continue;
1✔
382
                    }
383
                } else {
384
                    if ($nextNextToken->isComment() && str_starts_with($nextNextToken->getContent(), '#[')) {
×
385
                        continue;
×
386
                    }
387
                }
388

389
                if ($nextNextToken->isGivenKind(T_DOC_COMMENT)) {
81✔
390
                    continue;
1✔
391
                }
392
            }
393

394
            $tokens->ensureWhitespaceAtIndex($whitespaceTokenIndex, 0, ' ');
351✔
395
        }
396
    }
397

398
    protected function createConfigurationDefinition(): FixerConfigurationResolverInterface
399
    {
400
        $tokenMapContainASingleSpaceKeys = array_keys(self::$tokenMapContainASingleSpace);
415✔
401
        $tokenMapPrecededByASingleSpaceKeys = array_keys(self::$tokenMapPrecededByASingleSpace);
415✔
402
        $tokenMapFollowedByASingleSpaceKeys = array_keys(self::$tokenMapFollowedByASingleSpace);
415✔
403

404
        return new FixerConfigurationResolver([
415✔
405
            (new FixerOptionBuilder('constructs_contain_a_single_space', 'List of constructs which must contain a single space.'))
415✔
406
                ->setAllowedTypes(['string[]'])
415✔
407
                ->setAllowedValues([new AllowedValueSubset($tokenMapContainASingleSpaceKeys)])
415✔
408
                ->setDefault($tokenMapContainASingleSpaceKeys)
415✔
409
                ->getOption(),
415✔
410
            (new FixerOptionBuilder('constructs_preceded_by_a_single_space', 'List of constructs which must be preceded by a single space.'))
415✔
411
                ->setAllowedTypes(['string[]'])
415✔
412
                ->setAllowedValues([new AllowedValueSubset($tokenMapPrecededByASingleSpaceKeys)])
415✔
413
                ->setDefault(['as', 'use_lambda'])
415✔
414
                ->getOption(),
415✔
415
            (new FixerOptionBuilder('constructs_followed_by_a_single_space', 'List of constructs which must be followed by a single space.'))
415✔
416
                ->setAllowedTypes(['string[]'])
415✔
417
                ->setAllowedValues([new AllowedValueSubset($tokenMapFollowedByASingleSpaceKeys)])
415✔
418
                ->setDefault($tokenMapFollowedByASingleSpaceKeys)
415✔
419
                ->getOption(),
415✔
420
        ]);
415✔
421
    }
422

423
    private function isMultiLineReturn(Tokens $tokens, int $index): bool
424
    {
425
        ++$index;
17✔
426
        $tokenFollowingReturn = $tokens[$index];
17✔
427

428
        if (
429
            !$tokenFollowingReturn->isGivenKind(T_WHITESPACE)
17✔
430
            || !str_contains($tokenFollowingReturn->getContent(), "\n")
17✔
431
        ) {
432
            return false;
8✔
433
        }
434

435
        $nestedCount = 0;
12✔
436

437
        for ($indexEnd = \count($tokens) - 1, ++$index; $index < $indexEnd; ++$index) {
12✔
438
            if (str_contains($tokens[$index]->getContent(), "\n")) {
12✔
439
                return true;
9✔
440
            }
441

442
            if ($tokens[$index]->equals('{')) {
12✔
443
                ++$nestedCount;
×
444
            } elseif ($tokens[$index]->equals('}')) {
12✔
445
                --$nestedCount;
×
446
            } elseif (0 === $nestedCount && $tokens[$index]->equalsAny([';', [T_CLOSE_TAG]])) {
12✔
447
                break;
×
448
            }
449
        }
450

451
        return false;
3✔
452
    }
453

454
    private function isMultilineExtendsOrImplementsWithMoreThanOneAncestor(Tokens $tokens, int $index): bool
455
    {
456
        $hasMoreThanOneAncestor = false;
26✔
457

458
        while (true) {
26✔
459
            ++$index;
26✔
460
            $token = $tokens[$index];
26✔
461

462
            if ($token->equals(',')) {
26✔
463
                $hasMoreThanOneAncestor = true;
6✔
464

465
                continue;
6✔
466
            }
467

468
            if ($token->equals('{')) {
26✔
469
                return false;
24✔
470
            }
471

472
            if ($hasMoreThanOneAncestor && str_contains($token->getContent(), "\n")) {
26✔
473
                return true;
2✔
474
            }
475
        }
476

NEW
477
        return LogicException('Not reachable code was reached.'); // @phpstan-ignore deadCode.unreachable
×
478
    }
479

480
    private function isMultilineCommaSeparatedConstant(Tokens $tokens, int $constantIndex): bool
481
    {
482
        $isMultilineConstant = false;
10✔
483
        $hasMoreThanOneConstant = false;
10✔
484
        $index = $constantIndex;
10✔
485
        while (!$tokens[$index]->equalsAny([';', [T_CLOSE_TAG]])) {
10✔
486
            ++$index;
10✔
487

488
            $isMultilineConstant = $isMultilineConstant || str_contains($tokens[$index]->getContent(), "\n");
10✔
489

490
            if ($tokens[$index]->equals(',')) {
10✔
491
                $hasMoreThanOneConstant = true;
2✔
492
            }
493

494
            $blockType = Tokens::detectBlockType($tokens[$index]);
10✔
495

496
            if (null !== $blockType && true === $blockType['isStart']) {
10✔
497
                $index = $tokens->findBlockEnd($blockType['type'], $index);
1✔
498
            }
499
        }
500

501
        return $hasMoreThanOneConstant && $isMultilineConstant;
10✔
502
    }
503

504
    private function isFullLineCommentBefore(Tokens $tokens, int $index): bool
505
    {
506
        $beforeIndex = $tokens->getPrevNonWhitespace($index);
29✔
507

508
        if (!$tokens[$beforeIndex]->isGivenKind([T_COMMENT])) {
29✔
509
            return false;
25✔
510
        }
511

512
        $content = $tokens[$beforeIndex]->getContent();
4✔
513

514
        return str_starts_with($content, '#') || str_starts_with($content, '//');
4✔
515
    }
516
}
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

© 2026 Coveralls, Inc