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_RemovedFunctionParametersSniff. |
||
| 4 | * |
||
| 5 | * @category PHP |
||
| 6 | * @package PHPCompatibility |
||
| 7 | * @author Wim Godden <[email protected]> |
||
| 8 | */ |
||
| 9 | |||
| 10 | /** |
||
| 11 | * PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff. |
||
| 12 | * |
||
| 13 | * @category PHP |
||
| 14 | * @package PHPCompatibility |
||
| 15 | * @author Wim Godden <[email protected]> |
||
| 16 | */ |
||
| 17 | class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff |
||
| 18 | extends PHPCompatibility_AbstractRemovedFeatureSniff |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 19 | { |
||
| 20 | /** |
||
| 21 | * A list of removed function parameters, which were present in older versions. |
||
| 22 | * |
||
| 23 | * The array lists : version number with false (deprecated) and true (removed). |
||
| 24 | * The index is the location of the parameter in the parameter list, starting at 0 ! |
||
| 25 | * If's sufficient to list the first version where the function parameter was deprecated/removed. |
||
| 26 | * |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $removedFunctionParameters = array( |
||
| 30 | 'gmmktime' => array( |
||
| 31 | 6 => array( |
||
| 32 | 'name' => 'is_dst', |
||
| 33 | '5.1' => false, // deprecated |
||
| 34 | '7.0' => true, |
||
| 35 | ), |
||
| 36 | ), |
||
| 37 | 'ldap_first_attribute' => array( |
||
| 38 | 2 => array( |
||
| 39 | 'name' => 'ber_identifier', |
||
| 40 | '5.2.4' => true, |
||
| 41 | ), |
||
| 42 | ), |
||
| 43 | 'ldap_next_attribute' => array( |
||
| 44 | 2 => array( |
||
| 45 | 'name' => 'ber_identifier', |
||
| 46 | '5.2.4' => true, |
||
| 47 | ), |
||
| 48 | ), |
||
| 49 | 'mktime' => array( |
||
| 50 | 6 => array( |
||
| 51 | 'name' => 'is_dst', |
||
| 52 | '5.1' => false, // deprecated |
||
| 53 | '7.0' => true, |
||
| 54 | ), |
||
| 55 | ), |
||
| 56 | ); |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * Returns an array of tokens this test wants to listen for. |
||
| 61 | * |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | public function register() |
||
| 65 | { |
||
| 66 | // Handle case-insensitivity of function names. |
||
| 67 | $this->removedFunctionParameters = $this->arrayKeysToLowercase($this->removedFunctionParameters); |
||
| 68 | |||
| 69 | return array(T_STRING); |
||
| 70 | }//end register() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Processes this test, when one of its tokens is encountered. |
||
| 74 | * |
||
| 75 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 76 | * @param int $stackPtr The position of the current token in |
||
| 77 | * the stack passed in $tokens. |
||
| 78 | * |
||
| 79 | * @return void |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
| 82 | { |
||
| 83 | $tokens = $phpcsFile->getTokens(); |
||
| 84 | |||
| 85 | $ignore = array( |
||
| 86 | T_DOUBLE_COLON, |
||
| 87 | T_OBJECT_OPERATOR, |
||
| 88 | T_FUNCTION, |
||
| 89 | T_CONST, |
||
| 90 | ); |
||
| 91 | |||
| 92 | $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
||
| 93 | if (in_array($tokens[$prevToken]['code'], $ignore) === true) { |
||
| 94 | // Not a call to a PHP function. |
||
| 95 | return; |
||
| 96 | } |
||
| 97 | |||
| 98 | $function = $tokens[$stackPtr]['content']; |
||
| 99 | $functionLc = strtolower($function); |
||
| 100 | |||
| 101 | if (isset($this->removedFunctionParameters[$functionLc]) === false) { |
||
| 102 | return; |
||
| 103 | } |
||
| 104 | |||
| 105 | $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr); |
||
| 106 | if ($parameterCount === 0) { |
||
| 107 | return; |
||
| 108 | } |
||
| 109 | |||
| 110 | // If the parameter count returned > 0, we know there will be valid open parenthesis. |
||
| 111 | $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
||
| 112 | $parameterOffsetFound = $parameterCount - 1; |
||
| 113 | |||
| 114 | foreach($this->removedFunctionParameters[$functionLc] as $offset => $parameterDetails) { |
||
| 115 | if ($offset <= $parameterOffsetFound) { |
||
| 116 | $itemInfo = array( |
||
| 117 | 'name' => $function, |
||
| 118 | 'nameLc' => $functionLc, |
||
| 119 | 'offset' => $offset, |
||
| 120 | ); |
||
| 121 | $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo); |
||
|
0 ignored issues
–
show
It seems like
$openParenthesis defined by $phpcsFile->findNext(\PH...null, true, null, true) on line 111 can also be of type false; however, PHPCompatibility_Abstrac...nSniff::handleFeature() does only seem to accept integer, did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new Loading history...
|
|||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | }//end process() |
||
| 126 | |||
| 127 | |||
| 128 | /** |
||
| 129 | * Get the relevant sub-array for a specific item from a multi-dimensional array. |
||
| 130 | * |
||
| 131 | * @param array $itemInfo Base information about the item. |
||
| 132 | * |
||
| 133 | * @return array Version and other information about the item. |
||
| 134 | */ |
||
| 135 | public function getItemArray(array $itemInfo) |
||
| 136 | { |
||
| 137 | return $this->removedFunctionParameters[$itemInfo['nameLc']][$itemInfo['offset']]; |
||
| 138 | } |
||
| 139 | |||
| 140 | |||
| 141 | /** |
||
| 142 | * Get an array of the non-PHP-version array keys used in a sub-array. |
||
| 143 | * |
||
| 144 | * @return array |
||
| 145 | */ |
||
| 146 | protected function getNonVersionArrayKeys() |
||
| 147 | { |
||
| 148 | return array('name'); |
||
| 149 | } |
||
| 150 | |||
| 151 | |||
| 152 | /** |
||
| 153 | * Retrieve the relevant detail (version) information for use in an error message. |
||
| 154 | * |
||
| 155 | * @param array $itemArray Version and other information about the item. |
||
| 156 | * @param array $itemInfo Base information about the item. |
||
| 157 | * |
||
| 158 | * @return array |
||
| 159 | */ |
||
| 160 | public function getErrorInfo(array $itemArray, array $itemInfo) |
||
| 161 | { |
||
| 162 | $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
||
| 163 | $errorInfo['paramName'] = $itemArray['name']; |
||
| 164 | |||
| 165 | return $errorInfo; |
||
| 166 | } |
||
| 167 | |||
| 168 | |||
| 169 | /** |
||
| 170 | * Get the item name to be used for the creation of the error code. |
||
| 171 | * |
||
| 172 | * @param array $itemInfo Base information about the item. |
||
| 173 | * @param array $errorInfo Detail information about an item. |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | protected function getItemName(array $itemInfo, array $errorInfo) |
||
| 178 | { |
||
| 179 | return $itemInfo['name'].'_'.$errorInfo['paramName']; |
||
| 180 | } |
||
| 181 | |||
| 182 | |||
| 183 | /** |
||
| 184 | * Get the error message template for this sniff. |
||
| 185 | * |
||
| 186 | * @return string |
||
| 187 | */ |
||
| 188 | protected function getErrorMsgTemplate() |
||
| 189 | { |
||
| 190 | return 'The "%s" parameter for function %s() is '; |
||
| 191 | } |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
||
| 196 | * |
||
| 197 | * @param array $data The error data array which was created. |
||
| 198 | * @param array $itemInfo Base information about the item this error message applied to. |
||
| 199 | * @param array $errorInfo Detail information about an item this error message applied to. |
||
| 200 | * |
||
| 201 | * @return array |
||
| 202 | */ |
||
| 203 | protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
||
| 204 | { |
||
| 205 | array_shift($data); |
||
| 206 | array_unshift($data, $errorInfo['paramName'], $itemInfo['name']); |
||
| 207 | return $data; |
||
| 208 | } |
||
| 209 | |||
| 210 | |||
| 211 | }//end class |
||
| 212 |