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

PHP-CS-Fixer / PHP-CS-Fixer / 3721300657

pending completion
3721300657

push

github

GitHub
minor: Follow PSR12 ordered imports in Symfony ruleset (#6712)

9 of 9 new or added lines in 2 files covered. (100.0%)

22674 of 24281 relevant lines covered (93.38%)

39.08 hits per line

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

94.51
/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.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\ClassNotation;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
19
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
20
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
21
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
22
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
23
use PhpCsFixer\FixerDefinition\CodeSample;
24
use PhpCsFixer\FixerDefinition\FixerDefinition;
25
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
26
use PhpCsFixer\FixerDefinition\VersionSpecification;
27
use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
28
use PhpCsFixer\Preg;
29
use PhpCsFixer\Tokenizer\CT;
30
use PhpCsFixer\Tokenizer\Token;
31
use PhpCsFixer\Tokenizer\Tokens;
32
use PhpCsFixer\Tokenizer\TokensAnalyzer;
33
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
34

35
/**
36
 * Make sure there is one blank line above and below class elements.
37
 *
38
 * The exception is when an element is the first or last item in a 'classy'.
39
 */
40
final class ClassAttributesSeparationFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface
41
{
42
    /**
43
     * @internal
44
     */
45
    public const SPACING_NONE = 'none';
46

47
    /**
48
     * @internal
49
     */
50
    public const SPACING_ONE = 'one';
51

52
    private const SPACING_ONLY_IF_META = 'only_if_meta';
53

54
    /**
55
     * @var array<string, string>
56
     */
57
    private array $classElementTypes = [];
58

59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function configure(array $configuration): void
63
    {
64
        parent::configure($configuration);
101✔
65

66
        $this->classElementTypes = []; // reset previous configuration
101✔
67

68
        foreach ($this->configuration['elements'] as $elementType => $spacing) {
101✔
69
            $this->classElementTypes[$elementType] = $spacing;
101✔
70
        }
71
    }
72

73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getDefinition(): FixerDefinitionInterface
77
    {
78
        return new FixerDefinition(
3✔
79
            'Class, trait and interface elements must be separated with one or none blank line.',
3✔
80
            [
3✔
81
                new CodeSample(
3✔
82
                    '<?php
3✔
83
final class Sample
84
{
85
    protected function foo()
86
    {
87
    }
88
    protected function bar()
89
    {
90
    }
91

92

93
}
94
'
3✔
95
                ),
3✔
96
                new CodeSample(
3✔
97
                    '<?php
3✔
98
class Sample
99
{private $a; // foo
100
    /** second in a hour */
101
    private $b;
102
}
103
',
3✔
104
                    ['elements' => ['property' => self::SPACING_ONE]]
3✔
105
                ),
3✔
106
                new CodeSample(
3✔
107
                    '<?php
3✔
108
class Sample
109
{
110
    const A = 1;
111
    /** seconds in some hours */
112
    const B = 3600;
113
}
114
',
3✔
115
                    ['elements' => ['const' => self::SPACING_ONE]]
3✔
116
                ),
3✔
117
                new CodeSample(
3✔
118
                    '<?php
3✔
119
class Sample
120
{
121
    /** @var int */
122
    const SECOND = 1;
123
    /** @var int */
124
    const MINUTE = 60;
125

126
    const HOUR = 3600;
127

128
    const DAY = 86400;
129
}
130
',
3✔
131
                    ['elements' => ['const' => self::SPACING_ONLY_IF_META]]
3✔
132
                ),
3✔
133
                new VersionSpecificCodeSample(
3✔
134
                    '<?php
3✔
135
class Sample
136
{
137
    public $a;
138
    #[SetUp]
139
    public $b;
140
    /** @var string */
141
    public $c;
142
    /** @internal */
143
    #[Assert\String()]
144
    public $d;
145

146
    public $e;
147
}
148
',
3✔
149
                    new VersionSpecification(80000),
3✔
150
                    ['elements' => ['property' => self::SPACING_ONLY_IF_META]]
3✔
151
                ),
3✔
152
            ]
3✔
153
        );
3✔
154
    }
155

156
    /**
157
     * {@inheritdoc}
158
     *
159
     * Must run before BracesFixer, IndentationTypeFixer, NoExtraBlankLinesFixer, StatementIndentationFixer.
160
     * Must run after OrderedClassElementsFixer, SingleClassElementPerStatementFixer, VisibilityRequiredFixer.
161
     */
162
    public function getPriority(): int
163
    {
164
        return 55;
1✔
165
    }
166

167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function isCandidate(Tokens $tokens): bool
171
    {
172
        return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
86✔
173
    }
174

175
    /**
176
     * {@inheritdoc}
177
     */
178
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
179
    {
180
        foreach ($this->getElementsByClass($tokens) as $class) {
86✔
181
            $elements = $class['elements'];
85✔
182
            $elementCount = \count($elements);
85✔
183

184
            if (0 === $elementCount) {
85✔
185
                continue;
×
186
            }
187

188
            if (isset($this->classElementTypes[$elements[0]['type']])) {
85✔
189
                $this->fixSpaceBelowClassElement($tokens, $class);
82✔
190
                $this->fixSpaceAboveClassElement($tokens, $class, 0);
82✔
191
            }
192

193
            for ($index = 1; $index < $elementCount; ++$index) {
85✔
194
                if (isset($this->classElementTypes[$elements[$index]['type']])) {
61✔
195
                    $this->fixSpaceAboveClassElement($tokens, $class, $index);
60✔
196
                }
197
            }
198
        }
199
    }
200

201
    /**
202
     * {@inheritdoc}
203
     */
204
    protected function createConfigurationDefinition(): FixerConfigurationResolverInterface
205
    {
206
        return new FixerConfigurationResolver([
101✔
207
            (new FixerOptionBuilder('elements', 'Dictionary of `const|method|property|trait_import|case` => `none|one|only_if_meta` values.'))
101✔
208
                ->setAllowedTypes(['array'])
101✔
209
                ->setAllowedValues([static function (array $option): bool {
101✔
210
                    foreach ($option as $type => $spacing) {
101✔
211
                        $supportedTypes = ['const', 'method', 'property', 'trait_import', 'case'];
101✔
212

213
                        if (!\in_array($type, $supportedTypes, true)) {
101✔
214
                            throw new InvalidOptionsException(
2✔
215
                                sprintf(
2✔
216
                                    'Unexpected element type, expected any of "%s", got "%s".',
2✔
217
                                    implode('", "', $supportedTypes),
2✔
218
                                    \gettype($type).'#'.$type
2✔
219
                                )
2✔
220
                            );
2✔
221
                        }
222

223
                        $supportedSpacings = [self::SPACING_NONE, self::SPACING_ONE, self::SPACING_ONLY_IF_META];
101✔
224

225
                        if (!\in_array($spacing, $supportedSpacings, true)) {
101✔
226
                            throw new InvalidOptionsException(
1✔
227
                                sprintf(
1✔
228
                                    'Unexpected spacing for element type "%s", expected any of "%s", got "%s".',
1✔
229
                                    $spacing,
1✔
230
                                    implode('", "', $supportedSpacings),
1✔
231
                                    \is_object($spacing) ? \get_class($spacing) : (null === $spacing ? 'null' : \gettype($spacing).'#'.$spacing)
1✔
232
                                )
1✔
233
                            );
1✔
234
                        }
235
                    }
236

237
                    return true;
101✔
238
                }])
101✔
239
                ->setDefault([
101✔
240
                    'const' => self::SPACING_ONE,
101✔
241
                    'method' => self::SPACING_ONE,
101✔
242
                    'property' => self::SPACING_ONE,
101✔
243
                    'trait_import' => self::SPACING_NONE,
101✔
244
                    'case' => self::SPACING_NONE,
101✔
245
                ])
101✔
246
                ->getOption(),
101✔
247
        ]);
101✔
248
    }
249

250
    /**
251
     * Fix spacing above an element of a class, interface or trait.
252
     *
253
     * Deals with comments, PHPDocs and spaces above the element with respect to the position of the
254
     * element within the class, interface or trait.
255
     */
256
    private function fixSpaceAboveClassElement(Tokens $tokens, array $class, int $elementIndex): void
257
    {
258
        $element = $class['elements'][$elementIndex];
84✔
259
        $elementAboveEnd = isset($class['elements'][$elementIndex + 1]) ? $class['elements'][$elementIndex + 1]['end'] : 0;
84✔
260
        $nonWhiteAbove = $tokens->getPrevNonWhitespace($element['start']);
84✔
261

262
        // element is directly after class open brace
263
        if ($nonWhiteAbove === $class['open']) {
84✔
264
            $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 1);
60✔
265

266
            return;
60✔
267
        }
268

269
        // deal with comments above an element
270
        if ($tokens[$nonWhiteAbove]->isGivenKind(T_COMMENT)) {
75✔
271
            // check if the comment belongs to the previous element
272
            if ($elementAboveEnd === $nonWhiteAbove) {
22✔
273
                $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], $this->determineRequiredLineCount($tokens, $class, $elementIndex));
8✔
274

275
                return;
8✔
276
            }
277

278
            // more than one line break, always bring it back to 2 line breaks between the element start and what is above it
279
            if ($tokens[$nonWhiteAbove + 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove + 1]->getContent(), "\n") > 1) {
16✔
280
                $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 2);
