| Conditions | 12 |
| Paths | 7 |
| Total Lines | 45 |
| Code Lines | 33 |
| 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 |
||
| 34 | public function run() { |
||
| 35 | global $wgUploadThumbnailRenderMethod; |
||
| 36 | |||
| 37 | $transformParams = $this->params['transformParams']; |
||
| 38 | |||
| 39 | $file = wfLocalFile( $this->title ); |
||
| 40 | $file->load( File::READ_LATEST ); |
||
| 41 | |||
| 42 | if ( $file && $file->exists() ) { |
||
| 43 | if ( $wgUploadThumbnailRenderMethod === 'jobqueue' ) { |
||
| 44 | $thumb = $file->transform( $transformParams, File::RENDER_NOW ); |
||
| 45 | |||
| 46 | if ( $thumb && !$thumb->isError() ) { |
||
| 47 | return true; |
||
| 48 | } else { |
||
| 49 | $this->setLastError( __METHOD__ . ': thumbnail couln\'t be generated' ); |
||
| 50 | return false; |
||
| 51 | } |
||
| 52 | } elseif ( $wgUploadThumbnailRenderMethod === 'http' ) { |
||
| 53 | $thumbUrl = ''; |
||
| 54 | $status = $this->hitThumbUrl( $file, $transformParams, $thumbUrl ); |
||
| 55 | |||
| 56 | wfDebug( __METHOD__ . ": received status {$status}\n" ); |
||
| 57 | |||
| 58 | // 400 happens when requesting a size greater or equal than the original |
||
| 59 | if ( $status === 200 || $status === 301 || $status === 302 || $status === 400 ) { |
||
| 60 | return true; |
||
| 61 | } elseif ( $status ) { |
||
| 62 | $this->setLastError( __METHOD__ . ': incorrect HTTP status ' . |
||
| 63 | $status . ' when hitting ' . $thumbUrl ); |
||
| 64 | return false; |
||
| 65 | } else { |
||
| 66 | $this->setLastError( __METHOD__ . ': HTTP request failure' ); |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | } else { |
||
| 70 | $this->setLastError( __METHOD__ . ': unknown thumbnail render method ' . |
||
| 71 | $wgUploadThumbnailRenderMethod ); |
||
| 72 | return false; |
||
| 73 | } |
||
| 74 | } else { |
||
| 75 | $this->setLastError( __METHOD__ . ': file doesn\'t exist' ); |
||
| 76 | return false; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 112 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.