1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCompatibility_Sniffs_PHP_NewConstVisibility. |
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_NewConstVisibility. |
14
|
|
|
* |
15
|
|
|
* Visibility for class constants 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_NewConstVisibilitySniff extends PHPCompatibility_Sniff |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Returns an array of tokens this test wants to listen for. |
27
|
|
|
* |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public function register() |
31
|
|
|
{ |
32
|
|
|
return array(T_CONST); |
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
|
|
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
46
|
|
|
{ |
47
|
|
|
$tokens = $phpcsFile->getTokens(); |
48
|
|
|
$prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
49
|
|
|
|
50
|
|
|
if ($prevToken === false) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Is the previous token a visibility indicator ? |
55
|
|
|
if (in_array($tokens[$prevToken]['code'], PHP_CodeSniffer_Tokens::$scopeModifiers, true) === false) { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($this->tokenHasScope($phpcsFile, $stackPtr, array(T_CLASS, T_INTERFACE)) === true && $this->supportsBelow('7.0') === true) { |
60
|
|
|
$error = 'Visibility indicators for class constants are not supported in PHP 7.0 or earlier. Found "%s const"'; |
61
|
|
|
$data = array($tokens[$prevToken]['content']); |
62
|
|
|
$phpcsFile->addError($error, $stackPtr, 'Found', $data); |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
}//end process() |
67
|
|
|
|
68
|
|
|
}//end class |
69
|
|
|
|
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.