1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff. |
4
|
|
|
* |
5
|
|
|
* PHP version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PHPCompatibility |
9
|
|
|
* @author Wim Godden <[email protected]> |
10
|
|
|
* @copyright 2012 Cu.be Solutions bvba |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff. |
15
|
|
|
* |
16
|
|
|
* Discourages the use of deprecated and removed hash algorithms. |
17
|
|
|
* |
18
|
|
|
* PHP version 5.4 |
19
|
|
|
* |
20
|
|
|
* @category PHP |
21
|
|
|
* @package PHPCompatibility |
22
|
|
|
* @author Wim Godden <[email protected]> |
23
|
|
|
* @copyright 2012 Cu.be Solutions bvba |
24
|
|
|
*/ |
25
|
|
|
class PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff extends PHPCompatibility_AbstractRemovedFeatureSniff |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* A list of removed hash algorithms, which were present in older versions. |
30
|
|
|
* |
31
|
|
|
* The array lists : version number with false (deprecated) and true (removed). |
32
|
|
|
* If's sufficient to list the first version where the hash algorithm was deprecated/removed. |
33
|
|
|
* |
34
|
|
|
* @var array(string => array(string => bool)) |
35
|
|
|
*/ |
36
|
|
|
protected $removedAlgorithms = array( |
37
|
|
|
'salsa10' => array( |
38
|
|
|
'5.4' => true, |
39
|
|
|
), |
40
|
|
|
'salsa20' => array( |
41
|
|
|
'5.4' => true, |
42
|
|
|
), |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns an array of tokens this test wants to listen for. |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function register() |
51
|
|
|
{ |
52
|
|
|
return array(T_STRING); |
53
|
|
|
|
54
|
|
|
}//end register() |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Processes this test, when one of its tokens is encountered. |
59
|
|
|
* |
60
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
61
|
|
|
* @param int $stackPtr The position of the current token in the |
62
|
|
|
* stack passed in $tokens. |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
67
|
|
|
{ |
68
|
|
|
$algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr); |
69
|
|
|
if (empty($algo) || is_string($algo) === false) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Bow out if not one of the algorithms we're targetting. |
74
|
|
|
if (isset($this->removedAlgorithms[$algo]) === false) { |
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$itemInfo = array( |
79
|
|
|
'name' => $algo, |
80
|
|
|
); |
81
|
|
|
$this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
82
|
|
|
|
83
|
|
|
}//end process() |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the relevant sub-array for a specific item from a multi-dimensional array. |
88
|
|
|
* |
89
|
|
|
* @param array $itemInfo Base information about the item. |
90
|
|
|
* |
91
|
|
|
* @return array Version and other information about the item. |
92
|
|
|
*/ |
93
|
|
|
public function getItemArray(array $itemInfo) |
94
|
|
|
{ |
95
|
|
|
return $this->removedAlgorithms[$itemInfo['name']]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the error message template for this sniff. |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
protected function getErrorMsgTemplate() |
105
|
|
|
{ |
106
|
|
|
return 'The %s hash algorithm is '; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
}//end class |
111
|
|
|
|
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.