| Conditions | 9 |
| Paths | 24 |
| Total Lines | 82 |
| Code Lines | 53 |
| Lines | 6 |
| Ratio | 7.32 % |
| 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 |
||
| 42 | public function execute() { |
||
| 43 | $this->useTransactionalTimeLimit(); |
||
| 44 | |||
| 45 | $user = $this->getUser(); |
||
| 46 | $params = $this->extractRequestParams(); |
||
| 47 | |||
| 48 | $titleObj = $this->getRbTitle( $params ); |
||
| 49 | $pageObj = WikiPage::factory( $titleObj ); |
||
|
|
|||
| 50 | $summary = $params['summary']; |
||
| 51 | $details = []; |
||
| 52 | |||
| 53 | // If change tagging was requested, check that the user is allowed to tag, |
||
| 54 | // and the tags are valid |
||
| 55 | View Code Duplication | if ( count( $params['tags'] ) ) { |
|
| 56 | $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user ); |
||
| 57 | if ( !$tagStatus->isOK() ) { |
||
| 58 | $this->dieStatus( $tagStatus ); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | $retval = $pageObj->doRollback( |
||
| 63 | $this->getRbUser( $params ), |
||
| 64 | $summary, |
||
| 65 | $params['token'], |
||
| 66 | $params['markbot'], |
||
| 67 | $details, |
||
| 68 | $user, |
||
| 69 | $params['tags'] |
||
| 70 | ); |
||
| 71 | |||
| 72 | // We don't care about multiple errors, just report one of them |
||
| 73 | if ( $retval ) { |
||
| 74 | if ( isset( $retval[0][0] ) && |
||
| 75 | ( $retval[0][0] == 'alreadyrolled' || $retval[0][0] == 'cantrollback' ) |
||
| 76 | ) { |
||
| 77 | $error = $retval[0]; |
||
| 78 | $userMessage = $this->msg( $error[0], array_slice( $error, 1 ) ); |
||
| 79 | // dieUsageMsg() doesn't support $extraData |
||
| 80 | $errorCode = $error[0]; |
||
| 81 | $errorInfo = isset( ApiBase::$messageMap[$errorCode] ) ? |
||
| 82 | ApiBase::$messageMap[$errorCode]['info'] : |
||
| 83 | $errorCode; |
||
| 84 | $this->dieUsage( $errorInfo, $errorCode, 0, [ |
||
| 85 | 'messageHtml' => $userMessage->parseAsBlock() |
||
| 86 | ] ); |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->dieUsageMsg( reset( $retval ) ); |
||
| 90 | } |
||
| 91 | |||
| 92 | $watch = 'preferences'; |
||
| 93 | if ( isset( $params['watchlist'] ) ) { |
||
| 94 | $watch = $params['watchlist']; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Watch pages |
||
| 98 | $this->setWatch( $watch, $titleObj, 'watchrollback' ); |
||
| 99 | |||
| 100 | $info = [ |
||
| 101 | 'title' => $titleObj->getPrefixedText(), |
||
| 102 | 'pageid' => intval( $details['current']->getPage() ), |
||
| 103 | 'summary' => $details['summary'], |
||
| 104 | 'revid' => intval( $details['newid'] ), |
||
| 105 | // The revision being reverted (previously the current revision of the page) |
||
| 106 | 'old_revid' => intval( $details['current']->getID() ), |
||
| 107 | // The revision being restored (the last revision before revision(s) by the reverted user) |
||
| 108 | 'last_revid' => intval( $details['target']->getID() ) |
||
| 109 | ]; |
||
| 110 | |||
| 111 | $oldUser = $details['current']->getUserText( Revision::FOR_THIS_USER ); |
||
| 112 | $lastUser = $details['target']->getUserText( Revision::FOR_THIS_USER ); |
||
| 113 | $diffUrl = $titleObj->getFullURL( [ |
||
| 114 | 'diff' => $info['revid'], |
||
| 115 | 'oldid' => $info['old_revid'], |
||
| 116 | 'diffonly' => '1' |
||
| 117 | ] ); |
||
| 118 | $info['messageHtml'] = $this->msg( 'rollback-success-notify' ) |
||
| 119 | ->params( $oldUser, $lastUser, $diffUrl ) |
||
| 120 | ->parseAsBlock(); |
||
| 121 | |||
| 122 | $this->getResult()->addValue( null, $this->getModuleName(), $info ); |
||
| 123 | } |
||
| 124 | |||
| 235 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: