Conditions | 11 |
Paths | 22 |
Total Lines | 93 |
Code Lines | 70 |
Lines | 30 |
Ratio | 32.26 % |
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 |
||
27 | public function execute() { |
||
28 | $this->useTransactionalTimeLimit(); |
||
29 | |||
30 | $params = $this->extractRequestParams(); |
||
31 | $rotation = $params['rotation']; |
||
32 | |||
33 | $continuationManager = new ApiContinuationManager( $this, [], [] ); |
||
34 | $this->setContinuationManager( $continuationManager ); |
||
35 | |||
36 | $pageSet = $this->getPageSet(); |
||
37 | $pageSet->execute(); |
||
38 | |||
39 | $result = []; |
||
|
|||
40 | |||
41 | $result = $pageSet->getInvalidTitlesAndRevisions( [ |
||
42 | 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'interwikiTitles', |
||
43 | ] ); |
||
44 | |||
45 | foreach ( $pageSet->getTitles() as $title ) { |
||
46 | $r = []; |
||
47 | $r['id'] = $title->getArticleID(); |
||
48 | ApiQueryBase::addTitleInfo( $r, $title ); |
||
49 | View Code Duplication | if ( !$title->exists() ) { |
|
50 | $r['missing'] = true; |
||
51 | if ( $title->isKnown() ) { |
||
52 | $r['known'] = true; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | $file = wfFindFile( $title, [ 'latest' => true ] ); |
||
57 | View Code Duplication | if ( !$file ) { |
|
58 | $r['result'] = 'Failure'; |
||
59 | $r['errormessage'] = 'File does not exist'; |
||
60 | $result[] = $r; |
||
61 | continue; |
||
62 | } |
||
63 | $handler = $file->getHandler(); |
||
64 | View Code Duplication | if ( !$handler || !$handler->canRotate() ) { |
|
65 | $r['result'] = 'Failure'; |
||
66 | $r['errormessage'] = 'File type cannot be rotated'; |
||
67 | $result[] = $r; |
||
68 | continue; |
||
69 | } |
||
70 | |||
71 | // Check whether we're allowed to rotate this file |
||
72 | $permError = $this->checkPermissions( $this->getUser(), $file->getTitle() ); |
||
73 | View Code Duplication | if ( $permError !== null ) { |
|
74 | $r['result'] = 'Failure'; |
||
75 | $r['errormessage'] = $permError; |
||
76 | $result[] = $r; |
||
77 | continue; |
||
78 | } |
||
79 | |||
80 | $srcPath = $file->getLocalRefPath(); |
||
81 | View Code Duplication | if ( $srcPath === false ) { |
|
82 | $r['result'] = 'Failure'; |
||
83 | $r['errormessage'] = 'Cannot get local file path'; |
||
84 | $result[] = $r; |
||
85 | continue; |
||
86 | } |
||
87 | $ext = strtolower( pathinfo( "$srcPath", PATHINFO_EXTENSION ) ); |
||
88 | $tmpFile = TempFSFile::factory( 'rotate_', $ext, wfTempDir() ); |
||
89 | $dstPath = $tmpFile->getPath(); |
||
90 | $err = $handler->rotate( $file, [ |
||
91 | 'srcPath' => $srcPath, |
||
92 | 'dstPath' => $dstPath, |
||
93 | 'rotation' => $rotation |
||
94 | ] ); |
||
95 | if ( !$err ) { |
||
96 | $comment = wfMessage( |
||
97 | 'rotate-comment' |
||
98 | )->numParams( $rotation )->inContentLanguage()->text(); |
||
99 | $status = $file->upload( $dstPath, |
||
100 | $comment, $comment, 0, false, false, $this->getUser() ); |
||
101 | if ( $status->isGood() ) { |
||
102 | $r['result'] = 'Success'; |
||
103 | } else { |
||
104 | $r['result'] = 'Failure'; |
||
105 | $r['errormessage'] = $this->getErrorFormatter()->arrayFromStatus( $status ); |
||
106 | } |
||
107 | } else { |
||
108 | $r['result'] = 'Failure'; |
||
109 | $r['errormessage'] = $err->toText(); |
||
110 | } |
||
111 | $result[] = $r; |
||
112 | } |
||
113 | $apiResult = $this->getResult(); |
||
114 | ApiResult::setIndexedTagName( $result, 'page' ); |
||
115 | $apiResult->addValue( null, $this->getModuleName(), $result ); |
||
116 | |||
117 | $this->setContinuationManager( null ); |
||
118 | $continuationManager->setContinuationIntoResult( $apiResult ); |
||
119 | } |
||
120 | |||
194 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.