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

PHPCSStandards / PHP_CodeSniffer / 17483947696

05 Sep 2025 04:45AM UTC coverage: 78.507% (-0.7%) from 79.184%
17483947696

push

github

web-flow
Merge pull request #1213 from PHPCSStandards/feature/remove-filelist-tests

:fire: Hot Fix: remove FileList tests

25309 of 32238 relevant lines covered (78.51%)

73.81 hits per line

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

86.67
/src/Standards/Squiz/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php
1
<?php
2
/**
3
 * Ensure there are no blank lines between the names of classes/IDs.
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
 * @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 ClassDefinitionNameSpacingSniff 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_CURLY_BRACKET];
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
        if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
3✔
56
            // Syntax error or live coding, bow out.
57
            return;
3✔
58
        }
59

60
        // Do not check nested style definitions as, for example, in @media style rules.
61
        $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
3✔
62
        if ($nested !== false) {
3✔
63
            return;
3✔
64
        }
65

66
        // Find the first blank line before this opening brace, unless we get
67
        // to another style definition, comment or the start of the file.
68
        $endTokens  = [
1✔
69
            T_OPEN_CURLY_BRACKET  => T_OPEN_CURLY_BRACKET,
3✔
70
            T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
3✔
71
            T_OPEN_TAG            => T_OPEN_TAG,
3✔
72
        ];
2✔
73
        $endTokens += Tokens::$commentTokens;
3✔
74

75
        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
3✔
76

77
        $foundContent = false;
3✔
78
        $currentLine  = $tokens[$prev]['line'];
3✔
79
        for ($i = ($stackPtr - 1); $i >= 0; $i--) {
3✔
80
            if (isset($endTokens[$tokens[$i]['code']]) === true) {
3✔
81
                break;
3✔
82
            }
83

84
            if ($tokens[$i]['line'] === $currentLine) {
3✔
85
                if ($tokens[$i]['code'] !== T_WHITESPACE) {
3✔
86
                    $foundContent = true;
3✔
87
                }
1✔
88

89
                continue;
3✔
90
            }
91

92
            // We changed lines.
93
            if ($foundContent === false) {
3✔
94
                // Before we throw an error, make sure we are not looking
95
                // at a gap before the style definition.
96
                $prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true);
3✔
97
                if ($prev !== false
2✔
98
                    && isset($endTokens[$tokens[$prev]['code']]) === false
3✔
99
                ) {
1✔
100
                    $error = 'Blank lines are not allowed between class names';
3✔
101
                    $phpcsFile->addError($error, ($i + 1), 'BlankLinesFound');
3✔
102
                }
1✔
103

104
                break;
3✔
105
            }
106

107
            $foundContent = false;
3✔
108
            $currentLine  = $tokens[$i]['line'];
3✔
109
        }//end for
1✔
110

111
    }//end process()
2✔
112

113

114
    /**
115
     * Provide the version number in which the sniff was deprecated.
116
     *
117
     * @return string
118
     */
119
    public function getDeprecationVersion()
×
120
    {
121
        return 'v3.9.0';
×
122

123
    }//end getDeprecationVersion()
124

125

126
    /**
127
     * Provide the version number in which the sniff will be removed.
128
     *
129
     * @return string
130
     */
131
    public function getRemovalVersion()
×
132
    {
133
        return 'v4.0.0';
×
134

135
    }//end getRemovalVersion()
136

137

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

147
    }//end getDeprecationMessage()
148

149

150
}//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