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

PHPCSStandards / PHP_CodeSniffer / 15036337869

15 May 2025 04:03AM UTC coverage: 78.375% (-0.2%) from 78.556%
15036337869

Pull #856

github

web-flow
Merge 93f570b46 into f5e7943d0
Pull Request #856: [Doc] Cover all errors of PEAR ClassDeclaration

25112 of 32041 relevant lines covered (78.37%)

69.4 hits per line

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

80.65
/src/Standards/Squiz/Sniffs/CSS/DuplicateStyleDefinitionSniff.php
1
<?php
2
/**
3
 * Check for duplicate style definitions in the same class.
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

18
class DuplicateStyleDefinitionSniff implements Sniff, DeprecatedSniff
19
{
20

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

28

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

38
    }//end register()
39

40

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

54
        if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
3✔
55
            // Syntax error or live coding, bow out.
56
            return;
3✔
57
        }
58

59
        // Find the content of each style definition name.
60
        $styleNames = [];
3✔
61

62
        $next = $stackPtr;
3✔
63
        $end  = $tokens[$stackPtr]['bracket_closer'];
3✔
64

65
        do {
66
            $next = $phpcsFile->findNext([T_STYLE, T_OPEN_CURLY_BRACKET], ($next + 1), $end);
3✔
67
            if ($next === false) {
3✔
68
                // Class definition is empty.
69
                break;
3✔
70
            }
71

72
            if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) {
3✔
73
                $next = $tokens[$next]['bracket_closer'];
3✔
74
                continue;
3✔
75
            }
76

77
            $name = $tokens[$next]['content'];
3✔
78
            if (isset($styleNames[$name]) === true) {
3✔
79
                $first = $styleNames[$name];
3✔
80
                $error = 'Duplicate style definition found; first defined on line %s';
3✔
81
                $data  = [$tokens[$first]['line']];
3✔
82
                $phpcsFile->addError($error, $next, 'Found', $data);
3✔
83
            } else {
1✔
84
                $styleNames[$name] = $next;
3✔
85
            }
86
        } while ($next !== false);
3✔
87

88
    }//end process()
2✔
89

90

91
    /**
92
     * Provide the version number in which the sniff was deprecated.
93
     *
94
     * @return string
95
     */
96
    public function getDeprecationVersion()
×
97
    {
98
        return 'v3.9.0';
×
99

100
    }//end getDeprecationVersion()
101

102

103
    /**
104
     * Provide the version number in which the sniff will be removed.
105
     *
106
     * @return string
107
     */
108
    public function getRemovalVersion()
×
109
    {
110
        return 'v4.0.0';
×
111

112
    }//end getRemovalVersion()
113

114

115
    /**
116
     * Provide a custom message to display with the deprecation.
117
     *
118
     * @return string
119
     */
120
    public function getDeprecationMessage()
×
121
    {
122
        return 'Support for scanning CSS files will be removed completely in v4.0.0.';
×
123

124
    }//end getDeprecationMessage()
125

126

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