Conditions | 9 |
Paths | 30 |
Total Lines | 56 |
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 |
||
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 | $regex .= $this->stripQuotes($tokens[$i]['content']); |
||
133 | } |
||
134 | } |
||
135 | // Deal with multi-line regexes which were broken up in several string tokens. |
||
136 | $regex = $this->stripQuotes($regex); |
||
137 | |||
138 | if ($regex === '') { |
||
139 | // No string token found in the first parameter, so skip it (e.g. if variable passed in). |
||
140 | return; |
||
141 | } |
||
142 | |||
143 | $regexFirstChar = substr($regex, 0, 1); |
||
144 | |||
145 | // Make sure that the character identified as the delimiter is valid. |
||
146 | // Otherwise, it is a false positive caused by the string concatenation. |
||
147 | if (preg_match('`[a-z0-9\\\\ ]`i', $regexFirstChar) === 1) { |
||
148 | return; |
||
149 | } |
||
150 | |||
151 | if (isset($this->doublesSeparators[$regexFirstChar])) { |
||
152 | $regexEndPos = strrpos($regex, $this->doublesSeparators[$regexFirstChar]); |
||
153 | } |
||
154 | else { |
||
155 | $regexEndPos = strrpos($regex, $regexFirstChar); |
||
156 | } |
||
157 | |||
158 | if($regexEndPos) { |
||
159 | $modifiers = substr($regex, $regexEndPos + 1); |
||
160 | |||
161 | if (strpos($modifiers, 'e') !== false) { |
||
162 | $error = '%s() - /e modifier is deprecated since PHP 5.5'; |
||
163 | $isError = false; |
||
164 | $errorCode = 'Deprecated'; |
||
165 | $data = array($functionName); |
||
166 | |||
167 | if ($this->supportsAbove('7.0')) { |
||
168 | $error .= ' and removed since PHP 7.0'; |
||
169 | $isError = true; |
||
170 | $errorCode = 'Removed'; |
||
171 | } |
||
172 | |||
173 | $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data); |
||
174 | } |
||
175 | } |
||
176 | }//end processRegexPattern() |
||
177 | |||
179 |
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.