• 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

75.76
/src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php
1
<?php
2
/**
3
 * Runs csslint on the file.
4
 *
5
 * @author    Roman Levishchenko <index.0h@gmail.com>
6
 * @copyright 2013-2014 Roman Levishchenko
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\Generic\Sniffs\Debug;
13

14
use PHP_CodeSniffer\Config;
15
use PHP_CodeSniffer\Files\File;
16
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
17
use PHP_CodeSniffer\Sniffs\Sniff;
18
use PHP_CodeSniffer\Util\Common;
19

20
class CSSLintSniff implements Sniff, DeprecatedSniff
21
{
22

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

30

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

40
    }//end register()
41

42

43
    /**
44
     * Processes the tokens that this sniff is interested in.
45
     *
46
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
47
     * @param int                         $stackPtr  The position in the stack where
48
     *                                               the token was found.
49
     *
50
     * @return int
51
     */
52
    public function process(File $phpcsFile, $stackPtr)
4✔
53
    {
54
        $csslintPath = Config::getExecutablePath('csslint');
4✔
55
        if ($csslintPath === null) {
4✔
56
            return $phpcsFile->numTokens;
×
57
        }
58

59
        $fileName = $phpcsFile->getFilename();
4✔
60

61
        $cmd = Common::escapeshellcmd($csslintPath).' '.escapeshellarg($fileName).' 2>&1';
4✔
62
        exec($cmd, $output, $retval);
4✔
63

64
        if (is_array($output) === false) {
4✔
65
            return $phpcsFile->numTokens;
×
66
        }
67

68
        $count = count($output);
4✔
69

70
        for ($i = 0; $i < $count; $i++) {
4✔
71
            $matches    = [];
4✔
72
            $numMatches = preg_match(
4✔
73
                '/(error|warning) at line (\d+)/',
4✔
74
                $output[$i],
4✔
75
                $matches
2✔
76
            );
4✔
77

78
            if ($numMatches === 0) {
4✔
79
                continue;
4✔
80
            }
81

82
            $line    = (int) $matches[2];
4✔
83
            $message = 'csslint says: '.$output[($i + 1)];
4✔
84
            // First line is message with error line and error code.
85
            // Second is error message.
86
            // Third is wrong line in file.
87
            // Fourth is empty line.
88
            $i += 4;
4✔
89

90
            $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
4✔
91
        }//end for
2✔
92

93
        // Ignore the rest of the file.
94
        return $phpcsFile->numTokens;
4✔
95

96
    }//end process()
97

98

99
    /**
100
     * Provide the version number in which the sniff was deprecated.
101
     *
102
     * @return string
103
     */
104
    public function getDeprecationVersion()
×
105
    {
106
        return 'v3.9.0';
×
107

108
    }//end getDeprecationVersion()
109

110

111
    /**
112
     * Provide the version number in which the sniff will be removed.
113
     *
114
     * @return string
115
     */
116
    public function getRemovalVersion()
×
117
    {
118
        return 'v4.0.0';
×
119

120
    }//end getRemovalVersion()
121

122

123
    /**
124
     * Provide a custom message to display with the deprecation.
125
     *
126
     * @return string
127
     */
128
    public function getDeprecationMessage()
×
129
    {
130
        return 'Support for scanning CSS files will be removed completely in v4.0.0.';
×
131

132
    }//end getDeprecationMessage()
133

134

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