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