• 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

58.93
/src/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php
1
<?php
2
/**
3
 * Bans the use of some styles, such as deprecated or browser-specific styles.
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

18
class ForbiddenStylesSniff 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
     * A list of forbidden styles with their alternatives.
30
     *
31
     * The value is NULL if no alternative exists. i.e., the
32
     * style should just not be used.
33
     *
34
     * @var array<string, string|null>
35
     */
36
    protected $forbiddenStyles = [
37
        '-moz-border-radius'             => 'border-radius',
38
        '-webkit-border-radius'          => 'border-radius',
39
        '-moz-border-radius-topleft'     => 'border-top-left-radius',
40
        '-moz-border-radius-topright'    => 'border-top-right-radius',
41
        '-moz-border-radius-bottomright' => 'border-bottom-right-radius',
42
        '-moz-border-radius-bottomleft'  => 'border-bottom-left-radius',
43
        '-moz-box-shadow'                => 'box-shadow',
44
        '-webkit-box-shadow'             => 'box-shadow',
45
    ];
46

47
    /**
48
     * A cache of forbidden style names, for faster lookups.
49
     *
50
     * @var string[]
51
     */
52
    protected $forbiddenStyleNames = [];
53

54
    /**
55
     * If true, forbidden styles will be considered regular expressions.
56
     *
57
     * @var boolean
58
     */
59
    protected $patternMatch = false;
60

61
    /**
62
     * If true, an error will be thrown; otherwise a warning.
63
     *
64
     * @var boolean
65
     */
66
    public $error = true;
67

68

69
    /**
70
     * Returns an array of tokens this test wants to listen for.
71
     *
72
     * @return array<int|string>
73
     */
74
    public function register()
3✔
75
    {
76
        $this->forbiddenStyleNames = array_keys($this->forbiddenStyles);
3✔
77

78
        if ($this->patternMatch === true) {
3✔
79
            foreach ($this->forbiddenStyleNames as $i => $name) {
×
80
                $this->forbiddenStyleNames[$i] = '/'.$name.'/i';
×
81
            }
82
        }
83

84
        return [T_STYLE];
3✔
85

86
    }//end register()
87

88

89
    /**
90
     * Processes this test, when one of its tokens is encountered.
91
     *
92
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
93
     * @param int                         $stackPtr  The position of the current token in
94
     *                                               the stack passed in $tokens.
95
     *
96
     * @return void
97
     */
98
    public function process(File $phpcsFile, $stackPtr)
3✔
99
    {
100
        $tokens  = $phpcsFile->getTokens();
3✔
101
        $style   = strtolower($tokens[$stackPtr]['content']);
3✔
102
        $pattern = null;
3✔
103

104
        if ($this->patternMatch === true) {
3✔
105
            $count   = 0;
×
106
            $pattern = preg_replace(
×
107
                $this->forbiddenStyleNames,
×
108
                $this->forbiddenStyleNames,
×
109
                $style,
×
110
                1,
×
111
                $count
112
            );
113

114
            if ($count === 0) {
×
115
                return;
×
116
            }
117

118
            // Remove the pattern delimiters and modifier.
119
            $pattern = substr($pattern, 1, -2);
×
120
        } else {
121
            if (in_array($style, $this->forbiddenStyleNames, true) === false) {
3✔
122
                return;
3✔
123
            }
124
        }//end if
125

126
        $this->addError($phpcsFile, $stackPtr, $style, $pattern);
3✔
127

128
    }//end process()
2✔
129

130

131
    /**
132
     * Generates the error or warning for this sniff.
133
     *
134
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
135
     * @param int                         $stackPtr  The position of the forbidden style
136
     *                                               in the token array.
137
     * @param string                      $style     The name of the forbidden style.
138
     * @param string                      $pattern   The pattern used for the match.
139
     *
140
     * @return void
141
     */
142
    protected function addError($phpcsFile, $stackPtr, $style, $pattern=null)
3✔
143
    {
144
        $data  = [$style];
3✔
145
        $error = 'The use of style %s is ';
3✔
146
        if ($this->error === true) {
3✔
147
            $type   = 'Found';
3✔
148
            $error .= 'forbidden';
3✔
149
        } else {
1✔
150
            $type   = 'Discouraged';
×
151
            $error .= 'discouraged';
×
152
        }
153

154
        if ($pattern === null) {
3✔
155
            $pattern = $style;
3✔
156
        }
1✔
157

158
        if ($this->forbiddenStyles[$pattern] !== null) {
3✔
159
            $data[] = $this->forbiddenStyles[$pattern];
3✔
160
            if ($this->error === true) {
3✔
161
                $fix = $phpcsFile->addFixableError($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data);
3✔
162
            } else {
1✔
163
                $fix = $phpcsFile->addFixableWarning($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data);
×
164
            }
165

166
            if ($fix === true) {
3✔
167
                $phpcsFile->fixer->replaceToken($stackPtr, $this->forbiddenStyles[$pattern]);
3✔
168
            }
1✔
169
        } else {
1✔
170
            if ($this->error === true) {
×
171
                $phpcsFile->addError($error, $stackPtr, $type, $data);
×
172
            } else {
173
                $phpcsFile->addWarning($error, $stackPtr, $type, $data);
×
174
            }
175
        }
176

177
    }//end addError()
2✔
178

179

180
    /**
181
     * Provide the version number in which the sniff was deprecated.
182
     *
183
     * @return string
184
     */
185
    public function getDeprecationVersion()
×
186
    {
187
        return 'v3.9.0';
×
188

189
    }//end getDeprecationVersion()
190

191

192
    /**
193
     * Provide the version number in which the sniff will be removed.
194
     *
195
     * @return string
196
     */
197
    public function getRemovalVersion()
×
198
    {
199
        return 'v4.0.0';
×
200

201
    }//end getRemovalVersion()
202

203

204
    /**
205
     * Provide a custom message to display with the deprecation.
206
     *
207
     * @return string
208
     */
209
    public function getDeprecationMessage()
×
210
    {
211
        return 'Support for scanning CSS files will be removed completely in v4.0.0.';
×
212

213
    }//end getDeprecationMessage()
214

215

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