| Conditions | 12 |
| Paths | 10 |
| Total Lines | 56 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 74 | $tokens = $phpcsFile->getTokens(); |
||
| 75 | $functionNameLc = strtolower($functionName); |
||
| 76 | $firstParam = $parameters[1]; |
||
| 77 | |||
| 78 | // Differentiate between an array of patterns passed and a single pattern. |
||
| 79 | $nextNonEmpty = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, $firstParam['start'], ($firstParam['end'] + 1), true); |
||
| 80 | if ($nextNonEmpty !== false && ($tokens[$nextNonEmpty]['code'] === T_ARRAY || $tokens[$nextNonEmpty]['code'] === T_OPEN_SHORT_ARRAY)) { |
||
| 81 | $arrayValues = $this->getFunctionCallParameters($phpcsFile, $nextNonEmpty); |
||
| 82 | if ($functionNameLc === 'preg_replace_callback_array') { |
||
| 83 | // For preg_replace_callback_array(), the patterns will be in the array keys. |
||
| 84 | foreach ($arrayValues as $value) { |
||
| 85 | $hasKey = $phpcsFile->findNext(T_DOUBLE_ARROW, $value['start'], ($value['end'] + 1)); |
||
| 86 | if ($hasKey === false) { |
||
| 87 | continue; |
||
| 88 | } |
||
| 89 | |||
| 90 | $value['end'] = ($hasKey - 1); |
||
| 91 | $value['raw'] = trim($phpcsFile->getTokensAsString($value['start'], ($hasKey - $value['start']))); |
||
| 92 | $this->processRegexPattern($value, $phpcsFile, $value['end'], $functionName); |
||
| 93 | } |
||
| 94 | |||
| 95 | } else { |
||
| 96 | // Otherwise, the patterns will be in the array values. |
||
| 97 | foreach ($arrayValues as $value) { |
||
| 98 | $hasKey = $phpcsFile->findNext(T_DOUBLE_ARROW, $value['start'], ($value['end'] + 1)); |
||
| 99 | if ($hasKey !== false) { |
||
| 100 | $value['start'] = ($hasKey + 1); |
||
| 101 | $value['raw'] = trim($phpcsFile->getTokensAsString($value['start'], (($value['end'] + 1) - $value['start']))); |
||
| 102 | } |
||
| 103 | |||
| 104 | $this->processRegexPattern($value, $phpcsFile, $value['end'], $functionName); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | } else { |
||
| 109 | $this->processRegexPattern($firstParam, $phpcsFile, $stackPtr, $functionName); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | |||
| 114 | /** |
||
| 115 | * Do a version check to determine if this sniff needs to run at all. |
||
| 116 | * |
||
| 117 | * @return bool |
||
| 118 | */ |
||
| 119 | protected function bowOutEarly() |
||
| 120 | { |
||
| 121 | return ($this->supportsAbove('5.5') === false); |
||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * Analyse a potential regex pattern for usage of the /e modifier. |
||
| 127 | * |
||
| 128 | * @param array $pattern Array containing the start and end token |
||
| 129 | * pointer of the potential regex pattern and |
||
| 130 | * the raw string value of the pattern. |
||
| 219 |