1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff. |
4
|
|
|
* |
5
|
|
|
* PHP version 7.0 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PHPCompatibility |
9
|
|
|
* @author Wim Godden <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff. |
14
|
|
|
* |
15
|
|
|
* PHP version 7.0 |
16
|
|
|
* |
17
|
|
|
* @category PHP |
18
|
|
|
* @package PHPCompatibility |
19
|
|
|
* @author Wim Godden <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff extends PHPCompatibility_Sniff |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Returns an array of tokens this test wants to listen for. |
25
|
|
|
* |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
14 |
|
public function register() |
29
|
|
|
{ |
30
|
14 |
|
if (defined('T_OPEN_USE_GROUP')) { |
31
|
14 |
|
return array(T_OPEN_USE_GROUP); |
32
|
|
|
} else { |
33
|
|
|
return array(T_USE); |
34
|
|
|
} |
35
|
|
|
}//end register() |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Processes this test, when one of its tokens is encountered. |
40
|
|
|
* |
41
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
42
|
|
|
* @param int $stackPtr The position of the current token in |
43
|
|
|
* the stack passed in $tokens. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
2 |
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
48
|
|
|
{ |
49
|
2 |
|
if ($this->supportsBelow('5.6') === false) { |
50
|
1 |
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
$tokens = $phpcsFile->getTokens(); |
54
|
1 |
|
$token = $tokens[$stackPtr]; |
55
|
|
|
|
56
|
|
|
// Deal with PHPCS pre-2.6.0. |
57
|
1 |
|
if ($token['code'] === T_USE) { |
58
|
|
|
$hasCurlyBrace = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); |
59
|
|
|
if ($hasCurlyBrace === false) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); |
64
|
|
|
if ($prevToken === false || $tokens[$prevToken]['code'] !== T_NS_SEPARATOR) { |
65
|
|
|
return; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// Still here ? In that case, it is a group use statement. |
70
|
1 |
|
$phpcsFile->addError( |
71
|
1 |
|
'Group use declarations are not allowed in PHP 5.6 or earlier', |
72
|
1 |
|
$stackPtr, |
73
|
|
|
'Found' |
74
|
1 |
|
); |
75
|
|
|
|
76
|
1 |
|
}//end process() |
77
|
|
|
}//end class |
78
|
|
|
|
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.