| Conditions | 10 |
| Paths | 40 |
| Total Lines | 61 |
| Code Lines | 31 |
| 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 |
||
| 121 | protected function processRegexPattern($pattern, $phpcsFile, $stackPtr, $functionName) |
||
| 122 | { |
||
| 123 | $tokens = $phpcsFile->getTokens(); |
||
| 124 | |||
| 125 | /* |
||
| 126 | * The pattern might be build up of a combination of strings, variables |
||
| 127 | * and function calls. We are only concerned with the strings. |
||
| 128 | */ |
||
| 129 | $regex = ''; |
||
| 130 | for ($i = $pattern['start']; $i <= $pattern['end']; $i++ ) { |
||
| 131 | if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$stringTokens, true) === true) { |
||
| 132 | $content = $this->stripQuotes($tokens[$i]['content']); |
||
| 133 | if ($tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING) { |
||
| 134 | $content = $this->stripVariables($content); |
||
| 135 | } |
||
| 136 | |||
| 137 | $regex .= trim($content); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | // Deal with multi-line regexes which were broken up in several string tokens. |
||
| 141 | $regex = $this->stripQuotes($regex); |
||
| 142 | |||
| 143 | if ($regex === '') { |
||
| 144 | // No string token found in the first parameter, so skip it (e.g. if variable passed in). |
||
| 145 | return; |
||
| 146 | } |
||
| 147 | |||
| 148 | $regexFirstChar = substr($regex, 0, 1); |
||
| 149 | |||
| 150 | // Make sure that the character identified as the delimiter is valid. |
||
| 151 | // Otherwise, it is a false positive caused by the string concatenation. |
||
| 152 | if (preg_match('`[a-z0-9\\\\ ]`i', $regexFirstChar) === 1) { |
||
| 153 | return; |
||
| 154 | } |
||
| 155 | |||
| 156 | if (isset($this->doublesSeparators[$regexFirstChar])) { |
||
| 157 | $regexEndPos = strrpos($regex, $this->doublesSeparators[$regexFirstChar]); |
||
| 158 | } |
||
| 159 | else { |
||
| 160 | $regexEndPos = strrpos($regex, $regexFirstChar); |
||
| 161 | } |
||
| 162 | |||
| 163 | if($regexEndPos) { |
||
| 164 | $modifiers = substr($regex, $regexEndPos + 1); |
||
| 165 | |||
| 166 | if (strpos($modifiers, 'e') !== false) { |
||
| 167 | $error = '%s() - /e modifier is deprecated since PHP 5.5'; |
||
| 168 | $isError = false; |
||
| 169 | $errorCode = 'Deprecated'; |
||
| 170 | $data = array($functionName); |
||
| 171 | |||
| 172 | if ($this->supportsAbove('7.0')) { |
||
| 173 | $error .= ' and removed since PHP 7.0'; |
||
| 174 | $isError = true; |
||
| 175 | $errorCode = 'Removed'; |
||
| 176 | } |
||
| 177 | |||
| 178 | $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | }//end processRegexPattern() |
||
| 182 | |||
| 184 |
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.