| Conditions | 14 |
| Paths | 9 |
| Total Lines | 28 |
| Code Lines | 20 |
| 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 |
||
| 66 | public static function useFileCache( ResourceLoaderContext $context ) { |
||
| 67 | global $wgUseFileCache, $wgDefaultSkin, $wgLanguageCode; |
||
| 68 | if ( !$wgUseFileCache ) { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | // Get all query values |
||
| 72 | $queryVals = $context->getRequest()->getValues(); |
||
| 73 | foreach ( $queryVals as $query => $val ) { |
||
| 74 | if ( in_array( $query, [ 'modules', 'image', 'variant', 'version', '*' ] ) ) { |
||
| 75 | // Use file cache regardless of the value of this parameter |
||
| 76 | continue; // note: &* added as IE fix |
||
| 77 | } elseif ( $query === 'skin' && $val === $wgDefaultSkin ) { |
||
| 78 | continue; |
||
| 79 | } elseif ( $query === 'lang' && $val === $wgLanguageCode ) { |
||
| 80 | continue; |
||
| 81 | } elseif ( $query === 'only' && in_array( $val, [ 'styles', 'scripts' ] ) ) { |
||
| 82 | continue; |
||
| 83 | } elseif ( $query === 'debug' && $val === 'false' ) { |
||
| 84 | continue; |
||
| 85 | } elseif ( $query === 'format' && $val === 'rasterized' ) { |
||
| 86 | continue; |
||
| 87 | } |
||
| 88 | |||
| 89 | return false; |
||
| 90 | } |
||
| 91 | |||
| 92 | return true; // cacheable |
||
| 93 | } |
||
| 94 | |||
| 118 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: