| Conditions | 23 |
| Paths | 2486 |
| Total Lines | 184 |
| Code Lines | 113 |
| 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 |
||
| 105 | public function setVisibility( array $params ) { |
||
| 106 | $status = Status::newGood(); |
||
| 107 | |||
| 108 | $bitPars = $params['value']; |
||
| 109 | $comment = $params['comment']; |
||
| 110 | $perItemStatus = isset( $params['perItemStatus'] ) ? $params['perItemStatus'] : false; |
||
| 111 | |||
| 112 | // CAS-style checks are done on the _deleted fields so the select |
||
| 113 | // does not need to use FOR UPDATE nor be in the atomic section |
||
| 114 | $dbw = wfGetDB( DB_MASTER ); |
||
| 115 | $this->res = $this->doQuery( $dbw ); |
||
| 116 | |||
| 117 | $status->merge( $this->acquireItemLocks() ); |
||
| 118 | if ( !$status->isGood() ) { |
||
| 119 | return $status; |
||
| 120 | } |
||
| 121 | |||
| 122 | $dbw->startAtomic( __METHOD__ ); |
||
| 123 | $dbw->onTransactionResolution( |
||
| 124 | function () { |
||
| 125 | // Release locks on commit or error |
||
| 126 | $this->releaseItemLocks(); |
||
| 127 | }, |
||
| 128 | __METHOD__ |
||
| 129 | ); |
||
| 130 | |||
| 131 | $missing = array_flip( $this->ids ); |
||
| 132 | $this->clearFileOps(); |
||
| 133 | $idsForLog = []; |
||
| 134 | $authorIds = $authorIPs = []; |
||
| 135 | |||
| 136 | if ( $perItemStatus ) { |
||
| 137 | $status->itemStatuses = []; |
||
| 138 | } |
||
| 139 | |||
| 140 | // For multi-item deletions, set the old/new bitfields in log_params such that "hid X" |
||
| 141 | // shows in logs if field X was hidden from ANY item and likewise for "unhid Y". Note the |
||
| 142 | // form does not let the same field get hidden and unhidden in different items at once. |
||
| 143 | $virtualOldBits = 0; |
||
| 144 | $virtualNewBits = 0; |
||
| 145 | $logType = 'delete'; |
||
| 146 | |||
| 147 | // Will be filled with id => [old, new bits] information and |
||
| 148 | // passed to doPostCommitUpdates(). |
||
| 149 | $visibilityChangeMap = []; |
||
| 150 | |||
| 151 | /** @var $item RevDelItem */ |
||
| 152 | foreach ( $this as $item ) { |
||
| 153 | unset( $missing[$item->getId()] ); |
||
| 154 | |||
| 155 | if ( $perItemStatus ) { |
||
| 156 | $itemStatus = Status::newGood(); |
||
| 157 | $status->itemStatuses[$item->getId()] = $itemStatus; |
||
| 158 | } else { |
||
| 159 | $itemStatus = $status; |
||
| 160 | } |
||
| 161 | |||
| 162 | $oldBits = $item->getBits(); |
||
| 163 | // Build the actual new rev_deleted bitfield |
||
| 164 | $newBits = RevisionDeleter::extractBitfield( $bitPars, $oldBits ); |
||
| 165 | |||
| 166 | if ( $oldBits == $newBits ) { |
||
| 167 | $itemStatus->warning( |
||
| 168 | 'revdelete-no-change', $item->formatDate(), $item->formatTime() ); |
||
| 169 | $status->failCount++; |
||
| 170 | continue; |
||
| 171 | } elseif ( $oldBits == 0 && $newBits != 0 ) { |
||
| 172 | $opType = 'hide'; |
||
| 173 | } elseif ( $oldBits != 0 && $newBits == 0 ) { |
||
| 174 | $opType = 'show'; |
||
| 175 | } else { |
||
| 176 | $opType = 'modify'; |
||
| 177 | } |
||
| 178 | |||
| 179 | if ( $item->isHideCurrentOp( $newBits ) ) { |
||
| 180 | // Cannot hide current version text |
||
| 181 | $itemStatus->error( |
||
| 182 | 'revdelete-hide-current', $item->formatDate(), $item->formatTime() ); |
||
| 183 | $status->failCount++; |
||
| 184 | continue; |
||
| 185 | } elseif ( !$item->canView() ) { |
||
| 186 | // Cannot access this revision |
||
| 187 | $msg = ( $opType == 'show' ) ? |
||
| 188 | 'revdelete-show-no-access' : 'revdelete-modify-no-access'; |
||
| 189 | $itemStatus->error( $msg, $item->formatDate(), $item->formatTime() ); |
||
| 190 | $status->failCount++; |
||
| 191 | continue; |
||
| 192 | // Cannot just "hide from Sysops" without hiding any fields |
||
| 193 | } elseif ( $newBits == Revision::DELETED_RESTRICTED ) { |
||
| 194 | $itemStatus->warning( |
||
| 195 | 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() ); |
||
| 196 | $status->failCount++; |
||
| 197 | continue; |
||
| 198 | } |
||
| 199 | |||
| 200 | // Update the revision |
||
| 201 | $ok = $item->setBits( $newBits ); |
||
| 202 | |||
| 203 | if ( $ok ) { |
||
| 204 | $idsForLog[] = $item->getId(); |
||
| 205 | // If any item field was suppressed or unsupressed |
||
| 206 | if ( ( $oldBits | $newBits ) & $this->getSuppressBit() ) { |
||
| 207 | $logType = 'suppress'; |
||
| 208 | } |
||
| 209 | // Track which fields where (un)hidden for each item |
||
| 210 | $addedBits = ( $oldBits ^ $newBits ) & $newBits; |
||
| 211 | $removedBits = ( $oldBits ^ $newBits ) & $oldBits; |
||
| 212 | $virtualNewBits |= $addedBits; |
||
| 213 | $virtualOldBits |= $removedBits; |
||
| 214 | |||
| 215 | $status->successCount++; |
||
| 216 | if ( $item->getAuthorId() > 0 ) { |
||
| 217 | $authorIds[] = $item->getAuthorId(); |
||
| 218 | } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) { |
||
| 219 | $authorIPs[] = $item->getAuthorName(); |
||
| 220 | } |
||
| 221 | |||
| 222 | // Save the old and new bits in $visibilityChangeMap for |
||
| 223 | // later use. |
||
| 224 | $visibilityChangeMap[$item->getId()] = [ |
||
| 225 | 'oldBits' => $oldBits, |
||
| 226 | 'newBits' => $newBits, |
||
| 227 | ]; |
||
| 228 | } else { |
||
| 229 | $itemStatus->error( |
||
| 230 | 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() ); |
||
| 231 | $status->failCount++; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | // Handle missing revisions |
||
| 236 | foreach ( $missing as $id => $unused ) { |
||
| 237 | if ( $perItemStatus ) { |
||
| 238 | $status->itemStatuses[$id] = Status::newFatal( 'revdelete-modify-missing', $id ); |
||
| 239 | } else { |
||
| 240 | $status->error( 'revdelete-modify-missing', $id ); |
||
| 241 | } |
||
| 242 | $status->failCount++; |
||
| 243 | } |
||
| 244 | |||
| 245 | if ( $status->successCount == 0 ) { |
||
| 246 | $dbw->endAtomic( __METHOD__ ); |
||
| 247 | return $status; |
||
| 248 | } |
||
| 249 | |||
| 250 | // Save success count |
||
| 251 | $successCount = $status->successCount; |
||
| 252 | |||
| 253 | // Move files, if there are any |
||
| 254 | $status->merge( $this->doPreCommitUpdates() ); |
||
| 255 | if ( !$status->isOK() ) { |
||
| 256 | // Fatal error, such as no configured archive directory or I/O failures |
||
| 257 | wfGetLBFactory()->rollbackMasterChanges( __METHOD__ ); |
||
| 258 | return $status; |
||
| 259 | } |
||
| 260 | |||
| 261 | // Log it |
||
| 262 | $this->updateLog( |
||
| 263 | $logType, |
||
| 264 | [ |
||
| 265 | 'title' => $this->title, |
||
| 266 | 'count' => $successCount, |
||
| 267 | 'newBits' => $virtualNewBits, |
||
| 268 | 'oldBits' => $virtualOldBits, |
||
| 269 | 'comment' => $comment, |
||
| 270 | 'ids' => $idsForLog, |
||
| 271 | 'authorIds' => $authorIds, |
||
| 272 | 'authorIPs' => $authorIPs |
||
| 273 | ] |
||
| 274 | ); |
||
| 275 | |||
| 276 | // Clear caches after commit |
||
| 277 | DeferredUpdates::addCallableUpdate( |
||
| 278 | function () use ( $visibilityChangeMap ) { |
||
| 279 | $this->doPostCommitUpdates( $visibilityChangeMap ); |
||
| 280 | }, |
||
| 281 | DeferredUpdates::PRESEND, |
||
| 282 | $dbw |
||
| 283 | ); |
||
| 284 | |||
| 285 | $dbw->endAtomic( __METHOD__ ); |
||
| 286 | |||
| 287 | return $status; |
||
| 288 | } |
||
| 289 | |||
| 409 |
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.