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

PHPCSStandards / PHP_CodeSniffer / 17343936854

30 Aug 2025 12:45PM UTC coverage: 79.184% (+0.6%) from 78.578%
17343936854

Pull #1206

github

web-flow
Merge e70599f05 into ca606d9f6
Pull Request #1206: Tokenizer/PHP: improved tokenization of fully qualified exit/die/true/false/null

60 of 63 new or added lines in 5 files covered. (95.24%)

1 existing line in 1 file now uncovered.

25346 of 32009 relevant lines covered (79.18%)

74.34 hits per line

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

0.0
/src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php
1
<?php
2
/**
3
 * Runs gjslint on the file.
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\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 ClosureLinterSniff implements Sniff, DeprecatedSniff
21
{
22

23
    /**
24
     * A list of error codes that should show errors.
25
     *
26
     * All other error codes will show warnings.
27
     *
28
     * @var array
29
     */
30
    public $errorCodes = [];
31

32
    /**
33
     * A list of error codes to ignore.
34
     *
35
     * @var array
36
     */
37
    public $ignoreCodes = [];
38

39
    /**
40
     * A list of tokenizers this sniff supports.
41
     *
42
     * @var array
43
     */
44
    public $supportedTokenizers = ['JS'];
45

46

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

56
    }//end register()
57

58

59
    /**
60
     * Processes the tokens that this sniff is interested in.
61
     *
62
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
63
     * @param int                         $stackPtr  The position in the stack where
64
     *                                               the token was found.
65
     *
66
     * @return int
67
     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jslint.js could not be run.
68
     */
69
    public function process(File $phpcsFile, $stackPtr)
×
70
    {
71
        $lintPath = Config::getExecutablePath('gjslint');
×
72
        if ($lintPath === null) {
×
73
            return $phpcsFile->numTokens;
×
74
        }
75

76
        $fileName = $phpcsFile->getFilename();
×
77

78
        $lintPath = Common::escapeshellcmd($lintPath);
×
79
        $cmd      = $lintPath.' --nosummary --notime --unix_mode '.escapeshellarg($fileName);
×
80
        exec($cmd, $output, $retval);
×
81

82
        if (is_array($output) === false) {
×
83
            return $phpcsFile->numTokens;
×
84
        }
85

86
        foreach ($output as $finding) {
×
87
            $matches    = [];
×
88
            $numMatches = preg_match('/^(.*):([0-9]+):\(.*?([0-9]+)\)(.*)$/', $finding, $matches);
×
89
            if ($numMatches === 0) {
×
90
                continue;
×
91
            }
92

93
            // Skip error codes we are ignoring.
94
            $code = $matches[3];
×
95
            if (in_array($code, $this->ignoreCodes) === true) {
×
96
                continue;
×
97
            }
98

99
            $line  = (int) $matches[2];
×
100
            $error = trim($matches[4]);
×
101

102
            $message = 'gjslint says: (%s) %s';
×
103
            $data    = [
104
                $code,
×
105
                $error,
×
UNCOV
106
            ];
×
107
            if (in_array($code, $this->errorCodes) === true) {
×
108
                $phpcsFile->addErrorOnLine($message, $line, 'ExternalToolError', $data);
×
109
            } else {
110
                $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool', $data);
×
111
            }
112
        }//end foreach
113

114
        // Ignore the rest of the file.
115
        return $phpcsFile->numTokens;
×
116

117
    }//end process()
118

119

120
    /**
121
     * Provide the version number in which the sniff was deprecated.
122
     *
123
     * @return string
124
     */
125
    public function getDeprecationVersion()
×
126
    {
127
        return 'v3.9.0';
×
128

129
    }//end getDeprecationVersion()
130

131

132
    /**
133
     * Provide the version number in which the sniff will be removed.
134
     *
135
     * @return string
136
     */
137
    public function getRemovalVersion()
×
138
    {
139
        return 'v4.0.0';
×
140

141
    }//end getRemovalVersion()
142

143

144
    /**
145
     * Provide a custom message to display with the deprecation.
146
     *
147
     * @return string
148
     */
149
    public function getDeprecationMessage()
×
150
    {
151
        return 'Support for scanning JavaScript files will be removed completely in v4.0.0.';
×
152

153
    }//end getDeprecationMessage()
154

155

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

© 2025 Coveralls, Inc