These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff. |
||
| 4 | * |
||
| 5 | * @category PHP |
||
| 6 | * @package PHPCompatibility |
||
| 7 | * @author Juliette Reinders Folmer <[email protected]> |
||
| 8 | */ |
||
| 9 | |||
| 10 | /** |
||
| 11 | * PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff. |
||
| 12 | * |
||
| 13 | * @category PHP |
||
| 14 | * @package PHPCompatibility |
||
| 15 | * @author Juliette Reinders Folmer <[email protected]> |
||
| 16 | */ |
||
| 17 | class PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff |
||
| 18 | extends PHPCompatibility_AbstractNewFeatureSniff |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 19 | { |
||
| 20 | /** |
||
| 21 | * A list of new hash algorithms, not present in older versions. |
||
| 22 | * |
||
| 23 | * The array lists : version number with false (not present) or true (present). |
||
| 24 | * If's sufficient to list the first version where the hash algorithm appears. |
||
| 25 | * |
||
| 26 | * @var array(string => array(string => bool)) |
||
| 27 | */ |
||
| 28 | protected $newAlgorithms = array( |
||
| 29 | 'md2' => array( |
||
| 30 | '5.2' => false, |
||
| 31 | '5.3' => true, |
||
| 32 | ), |
||
| 33 | 'ripemd256' => array( |
||
| 34 | '5.2' => false, |
||
| 35 | '5.3' => true, |
||
| 36 | ), |
||
| 37 | 'ripemd320' => array( |
||
| 38 | '5.2' => false, |
||
| 39 | '5.3' => true, |
||
| 40 | ), |
||
| 41 | 'salsa10' => array( |
||
| 42 | '5.2' => false, |
||
| 43 | '5.3' => true, |
||
| 44 | ), |
||
| 45 | 'salsa20' => array( |
||
| 46 | '5.2' => false, |
||
| 47 | '5.3' => true, |
||
| 48 | ), |
||
| 49 | 'snefru256' => array( |
||
| 50 | '5.2' => false, |
||
| 51 | '5.3' => true, |
||
| 52 | ), |
||
| 53 | 'sha224' => array( |
||
| 54 | '5.2' => false, |
||
| 55 | '5.3' => true, |
||
| 56 | ), |
||
| 57 | 'joaat' => array( |
||
| 58 | '5.3' => false, |
||
| 59 | '5.4' => true, |
||
| 60 | ), |
||
| 61 | 'fnv132' => array( |
||
| 62 | '5.3' => false, |
||
| 63 | '5.4' => true, |
||
| 64 | ), |
||
| 65 | 'fnv164' => array( |
||
| 66 | '5.3' => false, |
||
| 67 | '5.4' => true, |
||
| 68 | ), |
||
| 69 | 'gost-crypto' => array( |
||
| 70 | '5.5' => false, |
||
| 71 | '5.6' => true, |
||
| 72 | ), |
||
| 73 | ); |
||
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * Returns an array of tokens this test wants to listen for. |
||
| 78 | * |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | public function register() |
||
| 82 | { |
||
| 83 | return array(T_STRING); |
||
| 84 | |||
| 85 | }//end register() |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Processes this test, when one of its tokens is encountered. |
||
| 90 | * |
||
| 91 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 92 | * @param int $stackPtr The position of the current token in the |
||
| 93 | * stack passed in $tokens. |
||
| 94 | * |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 98 | { |
||
| 99 | $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr); |
||
| 100 | if (empty($algo) || is_string($algo) === false) { |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | // Bow out if not one of the algorithms we're targetting. |
||
| 105 | if (isset($this->newAlgorithms[$algo]) === false) { |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | // Check if the algorithm used is new. |
||
| 110 | $itemInfo = array( |
||
| 111 | 'name' => $algo, |
||
| 112 | ); |
||
| 113 | $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
||
| 114 | |||
| 115 | }//end process() |
||
| 116 | |||
| 117 | |||
| 118 | /** |
||
| 119 | * Get the relevant sub-array for a specific item from a multi-dimensional array. |
||
| 120 | * |
||
| 121 | * @param array $itemInfo Base information about the item. |
||
| 122 | * |
||
| 123 | * @return array Version and other information about the item. |
||
| 124 | */ |
||
| 125 | public function getItemArray(array $itemInfo) |
||
| 126 | { |
||
| 127 | return $this->newAlgorithms[$itemInfo['name']]; |
||
| 128 | } |
||
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * Get the error message template for this sniff. |
||
| 133 | * |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | protected function getErrorMsgTemplate() |
||
| 137 | { |
||
| 138 | return 'The %s hash algorithm is not present in PHP version %s or earlier'; |
||
| 139 | } |
||
| 140 | |||
| 141 | |||
| 142 | }//end class |
||
| 143 |