| Conditions | 11 |
| Paths | 22 |
| Total Lines | 59 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | * @param string $functionName The token content (function name) which was matched. |
||
| 63 | * @param array $parameters Array with information about the parameters. |
||
| 64 | * |
||
| 65 | * @return int|void Integer stack pointer to skip forward or void to continue |
||
| 66 | * normal file processing. |
||
| 67 | */ |
||
| 68 | public function processParameters(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionName, $parameters) |
||
| 69 | { |
||
| 70 | $tokens = $phpcsFile->getTokens(); |
||
| 71 | $functionNameLc = strtolower($functionName); |
||
| 72 | |||
| 73 | // Check whether the options parameter in the function call is passed. |
||
| 74 | if (isset($parameters[$this->targetFunctions[$functionNameLc]]) === false) { |
||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | $optionsParam = $parameters[$this->targetFunctions[$functionNameLc]]; |
||
| 79 | |||
| 80 | $stringToken = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$stringTokens, $optionsParam['start'], $optionsParam['end'] + 1); |
||
| 81 | if ($stringToken === false) { |
||
| 82 | // No string token found in the options parameter, so skip it (e.g. variable passed in). |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 86 | $options = ''; |
||
| 87 | |||
| 88 | /* |
||
| 89 | * Get the content of any string tokens in the options parameter and remove the quotes and variables. |
||
| 90 | */ |
||
| 91 | for ($i = $stringToken; $i <= $optionsParam['end']; $i++) { |
||
| 92 | if (in_array($tokens[$i]['code'], \PHP_CodeSniffer_Tokens::$stringTokens, true) === false) { |
||
| 93 | continue; |
||
| 94 | } |
||
| 95 | |||
| 96 | $content = $this->stripQuotes($tokens[$i]['content']); |
||
| 97 | if ($tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING) { |
||
| 98 | $content = $this->stripVariables($content); |
||
| 99 | } |
||
| 100 | $content = trim($content); |
||
| 101 | |||
| 102 | if (empty($content) === false) { |
||
| 103 | $options .= $content; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | if (strpos($options, 'e') !== false) { |
||
| 108 | $error = 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.'; |
||
| 109 | |||
| 110 | // The alternative mb_ereg_replace_callback() function is only available since 5.4.1. |
||
| 111 | if ($this->supportsBelow('5.4.1') === false) { |
||
| 112 | $error .= ' Use mb_ereg_replace_callback() instead (PHP 5.4.1+).'; |
||
| 113 | } |
||
| 114 | |||
| 115 | $phpcsFile->addWarning($error, $stackPtr, 'Deprecated'); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | }//end class |
||
| 119 |