8✔
281

282
                return;
8✔
283
            }
284

285
            // there are 2 cases:
286
            if (
287
                1 === $element['start'] - $nonWhiteAbove
10✔
288
                || $tokens[$nonWhiteAbove - 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove - 1]->getContent(), "\n") > 0
10✔
289
                || $tokens[$nonWhiteAbove + 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove + 1]->getContent(), "\n") > 0
10✔
290
            ) {
291
                // 1. The comment is meant for the element (although not a PHPDoc),
292
                //    make sure there is one line break between the element and the comment...
293
                $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 1);
10✔
294
                //    ... and make sure there is blank line above the comment (with the exception when it is directly after a class opening)
295
                $nonWhiteAbove = $this->findCommentBlockStart($tokens, $nonWhiteAbove, $elementAboveEnd);
10✔
296
                $nonWhiteAboveComment = $tokens->getPrevNonWhitespace($nonWhiteAbove);
10✔
297

298
                $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $nonWhiteAboveComment === $class['open'] ? 1 : 2);
10✔
299
            } else {
300
                // 2. The comment belongs to the code above the element,
301
                //    make sure there is a blank line above the element (i.e. 2 line breaks)
302
                $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 2);
×
303
            }
304

305
            return;
10✔
306
        }
307

308
        // deal with element with a PHPDoc/attribute above it
