Failed Conditions
Branch test-scrutinizer-coverage (7e25b2)
by Wim
13:51 queued 10:07
created

process()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4.0047

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 14
cts 15
cp 0.9333
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 2
crap 4.0047
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_NewMultiCatch.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @category PHP
8
 * @package  PHPCompatibility
9
 * @author   Juliette Reinders Folmer <[email protected]>
10
 */
11
12
/**
13
 * PHPCompatibility_Sniffs_PHP_NewMultiCatch.
14
 *
15
 * Catching multiple exception types in one statement is available since PHP 7.1.
16
 *
17
 * PHP version 7.1
18
 *
19
 * @category PHP
20
 * @package  PHPCompatibility
21
 * @author   Juliette Reinders Folmer <[email protected]>
22
 */
23
class PHPCompatibility_Sniffs_PHP_NewMultiCatchSniff extends PHPCompatibility_Sniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    /**
26
     * Returns an array of tokens this test wants to listen for.
27
     *
28
     * @return array
29
     */
30 7
    public function register()
31
    {
32 7
        return array(T_CATCH);
33
34
    }//end register()
35
36
    /**
37
     * Processes this test, when one of its tokens is encountered.
38
     *
39
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
40
     * @param int                  $stackPtr  The position of the current token
41
     *                                        in the stack passed in $tokens.
42
     *
43
     * @return void
44
     */
45 2
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
    {
47 2
        if ($this->supportsBelow('7.0') === false) {
48 1
            return;
49
        }
50
51 1
        $tokens = $phpcsFile->getTokens();
52 1
        $token  = $tokens[$stackPtr];
53
54
        // Bow out during live coding.
55 1
        if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
56 1
            return;
57
        }
58
59 1
        $hasBitwiseOr = $phpcsFile->findNext(T_BITWISE_OR, $token['parenthesis_opener'], $token['parenthesis_closer']);
60
61 1
        if ($hasBitwiseOr === false) {
62 1
            return;
63
        }
64
65 1
        $phpcsFile->addError(
66 1
            'Catching multiple exceptions within one statement is not supported in PHP 7.0 or earlier.',
67
            $hasBitwiseOr,
68 1
            'Found'
69
        );
70
71 1
    }//end process()
72
73
}//end class
74