1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCompatibility_AbstractComplexVersionSniff. |
4
|
|
|
* |
5
|
|
|
* @category PHP |
6
|
|
|
* @package PHPCompatibility |
7
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* PHPCompatibility_AbstractComplexVersionSniff. |
12
|
|
|
* |
13
|
|
|
* @category PHP |
14
|
|
|
* @package PHPCompatibility |
15
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
abstract class PHPCompatibility_AbstractComplexVersionSniff |
|
|
|
|
18
|
|
|
extends PHPCompatibility_Sniff |
|
|
|
|
19
|
|
|
implements PHPCompatibility_ComplexVersionInterface |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Handle the retrieval of relevant information and - if necessary - throwing of an |
25
|
|
|
* error/warning for an item. |
26
|
|
|
* |
27
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
28
|
|
|
* @param int $stackPtr The position of the relevant token in |
29
|
|
|
* the stack. |
30
|
|
|
* @param array $itemInfo Base information about the item. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function handleFeature(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $itemInfo) |
35
|
|
|
{ |
36
|
|
|
$itemArray = $this->getItemArray($itemInfo); |
37
|
|
|
$errorInfo = $this->getErrorInfo($itemArray, $itemInfo); |
38
|
|
|
|
39
|
|
|
if ($this->shouldThrowError($errorInfo) === true) { |
40
|
|
|
$this->addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Determine whether an error/warning should be thrown for an item based on collected information. |
47
|
|
|
* |
48
|
|
|
* @param array $errorInfo Detail information about an item. |
49
|
|
|
* |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
abstract protected function shouldThrowError(array $errorInfo); |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get an array of the non-PHP-version array keys used in a sub-array. |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
protected function getNonVersionArrayKeys() |
61
|
|
|
{ |
62
|
|
|
return array(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Retrieve a subset of an item array containing only the array keys which |
68
|
|
|
* contain PHP version information. |
69
|
|
|
* |
70
|
|
|
* @param array $itemArray Version and other information about an item. |
71
|
|
|
* |
72
|
|
|
* @return array Array with only the version information. |
73
|
|
|
*/ |
74
|
|
|
protected function getVersionArray(array $itemArray) |
75
|
|
|
{ |
76
|
|
|
return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys())); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the item name to be used for the creation of the error code and in the error message. |
82
|
|
|
* |
83
|
|
|
* @param array $itemInfo Base information about the item. |
84
|
|
|
* @param array $errorInfo Detail information about an item. |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
protected function getItemName(array $itemInfo, array $errorInfo) |
89
|
|
|
{ |
90
|
|
|
return $itemInfo['name']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the error message template for a specific sniff. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
abstract protected function getErrorMsgTemplate(); |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
104
|
|
|
* |
105
|
|
|
* @param string $error The error message which was created. |
106
|
|
|
* @param array $itemInfo Base information about the item this error message applied to. |
107
|
|
|
* @param array $errorInfo Detail information about an item this error message applied to. |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
return $error; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
119
|
|
|
* |
120
|
|
|
* @param array $data The error data array which was created. |
121
|
|
|
* @param array $itemInfo Base information about the item this error message applied to. |
122
|
|
|
* @param array $errorInfo Detail information about an item this error message applied to. |
123
|
|
|
* |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
127
|
|
|
{ |
128
|
|
|
return $data; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
}//end class |
133
|
|
|
|
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.