Conditions | 12 |
Paths | 24 |
Total Lines | 57 |
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 |
||
147 | private static function doObfuscate( $text, $parser ) { |
||
148 | |||
149 | // Find all [[ ... ]] |
||
150 | preg_match_all('/\[{2}(.*?)\]{2}/is', $text, $matches ); |
||
151 | $off = false; |
||
152 | |||
153 | foreach ( $matches[0] as $match ) { |
||
154 | |||
155 | // Ignore transformed links ([[:Foo|Foo]]) |
||
156 | if ( strpos( $match, '[[:' ) !== false ) { |
||
157 | continue; |
||
158 | } |
||
159 | |||
160 | // Remember whether the text contains OFF/ON marker (added by |
||
161 | // recursive parser, template, embedded result printer) and restore |
||
162 | // the marker after the text has been processed |
||
163 | if ( $off === false ) { |
||
164 | $off = $match === InTextAnnotationParser::OFF; |
||
165 | } |
||
166 | |||
167 | $openNum = substr_count( $match, '[[' ); |
||
168 | $closeNum = substr_count( $match, ']]' ); |
||
169 | $markerNum = substr_count( $match, '::' ); |
||
170 | |||
171 | if ( $markerNum == 0 ) { |
||
172 | // Simple link [[ ... ]], no annotation therefore match and |
||
173 | // obfuscate [[, |, ]] for a matching text elements |
||
174 | $text = str_replace( $match, self::encodeLinks( $match ), $text ); |
||
175 | } elseif ( $openNum > $closeNum && $markerNum == 1 ) { |
||
176 | // [[Text::Some [[abc]] |
||
177 | // Forget about about the first position |
||
178 | $replace = str_replace( $match, self::encodeLinks( $match ), $match ); |
||
179 | $replace = substr_replace( $replace, '[[', 0, 10 ); |
||
180 | $text = str_replace( $match, $replace, $text ); |
||
181 | } elseif ( $openNum === $closeNum && $markerNum == 1 ) { |
||
182 | // [[Foo::Bar]] annotation therefore run a pattern match and |
||
183 | // obfuscate the returning [[, |, ]] result |
||
184 | $replace = self::encodeLinks( preg_replace_callback( |
||
185 | $parser->getRegexpPattern( false ), |
||
186 | array( $parser, 'preprocess' ), |
||
187 | $match |
||
188 | ) ); |
||
189 | $text = str_replace( $match, $replace, $text ); |
||
190 | } elseif ( $openNum > $closeNum && $markerNum == 2 ) { |
||
191 | // [[Text::Some [[Foo::Some]] |
||
192 | // Remove the first [[ and added after results are returned |
||
193 | $text = str_replace( $match, '[[' . self::doObfuscate( substr( $match, 2 ), $parser ), $text ); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | // Restore OFF/ON |
||
198 | if ( $off === true ) { |
||
199 | $text = InTextAnnotationParser::OFF . $text . InTextAnnotationParser::ON; |
||
200 | } |
||
201 | |||
202 | return $text; |
||
203 | } |
||
204 | |||
206 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.