309
        if ($tokens[$nonWhiteAbove]->isGivenKind([T_DOC_COMMENT, CT::T_ATTRIBUTE_CLOSE])) {
61✔
310
            // there should be one linebreak between the element and the attribute above it
311
            $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 1);
24✔
312

313
            // make sure there is blank line above the comment (with the exception when it is directly after a class opening)
314
            $nonWhiteAbove = $this->findCommentBlockStart($tokens, $nonWhiteAbove, $elementAboveEnd);
24✔
315
            $nonWhiteAboveComment = $tokens->getPrevNonWhitespace($nonWhiteAbove);
24✔
316

317
            $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $nonWhiteAboveComment === $class['open'] ? 1 : 2);
24✔
318

319
            return;
24✔
320
        }
321

322
        $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], $this->determineRequiredLineCount($tokens, $class, $elementIndex));
51✔
323
    }
324

325
    private function determineRequiredLineCount(Tokens $tokens, array $class, int $elementIndex): int
326
    {
327
        $type = $class['elements'][$elementIndex]['type'];
52✔
328
        $spacing = $this->classElementTypes[$type];
52✔
329

330
        if (self::SPACING_ONE === $spacing) {
52✔
331
            return 2;
37✔
332
        }
333

334
        if (self::SPACING_NONE === $spacing) {
21✔
335
            if (!isset($class['elements'][$elementIndex + 1])) {
14✔
336
                return 1;
×
337
            }
338

339
            $aboveElement = $class['elements'][$elementIndex + 1];
14✔
340

341
            if ($aboveElement['type'] !== $type) {
14✔
342
                return 2;
2✔
343
            }
344

345
            $aboveElementDocCandidateIndex = $tokens->getPrevNonWhitespace($aboveElement['start']);
14✔
346

347
            return $tokens[$aboveElementDocCandidateIndex]->isGivenKind([T_DOC_COMMENT, CT::T_ATTRIBUTE_CLOSE]) ? 2 : 1;
14✔
348
        }
349

350
        if (self::SPACING_ONLY_IF_META === $spacing) {
7✔
351
            $aboveElementDocCandidateIndex = $tokens->getPrevNonWhitespace($class['elements'][$elementIndex]['start']);
7✔
352

353
            return $tokens[$aboveElementDocCandidateIndex]->isGivenKind([T_DOC_COMMENT, CT::T_ATTRIBUTE_CLOSE]) ? 2 : 1;
7✔
354
        }
355

356
        throw new \RuntimeException(sprintf('Unknown spacing "%s".', $spacing));
×
357
    }
358

359
    private function fixSpaceBelowClassElement(Tokens $tokens, array $class): void
