Completed
Pull Request — master (#176)
by Juliette
02:44
created

process()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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