| Conditions | 17 |
| Paths | 16 |
| Total Lines | 109 |
| Code Lines | 63 |
| 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 |
||
| 115 | public function getActionLinks() { |
||
| 116 | $user = $this->context->getUser(); |
||
| 117 | if ( !$user->isAllowed( 'deletedhistory' ) |
||
| 118 | || $this->entry->isDeleted( LogPage::DELETED_ACTION ) |
||
| 119 | ) { |
||
| 120 | return ''; |
||
| 121 | } |
||
| 122 | |||
| 123 | switch ( $this->entry->getSubtype() ) { |
||
| 124 | case 'delete': // Show undelete link |
||
| 125 | if ( $user->isAllowed( 'undelete' ) ) { |
||
| 126 | $message = 'undeletelink'; |
||
| 127 | } else { |
||
| 128 | $message = 'undeleteviewlink'; |
||
| 129 | } |
||
| 130 | $revert = Linker::linkKnown( |
||
| 131 | SpecialPage::getTitleFor( 'Undelete' ), |
||
| 132 | $this->msg( $message )->escaped(), |
||
| 133 | [], |
||
| 134 | [ 'target' => $this->entry->getTarget()->getPrefixedDBkey() ] |
||
| 135 | ); |
||
| 136 | |||
| 137 | return $this->msg( 'parentheses' )->rawParams( $revert )->escaped(); |
||
| 138 | |||
| 139 | case 'revision': // If an edit was hidden from a page give a review link to the history |
||
| 140 | $params = $this->extractParameters(); |
||
| 141 | if ( !isset( $params[3] ) || !isset( $params[4] ) ) { |
||
| 142 | return ''; |
||
| 143 | } |
||
| 144 | |||
| 145 | // Different revision types use different URL params... |
||
| 146 | $key = $params[3]; |
||
| 147 | // This is a array or CSV of the IDs |
||
| 148 | $ids = is_array( $params[4] ) |
||
| 149 | ? $params[4] |
||
| 150 | : explode( ',', $params[4] ); |
||
| 151 | |||
| 152 | $links = []; |
||
| 153 | |||
| 154 | // If there's only one item, we can show a diff link |
||
| 155 | if ( count( $ids ) == 1 ) { |
||
| 156 | // Live revision diffs... |
||
| 157 | if ( $key == 'oldid' || $key == 'revision' ) { |
||
| 158 | $links[] = Linker::linkKnown( |
||
| 159 | $this->entry->getTarget(), |
||
| 160 | $this->msg( 'diff' )->escaped(), |
||
| 161 | [], |
||
| 162 | [ |
||
| 163 | 'diff' => intval( $ids[0] ), |
||
| 164 | 'unhide' => 1 |
||
| 165 | ] |
||
| 166 | ); |
||
| 167 | // Deleted revision diffs... |
||
| 168 | } elseif ( $key == 'artimestamp' || $key == 'archive' ) { |
||
| 169 | $links[] = Linker::linkKnown( |
||
| 170 | SpecialPage::getTitleFor( 'Undelete' ), |
||
| 171 | $this->msg( 'diff' )->escaped(), |
||
| 172 | [], |
||
| 173 | [ |
||
| 174 | 'target' => $this->entry->getTarget()->getPrefixedDBkey(), |
||
| 175 | 'diff' => 'prev', |
||
| 176 | 'timestamp' => $ids[0] |
||
| 177 | ] |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | // View/modify link... |
||
| 183 | $links[] = Linker::linkKnown( |
||
| 184 | SpecialPage::getTitleFor( 'Revisiondelete' ), |
||
| 185 | $this->msg( 'revdel-restore' )->escaped(), |
||
| 186 | [], |
||
| 187 | [ |
||
| 188 | 'target' => $this->entry->getTarget()->getPrefixedText(), |
||
| 189 | 'type' => $key, |
||
| 190 | 'ids' => implode( ',', $ids ), |
||
| 191 | ] |
||
| 192 | ); |
||
| 193 | |||
| 194 | return $this->msg( 'parentheses' )->rawParams( |
||
| 195 | $this->context->getLanguage()->pipeList( $links ) )->escaped(); |
||
| 196 | |||
| 197 | case 'event': // Hidden log items, give review link |
||
| 198 | $params = $this->extractParameters(); |
||
| 199 | if ( !isset( $params[3] ) ) { |
||
| 200 | return ''; |
||
| 201 | } |
||
| 202 | // This is a CSV of the IDs |
||
| 203 | $query = $params[3]; |
||
| 204 | if ( is_array( $query ) ) { |
||
| 205 | $query = implode( ',', $query ); |
||
| 206 | } |
||
| 207 | // Link to each hidden object ID, $params[1] is the url param |
||
| 208 | $revert = Linker::linkKnown( |
||
| 209 | SpecialPage::getTitleFor( 'Revisiondelete' ), |
||
| 210 | $this->msg( 'revdel-restore' )->escaped(), |
||
| 211 | [], |
||
| 212 | [ |
||
| 213 | 'target' => $this->entry->getTarget()->getPrefixedText(), |
||
| 214 | 'type' => 'logging', |
||
| 215 | 'ids' => $query |
||
| 216 | ] |
||
| 217 | ); |
||
| 218 | |||
| 219 | return $this->msg( 'parentheses' )->rawParams( $revert )->escaped(); |
||
| 220 | default: |
||
| 221 | return ''; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 288 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: