Conditions | 13 |
Paths | 768 |
Total Lines | 63 |
Code Lines | 40 |
Lines | 6 |
Ratio | 9.52 % |
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 |
||
32 | public function execute() { |
||
33 | $this->useTransactionalTimeLimit(); |
||
34 | |||
35 | $params = $this->extractRequestParams(); |
||
36 | $user = $this->getUser(); |
||
37 | if ( !$user->isAllowed( 'undelete' ) ) { |
||
38 | $this->dieUsageMsg( 'permdenied-undelete' ); |
||
39 | } |
||
40 | |||
41 | if ( $user->isBlocked() ) { |
||
42 | $this->dieBlocked( $user->getBlock() ); |
||
|
|||
43 | } |
||
44 | |||
45 | $titleObj = Title::newFromText( $params['title'] ); |
||
46 | if ( !$titleObj || $titleObj->isExternal() ) { |
||
47 | $this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] ); |
||
48 | } |
||
49 | |||
50 | // Check if user can add tags |
||
51 | View Code Duplication | if ( !is_null( $params['tags'] ) ) { |
|
52 | $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user ); |
||
53 | if ( !$ableToTag->isOK() ) { |
||
54 | $this->dieStatus( $ableToTag ); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | // Convert timestamps |
||
59 | if ( !isset( $params['timestamps'] ) ) { |
||
60 | $params['timestamps'] = []; |
||
61 | } |
||
62 | if ( !is_array( $params['timestamps'] ) ) { |
||
63 | $params['timestamps'] = [ $params['timestamps'] ]; |
||
64 | } |
||
65 | foreach ( $params['timestamps'] as $i => $ts ) { |
||
66 | $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts ); |
||
67 | } |
||
68 | |||
69 | $pa = new PageArchive( $titleObj, $this->getConfig() ); |
||
70 | $retval = $pa->undelete( |
||
71 | ( isset( $params['timestamps'] ) ? $params['timestamps'] : [] ), |
||
72 | $params['reason'], |
||
73 | $params['fileids'], |
||
74 | false, |
||
75 | $user, |
||
76 | $params['tags'] |
||
77 | ); |
||
78 | if ( !is_array( $retval ) ) { |
||
79 | $this->dieUsageMsg( 'cannotundelete' ); |
||
80 | } |
||
81 | |||
82 | if ( $retval[1] ) { |
||
83 | Hooks::run( 'FileUndeleteComplete', |
||
84 | [ $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ] ); |
||
85 | } |
||
86 | |||
87 | $this->setWatch( $params['watchlist'], $titleObj ); |
||
88 | |||
89 | $info['title'] = $titleObj->getPrefixedText(); |
||
90 | $info['revisions'] = intval( $retval[0] ); |
||
91 | $info['fileversions'] = intval( $retval[1] ); |
||
92 | $info['reason'] = $retval[2]; |
||
93 | $this->getResult()->addValue( null, $this->getModuleName(), $info ); |
||
94 | } |
||
95 | |||
153 |
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: