1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCompatibility_AbstractNewFeatureSniff. |
4
|
|
|
* |
5
|
|
|
* @category PHP |
6
|
|
|
* @package PHPCompatibility |
7
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* PPHPCompatibility_AbstractNewFeatureSniff. |
12
|
|
|
* |
13
|
|
|
* @category PHP |
14
|
|
|
* @package PHPCompatibility |
15
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
abstract class PHPCompatibility_AbstractNewFeatureSniff |
|
|
|
|
18
|
|
|
extends PHPCompatibility_AbstractComplexVersionSniff |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Determine whether an error/warning should be thrown for an item based on collected information. |
24
|
|
|
* |
25
|
|
|
* @param array $errorInfo Detail information about an item. |
26
|
|
|
* |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
protected function shouldThrowError(array $errorInfo) |
30
|
|
|
{ |
31
|
|
|
return ($errorInfo['not_in_version'] !== ''); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Retrieve the relevant detail (version) information for use in an error message. |
37
|
|
|
* |
38
|
|
|
* @param array $itemArray Version and other information about the item. |
39
|
|
|
* @param array $itemInfo Base information about the item. |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getErrorInfo(array $itemArray, array $itemInfo) |
44
|
|
|
{ |
45
|
|
|
$errorInfo = array( |
46
|
|
|
'not_in_version' => '', |
47
|
|
|
'error' => true, |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$versionArray = $this->getVersionArray($itemArray); |
51
|
|
|
|
52
|
|
|
if (empty($versionArray) === false) { |
53
|
|
View Code Duplication |
foreach ($versionArray as $version => $present) { |
|
|
|
|
54
|
|
|
if ($errorInfo['not_in_version'] === '' && $present === false |
55
|
|
|
&& $this->supportsBelow($version) === true |
56
|
|
|
) { |
57
|
|
|
$errorInfo['not_in_version'] = $version; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $errorInfo; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the error message template for this sniff. |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
protected function getErrorMsgTemplate() |
72
|
|
|
{ |
73
|
|
|
return '%s is not present in PHP version %s or earlier'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Generates the error or warning for this item. |
79
|
|
|
* |
80
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
81
|
|
|
* @param int $stackPtr The position of the relevant token in |
82
|
|
|
* the stack. |
83
|
|
|
* @param array $itemInfo Base information about the item. |
84
|
|
|
* @param array $errorInfo Array with detail (version) information |
85
|
|
|
* relevant to the item. |
86
|
|
|
* |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public function addError(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
90
|
|
|
{ |
91
|
|
|
$itemName = $this->getItemName($itemInfo, $errorInfo); |
92
|
|
|
$error = $this->getErrorMsgTemplate(); |
93
|
|
|
|
94
|
|
|
$errorCode = $this->stringToErrorCode($itemName).'Found'; |
95
|
|
|
$data = array( |
96
|
|
|
$itemName, |
97
|
|
|
$errorInfo['not_in_version'], |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
101
|
|
|
$data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
102
|
|
|
|
103
|
|
|
$this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
}//end class |
108
|
|
|
|
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.