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

PHPCSStandards / PHP_CodeSniffer / 18079229190

19 Sep 2025 11:00PM UTC coverage: 78.601% (-0.6%) from 79.178%
18079229190

push

github

jrfnl
Dependabot: remove `cooldown`

Follow up on PR 1273

Turns out that the `cooldown` configuration option is not supported for the `github-actions` ecosystem.... _sigh_

So I guess I better remove it again as otherwise Dependabot is blocked from running due to this "configuration error".

25341 of 32240 relevant lines covered (78.6%)

74.7 hits per line

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

86.54
/src/Standards/Squiz/Sniffs/CSS/DuplicateClassDefinitionSniff.php
1
<?php
2
/**
3
 * Check for duplicate class definitions that can be merged into one.
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/HEAD/licence.txt BSD Licence
8
 *
9
 * @deprecated 3.9.0
10
 */
11

12
namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS;
13

14
use PHP_CodeSniffer\Files\File;
15
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
16
use PHP_CodeSniffer\Sniffs\Sniff;
17
use PHP_CodeSniffer\Util\Tokens;
18

19
class DuplicateClassDefinitionSniff implements Sniff, DeprecatedSniff
20
{
21

22
    /**
23
     * A list of tokenizers this sniff supports.
24
     *
25
     * @var array
26
     */
27
    public $supportedTokenizers = ['CSS'];
28

29

30
    /**
31
     * Returns the token types that this sniff is interested in.
32
     *
33
     * @return array<int|string>
34
     */
35
    public function register()
3✔
36
    {
37
        return [T_OPEN_TAG];
3✔
38

39
    }//end register()
40

41

42
    /**
43
     * Processes the tokens that this sniff is interested in.
44
     *
45
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
46
     * @param int                         $stackPtr  The position in the stack where
47
     *                                               the token was found.
48
     *
49
     * @return void
50
     */
51
    public function process(File $phpcsFile, $stackPtr)
3✔
52
    {
53
        $tokens = $phpcsFile->getTokens();
3✔
54

55
        // Find the content of each class definition name.
56
        $classNames = [];
3✔
57
        $next       = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1));
3✔
58
        if ($next === false) {
3✔
59
            // No class definitions in the file.
60
            return;
×
61
        }
62

63
        // Save the class names in a "scope",
64
        // to prevent false positives with @media blocks.
65
        $scope = 'main';
3✔
66

67
        $find = [
1✔
68
            T_CLOSE_CURLY_BRACKET,
3✔
69
            T_OPEN_CURLY_BRACKET,
3✔
70
            T_OPEN_TAG,
3✔
71
        ];
2✔
72

73
        while ($next !== false) {
3✔
74
            $prev = $phpcsFile->findPrevious($find, ($next - 1));
3✔
75

76
            // Check if an inner block was closed.
77
            $beforePrev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true);
3✔
78
            if ($beforePrev !== false
2✔
79
                && $tokens[$beforePrev]['code'] === T_CLOSE_CURLY_BRACKET
3✔
80
            ) {
1✔
81
                $scope = 'main';
3✔
82
            }
1✔
83

84
            // Create a sorted name for the class so we can compare classes
85
            // even when the individual names are all over the place.
86
            $name = '';
3✔
87
            for ($i = ($prev + 1); $i < $next; $i++) {
3✔
88
                $name .= $tokens[$i]['content'];
3✔
89
            }
1✔
90

91
            $name = trim($name);
3✔
92
            $name = str_replace("\n", ' ', $name);
3✔
93
            $name = preg_replace('|[\s]+|', ' ', $name);
3✔
94
            $name = preg_replace('|\s*/\*.*\*/\s*|', '', $name);
3✔
95
            $name = str_replace(', ', ',', $name);
3✔
96

97
            $names = explode(',', $name);
3✔
98
            sort($names);
3✔
99
            $name = implode(',', $names);
3✔
100

101
            if ($name[0] === '@') {
3✔
102
                // Media block has its own "scope".
103
                $scope = $name;
3✔
104
            } else if (isset($classNames[$scope][$name]) === true) {
3✔
105
                $first = $classNames[$scope][$name];
3✔
106
                $error = 'Duplicate class definition found; first defined on line %s';
3✔
107
                $data  = [$tokens[$first]['line']];
3✔
108
                $phpcsFile->addError($error, $next, 'Found', $data);
3✔
109
            } else {
1✔
110
                $classNames[$scope][$name] = $next;
3✔
111
            }
112

113
            $next = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($next + 1));
3✔
114
        }//end while
1✔
115

116
    }//end process()
2✔
117

118

119
    /**
120
     * Provide the version number in which the sniff was deprecated.
121
     *
122
     * @return string
123
     */
124
    public function getDeprecationVersion()
×
125
    {
126
        return 'v3.9.0';
×
127

128
    }//end getDeprecationVersion()
129

130

131
    /**
132
     * Provide the version number in which the sniff will be removed.
133
     *
134
     * @return string
135
     */
136
    public function getRemovalVersion()
×
137
    {
138
        return 'v4.0.0';
×
139

140
    }//end getRemovalVersion()
141

142

143
    /**
144
     * Provide a custom message to display with the deprecation.
145
     *
146
     * @return string
147
     */
148
    public function getDeprecationMessage()
×
149
    {
150
        return 'Support for scanning CSS files will be removed completely in v4.0.0.';
×
151

152
    }//end getDeprecationMessage()
153

154

155
}//end class
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