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

PHPCSStandards / PHP_CodeSniffer / 8604248433

08 Apr 2024 05:26PM UTC coverage: 72.354%. Remained the same
8604248433

push

github

jrfnl
CS: use `implode()` not `join()`

The `join()` function in PHP is an alias of `implode()`, so let's use the proper function name.

1 of 2 new or added lines in 2 files covered. (50.0%)

17360 of 23993 relevant lines covered (72.35%)

55.29 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\Sniff;
16
use PHP_CodeSniffer\Files\File;
17
use PHP_CodeSniffer\Config;
18
use PHP_CodeSniffer\Exceptions\RuntimeException;
19
use PHP_CodeSniffer\Util\Common;
20

21
class CodeAnalyzerSniff implements Sniff
22
{
23

24

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

34
    }//end register()
35

36

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

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

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

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

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

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

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

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

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

97
    }//end process()
98

99

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