• 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

0.0
/src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php
1
<?php
2
/**
3
 * Runs the Zend Code Analyzer (from Zend Studio) on the file.
4
 *
5
 * @author    Holger Kral <holger.kral@zend.com>
6
 * @author    Greg Sherwood <gsherwood@squiz.net>
7
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
8
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
9
 *
10
 * @deprecated 3.9.0
11
 */
12

13
namespace PHP_CodeSniffer\Standards\Zend\Sniffs\Debug;
14

15
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
16
use PHP_CodeSniffer\Sniffs\Sniff;
17
use PHP_CodeSniffer\Files\File;
18
use PHP_CodeSniffer\Config;
19
use PHP_CodeSniffer\Exceptions\RuntimeException;
20
use PHP_CodeSniffer\Util\Common;
21

22
class CodeAnalyzerSniff implements Sniff, DeprecatedSniff
23
{
24

25

26
    /**
27
     * Returns the token types that this sniff is interested in.
28
     *
29
     * @return array<int|string>
30
     */
31
    public function register()
×
32
    {
33
        return [T_OPEN_TAG];
×
34

35
    }//end register()
36

37

38
    /**
39
     * Processes the tokens that this sniff is interested in.
40
     *
41
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
42
     * @param int                         $stackPtr  The position in the stack where
43
     *                                               the token was found.
44
     *
45
     * @return int
46
     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If ZendCodeAnalyzer could not be run.
47
     */
48
    public function process(File $phpcsFile, $stackPtr)
×
49
    {
50
        $analyzerPath = Config::getExecutablePath('zend_ca');
×
51
        if ($analyzerPath === null) {
×
52
            return $phpcsFile->numTokens;
×
53
        }
54

55
        $fileName = $phpcsFile->getFilename();
×
56

57
        // In the command, 2>&1 is important because the code analyzer sends its
58
        // findings to stderr. $output normally contains only stdout, so using 2>&1
59
        // will pipe even stderr to stdout.
60
        $cmd = Common::escapeshellcmd($analyzerPath).' '.escapeshellarg($fileName).' 2>&1';
×
61

62
        // There is the possibility to pass "--ide" as an option to the analyzer.
63
        // This would result in an output format which would be easier to parse.
64
        // The problem here is that no cleartext error messages are returned; only
65
        // error-code-labels. So for a start we go for cleartext output.
66
        $exitCode = exec($cmd, $output, $retval);
×
67

68
        // Variable $exitCode is the last line of $output if no error occurs, on
69
        // error it is numeric. Try to handle various error conditions and
70
        // provide useful error reporting.
71
        if (is_numeric($exitCode) === true && $exitCode > 0) {
×
72
            if (is_array($output) === true) {
×
73
                $msg = implode('\n', $output);
×
74
            }
75

76
            throw new RuntimeException("Failed invoking ZendCodeAnalyzer, exitcode was [$exitCode], retval was [$retval], output was [$msg]");
×
77
        }
78

79
        if (is_array($output) === true) {
×
80
            foreach ($output as $finding) {
×
81
                // The first two lines of analyzer output contain
82
                // something like this:
83
                // > Zend Code Analyzer 1.2.2
84
                // > Analyzing <filename>...
85
                // So skip these...
86
                $res = preg_match("/^.+\(line ([0-9]+)\):(.+)$/", $finding, $regs);
×
87
                if (empty($regs) === true || $res === false) {
×
88
                    continue;
×
89
                }
90

91
                $phpcsFile->addWarningOnLine(trim($regs[2]), $regs[1], 'ExternalTool');
×
92
            }
93
        }
94

95
        // Ignore the rest of the file.
96
        return $phpcsFile->numTokens;
×
97

98
    }//end process()
99

100

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

110
    }//end getDeprecationVersion()
111

112

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

122
    }//end getRemovalVersion()
123

124

125
    /**
126
     * Provide a custom message to display with the deprecation.
127
     *
128
     * @return string
129
     */
130
    public function getDeprecationMessage()
×
131
    {
132
        return '';
×
133

134
    }//end getDeprecationMessage()
135

136

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