Conditions | 19 |
Paths | > 20000 |
Total Lines | 88 |
Code Lines | 59 |
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 |
||
34 | public function execute() { |
||
35 | $this->useTransactionalTimeLimit(); |
||
36 | |||
37 | $params = $this->extractRequestParams(); |
||
38 | $user = $this->getUser(); |
||
39 | if ( !$user->isAllowed( RevisionDeleter::getRestriction( $params['type'] ) ) ) { |
||
40 | $this->dieUsageMsg( 'badaccess-group0' ); |
||
41 | } |
||
42 | |||
43 | if ( $user->isBlocked() ) { |
||
44 | $this->dieBlocked( $user->getBlock() ); |
||
|
|||
45 | } |
||
46 | |||
47 | if ( !$params['ids'] ) { |
||
48 | $this->dieUsage( "At least one value is required for 'ids'", 'badparams' ); |
||
49 | } |
||
50 | |||
51 | $hide = $params['hide'] ?: []; |
||
52 | $show = $params['show'] ?: []; |
||
53 | if ( array_intersect( $hide, $show ) ) { |
||
54 | $this->dieUsage( "Mutually exclusive values for 'hide' and 'show'", 'badparams' ); |
||
55 | } elseif ( !$hide && !$show ) { |
||
56 | $this->dieUsage( "At least one value is required for 'hide' or 'show'", 'badparams' ); |
||
57 | } |
||
58 | $bits = [ |
||
59 | 'content' => RevisionDeleter::getRevdelConstant( $params['type'] ), |
||
60 | 'comment' => Revision::DELETED_COMMENT, |
||
61 | 'user' => Revision::DELETED_USER, |
||
62 | ]; |
||
63 | $bitfield = []; |
||
64 | foreach ( $bits as $key => $bit ) { |
||
65 | if ( in_array( $key, $hide ) ) { |
||
66 | $bitfield[$bit] = 1; |
||
67 | } elseif ( in_array( $key, $show ) ) { |
||
68 | $bitfield[$bit] = 0; |
||
69 | } else { |
||
70 | $bitfield[$bit] = -1; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | if ( $params['suppress'] === 'yes' ) { |
||
75 | if ( !$user->isAllowed( 'suppressrevision' ) ) { |
||
76 | $this->dieUsageMsg( 'badaccess-group0' ); |
||
77 | } |
||
78 | $bitfield[Revision::DELETED_RESTRICTED] = 1; |
||
79 | } elseif ( $params['suppress'] === 'no' ) { |
||
80 | $bitfield[Revision::DELETED_RESTRICTED] = 0; |
||
81 | } else { |
||
82 | $bitfield[Revision::DELETED_RESTRICTED] = -1; |
||
83 | } |
||
84 | |||
85 | $targetObj = null; |
||
86 | if ( $params['target'] ) { |
||
87 | $targetObj = Title::newFromText( $params['target'] ); |
||
88 | } |
||
89 | $targetObj = RevisionDeleter::suggestTarget( $params['type'], $targetObj, $params['ids'] ); |
||
90 | if ( $targetObj === null ) { |
||
91 | $this->dieUsage( 'A target title is required for this RevDel type', 'needtarget' ); |
||
92 | } |
||
93 | |||
94 | $list = RevisionDeleter::createList( |
||
95 | $params['type'], $this->getContext(), $targetObj, $params['ids'] |
||
96 | ); |
||
97 | $status = $list->setVisibility( |
||
98 | [ 'value' => $bitfield, 'comment' => $params['reason'], 'perItemStatus' => true ] |
||
99 | ); |
||
100 | |||
101 | $result = $this->getResult(); |
||
102 | $data = $this->extractStatusInfo( $status ); |
||
103 | $data['target'] = $targetObj->getFullText(); |
||
104 | $data['items'] = []; |
||
105 | |||
106 | foreach ( $status->itemStatuses as $id => $s ) { |
||
107 | $data['items'][$id] = $this->extractStatusInfo( $s ); |
||
108 | $data['items'][$id]['id'] = $id; |
||
109 | } |
||
110 | |||
111 | $list->reloadFromMaster(); |
||
112 | // @codingStandardsIgnoreStart Avoid function calls in a FOR loop test part |
||
113 | for ( $item = $list->reset(); $list->current(); $item = $list->next() ) { |
||
114 | $data['items'][$item->getId()] += $item->getApiData( $this->getResult() ); |
||
115 | } |
||
116 | // @codingStandardsIgnoreEnd |
||
117 | |||
118 | $data['items'] = array_values( $data['items'] ); |
||
119 | ApiResult::setIndexedTagName( $data['items'], 'i' ); |
||
120 | $result->addValue( null, $this->getModuleName(), $data ); |
||
121 | } |
||
122 | |||
224 |
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: