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

NexusPHP / cs-config / 6078833893

05 Sep 2023 12:44AM UTC coverage: 98.586%. Remained the same
6078833893

Pull #3

github

web-flow
Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #3: Bump actions/checkout from 3 to 4

2928 of 2970 relevant lines covered (98.59%)

24.29 hits per line

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

96.55
/src/Fixer/Comment/NoCodeSeparatorCommentFixer.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Nexus CS Config.
7
 *
8
 * (c) 2020 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Nexus\CsConfig\Fixer\Comment;
15

16
use Nexus\CsConfig\Fixer\AbstractCustomFixer;
17
use PhpCsFixer\FixerDefinition\CodeSample;
18
use PhpCsFixer\FixerDefinition\FixerDefinition;
19
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
20
use PhpCsFixer\Tokenizer\Token;
21
use PhpCsFixer\Tokenizer\Tokens;
22

23
/**
24
 * Removes code separator comments except when used as section boundary.
25
 */
26
final class NoCodeSeparatorCommentFixer extends AbstractCustomFixer
27
{
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function getDefinition(): FixerDefinitionInterface
32
    {
33
        return new FixerDefinition(
9✔
34
            'There should not be any code separator comments.',
9✔
35
            [new CodeSample(
9✔
36
                <<<'EOF'
9✔
37
                    <?php
38

39
                    $code = 'a';
40

41
                    //------------------------
42

43
                    $arr = [];
44

45
                    EOF,
9✔
46
            )],
9✔
47
        );
9✔
48
    }
49

50
    /**
51
     * {@inheritDoc}
52
     */
53
    public function isCandidate(Tokens $tokens): bool
54
    {
55
        return $tokens->isTokenKindFound(T_COMMENT);
12✔
56
    }
57

58
    /**
59
     * {@inheritDoc}
60
     *
61
     * Must run before NoEmptyCommentFixer, SpaceAfterCommentStartFixer
62
     */
63
    public function getPriority(): int
64
    {
65
        return 2;
×
66
    }
67

68
    /**
69
     * {@inheritDoc}
70
     */
71
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
72
    {
73
        for ($index = 1, $count = $tokens->count(); $index < $count; ++$index) {
12✔
74
            /** @var Token $token */
75
            $token = $tokens[$index];
12✔
76

77
            if (! $token->isGivenKind(T_COMMENT)) {
12✔
78
                continue;
12✔
79
            }
80

81
            if (! $this->isCodeSeparatorComment($token->getContent())) {
12✔
82
                continue;
6✔
83
            }
84

85
            if ($this->isCommentBlockBoundary($tokens, $index)) {
9✔
86
                continue;
3✔
87
            }
88

89
            $tokens->removeLeadingWhitespace($index);
9✔
90
            $tokens->clearTokenAndMergeSurroundingWhitespace($index);
9✔
91
        }
92
    }
93

94
    /**
95
     * Checks if the recurring code separator comment is part of a comment
96
     * boundary that serves as a logical division between sections of code.
97
     *
98
     * ```
99
     * //================================== <-- this is used as a boundary
100
     * // SECTION
101
     * //================================== <-- this is used as a boundary
102
     *
103
     * //================================== <-- this is NOT a boundary
104
     *
105
     * ```
106
     */
107
    private function isCommentBlockBoundary(Tokens $tokens, int $index): bool
108
    {
109
        $prevIndex = $tokens->getPrevNonWhitespace($index);
9✔
110
        $nextIndex = $tokens->getNextNonWhitespace($index);
9✔
111

112
        /** @var Token $prevToken */
113
        $prevToken = $tokens[$prevIndex];
9✔
114
        $prevTokenIsRegularComment = $prevToken->isGivenKind(T_COMMENT)
9✔
115
            && ! $this->isCodeSeparatorComment($prevToken->getContent());
9✔
116

117
        /** @var Token $nextToken */
118
        $nextToken = $tokens[$nextIndex];
9✔
119
        $nextTokenIsRegularComment = $nextToken->isGivenKind(T_COMMENT)
9✔
120
            && ! $this->isCodeSeparatorComment($nextToken->getContent());
9✔
121

122
        return $prevTokenIsRegularComment || $nextTokenIsRegularComment;
9✔
123
    }
124

125
    private function isCodeSeparatorComment(string $comment): bool
126
    {
127
        return preg_match('/^\/\/\s*[-|=]+$/', $comment) === 1;
12✔
128
    }
129
}
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