360
    {
361
        $element = $class['elements'][0];
82✔
362

363
        // if this is last element fix; fix to the class end `}` here if appropriate
364
        if ($class['close'] === $tokens->getNextNonWhitespace($element['end'])) {
82✔
365
            $this->correctLineBreaks($tokens, $element['end'], $class['close'], 1);
82✔
366
        }
367
    }
368

369
    private function correctLineBreaks(Tokens $tokens, int $startIndex, int $endIndex, int $reqLineCount): void
370
    {
371
        $lineEnding = $this->whitespacesConfig->getLineEnding();
84✔
372

373
        ++$startIndex;
84✔
374
        $numbOfWhiteTokens = $endIndex - $startIndex;
84✔
375

376
        if (0 === $numbOfWhiteTokens) {
84✔
377
            $tokens->insertAt($startIndex, new Token([T_WHITESPACE, str_repeat($lineEnding, $reqLineCount)]));
17✔
378

379
            return;
17✔
380
        }
381

382
        $lineBreakCount = $this->getLineBreakCount($tokens, $startIndex, $endIndex);
84✔
383

384
        if ($reqLineCount === $lineBreakCount) {
84✔
385
            return;
84✔
386
        }
387

388
        if ($lineBreakCount < $reqLineCount) {
65✔
389
            $tokens[$startIndex] = new Token([
46✔
390
                T_WHITESPACE,
46✔
391
                str_repeat($lineEnding, $reqLineCount - $lineBreakCount).$tokens[$startIndex]->getContent(),
46✔
392
            ]);
46✔
393

394
            return;
46✔
395
        }
396

397
        // $lineCount = > $reqLineCount : check the one Token case first since this one will be true most of the time
398
        if (1 === $numbOfWhiteTokens) {
39✔
399
            $tokens[$startIndex] = new Token([
39✔
400
                T_WHITESPACE,
39✔
401
                Preg::replace('/\r\n|\n/', '', $tokens[$startIndex]->getContent(), $lineBreakCount - $reqLineCount),
39✔
402
            ]);
39✔
403

404
            return;
39✔
405
        }
406

407
        // $numbOfWhiteTokens = > 1
408
        $toReplaceCount = $lineBreakCount - $reqLineCount;
×
409

410
        for ($i = $startIndex; $i < $endIndex && $toReplaceCount > 0; ++$i) {
×
411
            $tokenLineCount = substr_count($tokens[$i]->getContent(), "\n");
×
412

413
            if ($tokenLineCount > 0) {
×
414
                $tokens[$i] = new Token([
×
415
                    T_WHITESPACE,
×
416
                    Preg::replace('/\r\n|\n/', '', $tokens[$i]->getContent(), min($toReplaceCount, $tokenLineCount)),
×
417
                ]);
×
418
                $toReplaceCount -= $tokenLineCount;
×
419
            }
420
        }
421
    }
422

423
    private function getLineBreakCount(Tokens $tokens, int $startIndex, int $endIndex): int
424
    {
425
        $lineCount = 0;
92✔
426

427
        for ($i = $startIndex; $i < $endIndex; ++$i) {
92✔
428
            $lineCount += substr_count($tokens[$i]->getContent(), "\n");
92✔
429
        }
430

431
        return $lineCount;
92✔
432
    }
433

434
    private function findCommentBlockStart(Tokens $tokens, int $start, int $elementAboveEnd): int
435
    {
436
        for ($i = $start; $i > $elementAboveEnd; --$i) {
41✔
437
            if ($tokens[$i]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
41✔
438
                $start = $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $i);
7✔
439

440
                continue;
7✔
441
            }
442

443
            if ($tokens[$i]->isComment()) {
41✔
444
                $start = $i;
36✔
445

446
                continue;
36✔
447
            }
448

449
            if (!$tokens[$i]->isWhitespace() || $this->getLineBreakCount($tokens, $i, $i + 1) > 1) {
41✔
450
                break;
37✔
451
            }
452
        }
453

454
        return $start;
41✔
455
    }
456

457
    private function getElementsByClass(Tokens $tokens): \Generator
