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