• 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

69.57
/src/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php
1
<?php
2
/**
3
 * Ensure that browser-specific styles are not used.
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\MySource\Sniffs\CSS;
13

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

18
class BrowserSpecificStylesSniff 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 specific stylesheet suffixes we allow.
30
     *
31
     * These stylesheets contain browser specific styles
32
     * so this sniff ignore them files in the form:
33
     * *_moz.css and *_ie7.css etc.
34
     *
35
     * @var array
36
     */
37
    protected $specificStylesheets = [
38
        'moz'    => true,
39
        'ie'     => true,
40
        'ie7'    => true,
41
        'ie8'    => true,
42
        'webkit' => true,
43
    ];
44

45

46
    /**
47
     * Returns the token types that this sniff is interested in.
48
     *
49
     * @return array<int|string>
50
     */
51
    public function register()
3✔
52
    {
53
        return [T_STYLE];
3✔
54

55
    }//end register()
56

57

58
    /**
59
     * Processes the tokens that this sniff is interested in.
60
     *
61
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
62
     * @param int                         $stackPtr  The position in the stack where
63
     *                                               the token was found.
64
     *
65
     * @return void
66
     */
67
    public function process(File $phpcsFile, $stackPtr)
3✔
68
    {
69
        // Ignore files with browser-specific suffixes.
70
        $filename  = $phpcsFile->getFilename();
3✔
71
        $breakChar = strrpos($filename, '_');
3✔
72
        if ($breakChar !== false && substr($filename, -4) === '.css') {
3✔
73
            $specific = substr($filename, ($breakChar + 1), -4);
3✔
74
            if (isset($this->specificStylesheets[$specific]) === true) {
3✔
75
                return;
×
76
            }
77
        }
1✔
78

79
        $tokens  = $phpcsFile->getTokens();
3✔
80
        $content = $tokens[$stackPtr]['content'];
3✔
81

82
        if ($content[0] === '-') {
3✔
83
            $error = 'Browser-specific styles are not allowed';
3✔
84
            $phpcsFile->addError($error, $stackPtr, 'ForbiddenStyle');
3✔
85
        }
1✔
86

87
    }//end process()
2✔
88

89

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

99
    }//end getDeprecationVersion()
100

101

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

111
    }//end getRemovalVersion()
112

113

114
    /**
115
     * Provide a custom message to display with the deprecation.
116
     *
117
     * @return string
118
     */
119
    public function getDeprecationMessage()
×
120
    {
121
        return 'The MySource standard will be removed completely in v4.0.0.';
×
122

123
    }//end getDeprecationMessage()
124

125

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