Conditions | 22 |
Paths | 2484 |
Total Lines | 160 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 |
||
106 | public function setVisibility( array $params ) { |
||
107 | $bitPars = $params['value']; |
||
108 | $comment = $params['comment']; |
||
109 | $perItemStatus = isset( $params['perItemStatus'] ) ? $params['perItemStatus'] : false; |
||
110 | |||
111 | // CAS-style checks are done on the _deleted fields so the select |
||
112 | // does not need to use FOR UPDATE nor be in the atomic section |
||
113 | $dbw = wfGetDB( DB_MASTER ); |
||
114 | $this->res = $this->doQuery( $dbw ); |
||
115 | |||
116 | $dbw->startAtomic( __METHOD__ ); |
||
117 | |||
118 | $status = Status::newGood(); |
||
119 | $missing = array_flip( $this->ids ); |
||
120 | $this->clearFileOps(); |
||
121 | $idsForLog = []; |
||
122 | $authorIds = $authorIPs = []; |
||
123 | |||
124 | if ( $perItemStatus ) { |
||
125 | $status->itemStatuses = []; |
||
126 | } |
||
127 | |||
128 | // For multi-item deletions, set the old/new bitfields in log_params such that "hid X" |
||
129 | // shows in logs if field X was hidden from ANY item and likewise for "unhid Y". Note the |
||
130 | // form does not let the same field get hidden and unhidden in different items at once. |
||
131 | $virtualOldBits = 0; |
||
132 | $virtualNewBits = 0; |
||
133 | $logType = 'delete'; |
||
134 | |||
135 | // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed |
||
136 | for ( $this->reset(); $this->current(); $this->next() ) { |
||
137 | // @codingStandardsIgnoreEnd |
||
138 | /** @var $item RevDelItem */ |
||
139 | $item = $this->current(); |
||
140 | unset( $missing[$item->getId()] ); |
||
141 | |||
142 | if ( $perItemStatus ) { |
||
143 | $itemStatus = Status::newGood(); |
||
144 | $status->itemStatuses[$item->getId()] = $itemStatus; |
||
145 | } else { |
||
146 | $itemStatus = $status; |
||
147 | } |
||
148 | |||
149 | $oldBits = $item->getBits(); |
||
150 | // Build the actual new rev_deleted bitfield |
||
151 | $newBits = RevisionDeleter::extractBitfield( $bitPars, $oldBits ); |
||
152 | |||
153 | if ( $oldBits == $newBits ) { |
||
154 | $itemStatus->warning( |
||
155 | 'revdelete-no-change', $item->formatDate(), $item->formatTime() ); |
||
156 | $status->failCount++; |
||
157 | continue; |
||
158 | } elseif ( $oldBits == 0 && $newBits != 0 ) { |
||
159 | $opType = 'hide'; |
||
160 | } elseif ( $oldBits != 0 && $newBits == 0 ) { |
||
161 | $opType = 'show'; |
||
162 | } else { |
||
163 | $opType = 'modify'; |
||
164 | } |
||
165 | |||
166 | if ( $item->isHideCurrentOp( $newBits ) ) { |
||
167 | // Cannot hide current version text |
||
168 | $itemStatus->error( |
||
169 | 'revdelete-hide-current', $item->formatDate(), $item->formatTime() ); |
||
170 | $status->failCount++; |
||
171 | continue; |
||
172 | } elseif ( !$item->canView() ) { |
||
173 | // Cannot access this revision |
||
174 | $msg = ( $opType == 'show' ) ? |
||
175 | 'revdelete-show-no-access' : 'revdelete-modify-no-access'; |
||
176 | $itemStatus->error( $msg, $item->formatDate(), $item->formatTime() ); |
||
177 | $status->failCount++; |
||
178 | continue; |
||
179 | // Cannot just "hide from Sysops" without hiding any fields |
||
180 | } elseif ( $newBits == Revision::DELETED_RESTRICTED ) { |
||
181 | $itemStatus->warning( |
||
182 | 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() ); |
||
183 | $status->failCount++; |
||
184 | continue; |
||
185 | } |
||
186 | |||
187 | // Update the revision |
||
188 | $ok = $item->setBits( $newBits ); |
||
189 | |||
190 | if ( $ok ) { |
||
191 | $idsForLog[] = $item->getId(); |
||
192 | // If any item field was suppressed or unsupressed |
||
193 | if ( ( $oldBits | $newBits ) & $this->getSuppressBit() ) { |
||
194 | $logType = 'suppress'; |
||
195 | } |
||
196 | // Track which fields where (un)hidden for each item |
||
197 | $addedBits = ( $oldBits ^ $newBits ) & $newBits; |
||
198 | $removedBits = ( $oldBits ^ $newBits ) & $oldBits; |
||
199 | $virtualNewBits |= $addedBits; |
||
200 | $virtualOldBits |= $removedBits; |
||
201 | |||
202 | $status->successCount++; |
||
203 | if ( $item->getAuthorId() > 0 ) { |
||
204 | $authorIds[] = $item->getAuthorId(); |
||
205 | } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) { |
||
206 | $authorIPs[] = $item->getAuthorName(); |
||
207 | } |
||
208 | } else { |
||
209 | $itemStatus->error( |
||
210 | 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() ); |
||
211 | $status->failCount++; |
||
212 | } |
||
213 | } |
||
214 | |||
215 | // Handle missing revisions |
||
216 | foreach ( $missing as $id => $unused ) { |
||
217 | if ( $perItemStatus ) { |
||
218 | $status->itemStatuses[$id] = Status::newFatal( 'revdelete-modify-missing', $id ); |
||
219 | } else { |
||
220 | $status->error( 'revdelete-modify-missing', $id ); |
||
221 | } |
||
222 | $status->failCount++; |
||
223 | } |
||
224 | |||
225 | if ( $status->successCount == 0 ) { |
||
226 | $dbw->rollback( __METHOD__ ); |
||
227 | return $status; |
||
228 | } |
||
229 | |||
230 | // Save success count |
||
231 | $successCount = $status->successCount; |
||
232 | |||
233 | // Move files, if there are any |
||
234 | $status->merge( $this->doPreCommitUpdates() ); |
||
235 | if ( !$status->isOK() ) { |
||
236 | // Fatal error, such as no configured archive directory |
||
237 | $dbw->rollback( __METHOD__ ); |
||
238 | return $status; |
||
239 | } |
||
240 | |||
241 | // Log it |
||
242 | $this->updateLog( |
||
243 | $logType, |
||
244 | [ |
||
245 | 'title' => $this->title, |
||
246 | 'count' => $successCount, |
||
247 | 'newBits' => $virtualNewBits, |
||
248 | 'oldBits' => $virtualOldBits, |
||
249 | 'comment' => $comment, |
||
250 | 'ids' => $idsForLog, |
||
251 | 'authorIds' => $authorIds, |
||
252 | 'authorIPs' => $authorIPs |
||
253 | ] |
||
254 | ); |
||
255 | |||
256 | // Clear caches |
||
257 | $that = $this; |
||
258 | $dbw->onTransactionIdle( function() use ( $that ) { |
||
259 | $that->doPostCommitUpdates(); |
||
260 | } ); |
||
261 | |||
262 | $dbw->endAtomic( __METHOD__ ); |
||
263 | |||
264 | return $status; |
||
265 | } |
||
266 | |||
365 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.