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

PHPCompatibility_Sniffs_PHP_LateStaticBindingSniff   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 57
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
B process() 0 31 6
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_LateStaticBindingSniff.
4
 *
5
 * PHP version 5.3
6
 *
7
 * @category PHP
8
 * @package  PHPCompatibility
9
 * @author   Juliette Reinders Folmer <[email protected]>
10
 */
11
12
/**
13
 * PHPCompatibility_Sniffs_PHP_LateStaticBindingSniff.
14
 *
15
 * PHP version 5.3
16
 *
17
 * @category PHP
18
 * @package  PHPCompatibility
19
 * @author   Juliette Reinders Folmer <[email protected]>
20
 */
21
class PHPCompatibility_Sniffs_PHP_LateStaticBindingSniff 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...
22
{
23
    /**
24
     * Returns an array of tokens this test wants to listen for.
25
     *
26
     * @return array
27
     */
28 7
    public function register()
29
    {
30 7
        return array(T_STATIC);
31
32
    }//end register()
33
34
35
    /**
36
     * Processes this test, when one of its tokens is encountered.
37
     *
38
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
39
     * @param int                  $stackPtr  The position of the current token in the
40
     *                                        stack passed in $tokens.
41
     *
42
     * @return void
43
     */
44 2
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
45
    {
46 2
        $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
47 2
        if ($nextNonEmpty === false) {
48
            return;
49
        }
50
51 2
        $tokens = $phpcsFile->getTokens();
52 2
        if ($tokens[$nextNonEmpty]['code'] !== T_DOUBLE_COLON) {
53 2
            return;
54
        }
55
56 2
        $inClass = $this->inClassScope($phpcsFile, $stackPtr, false);
57
58 2
        if ($inClass === true && $this->supportsBelow('5.2') === true) {
59 1
            $phpcsFile->addError(
60 1
                'Late static binding is not supported in PHP 5.2 or earlier.',
61
                $stackPtr,
62 1
                'Found'
63
            );
64
        }
65
66 2
        if ($inClass === false) {
67 2
            $phpcsFile->addError(
68 2
                'Late static binding is not supported outside of class scope.',
69
                $stackPtr,
70 2
                'OutsideClassScope'
71
            );
72
        }
73
74 2
    }//end process()
75
76
77
}//end class
78