458
    {
459
        $tokensAnalyzer = new TokensAnalyzer($tokens);
86✔
460
        $class = $classIndex = false;
86✔
461
        $elements = $tokensAnalyzer->getClassyElements();
86✔
462

463
        for (end($elements);; prev($elements)) {
86✔
464
            $index = key($elements);
86✔
465

466
            if (null === $index) {
86✔
467
                break;
86✔
468
            }
469

470
            $element = current($elements);
85✔
471
            $element['index'] = $index;
85✔
472

473
            if ($element['classIndex'] !== $classIndex) {
85✔
474
                if (false !== $class) {
85✔
475
                    yield $class;
4✔
476
                }
477

478
                $classIndex = $element['classIndex'];
85✔
479
                $classOpen = $tokens->getNextTokenOfKind($classIndex, ['{']);
85✔
480
                $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen);
85✔
481
                $class = [
85✔
482
                    'index' => $classIndex,
85✔
483
                    'open' => $classOpen,
85✔
484
                    'close' => $classEnd,
85✔
485
                    'elements' => [],
85✔
486
                ];
85✔
487
            }
488

489
            unset($element['classIndex']);
85✔
490
            $element['start'] = $this->getFirstTokenIndexOfClassElement($tokens, $class, $element);
85✔
491
            $element['end'] = $this->getLastTokenIndexOfClassElement($tokens, $class, $element, $tokensAnalyzer);
85✔
492

493
            $class['elements'][] = $element; // reset the key by design
85✔
494
        }
495

496
        if (false !== $class) {
86✔
497
            yield $class;
85✔
498
        }
499
    }
500

501
    private function getFirstTokenIndexOfClassElement(Tokens $tokens, array $class, array $element): int
502
    {
503
        $modifierTypes = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION];
85✔
504

505
        if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required
85✔
506
            $modifierTypes[] = T_READONLY;
85✔
507
        }
508

509
        $firstElementAttributeIndex = $element['index'];
85✔
510

511
        do {
512
            $nonWhiteAbove = $tokens->getPrevMeaningfulToken($firstElementAttributeIndex);
85✔
513

514
            if (null !== $nonWhiteAbove && $tokens[$nonWhiteAbove]->isGivenKind($modifierTypes)) {
85✔
515
                $firstElementAttributeIndex = $nonWhiteAbove;
71✔
516
            } else {
517
                break;
85✔
518
            }
519
        } while ($firstElementAttributeIndex > $class['open']);
71✔
520

521
        return $firstElementAttributeIndex;
85✔
522
    }
523

524
    // including trailing single line comments if belonging to the class element
525
    private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, array $element, TokensAnalyzer $tokensAnalyzer): int
526
    {
527
        // find last token of the element
528
        if ('method' === $element['type'] && !$tokens[$class['index']]->isGivenKind(T_INTERFACE)) {
85✔
529
            $attributes = $tokensAnalyzer->getMethodAttributes($element['index']);
52✔
530

531
            if (true === $attributes['abstract']) {
52✔
532
                $elementEndIndex = $tokens->getNextTokenOfKind($element['index'], [';']);
5✔
533
            } else {
534
                $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{']));
52✔
535
            }
536
        } elseif ('trait_import' === $element['type']) {
56✔
537
            $elementEndIndex = $element['index'];
12✔
538

539
            do {
540
                $elementEndIndex = $tokens->getNextMeaningfulToken($elementEndIndex);
12✔
541
            } while ($tokens[$elementEndIndex]->isGivenKind([T_STRING, T_NS_SEPARATOR]) || $tokens[$elementEndIndex]->equals(','));
12✔
542

543
            if (!$tokens[$elementEndIndex]->equals(';')) {
12✔
544
                $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{']));
12✔
545
            }
546
        } else { // 'const', 'property', enum-'case', or 'method' of an interface
547
            $elementEndIndex = $tokens->getNextTokenOfKind($element['index'], [';']);
46✔
548
        }
549

550
        $singleLineElement = true;
85✔
551

552
        for ($i = $element['index'] + 1; $i < $elementEndIndex; ++$i) {
85✔
553
            if (str_contains($tokens[$i]->getContent(), "\n")) {
69✔
554
                $singleLineElement = false;
30✔
555

556
                break;
30✔
557
            }
558
        }
559

560
        if ($singleLineElement) {
85✔
561
            while (true) {
70✔
562
                $nextToken = $tokens[$elementEndIndex + 1];
70✔
563

564
                if (($nextToken->isComment() || $nextToken->isWhitespace()) && !str_contains($nextToken->getContent(), "\n")) {
70✔
565
                    ++$elementEndIndex;
14✔
566
                } else {
567
                    break;
70✔
568
                }
569
            }
570

571
            if ($tokens[$elementEndIndex]->isWhitespace()) {
70✔
572
                $elementEndIndex = $tokens->getPrevNonWhitespace($elementEndIndex);
2✔
573
            }
574
        }
575

576
        return $elementEndIndex;
85✔
577
    }
578
}
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