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 |
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.