| Conditions | 7 |
| Paths | 18 |
| Total Lines | 65 |
| Code Lines | 42 |
| Lines | 15 |
| Ratio | 23.08 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 53 | function getQueryInfo() { |
||
| 54 | $conds = $jconds = []; |
||
| 55 | $tables = [ 'image' ]; |
||
| 56 | $fields = [ 'img_name', 'img_user', 'img_timestamp' ]; |
||
| 57 | $options = []; |
||
| 58 | |||
| 59 | View Code Duplication | if ( !$this->showBots ) { |
|
| 60 | $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' ); |
||
| 61 | |||
| 62 | if ( count( $groupsWithBotPermission ) ) { |
||
| 63 | $tables[] = 'user_groups'; |
||
| 64 | $conds[] = 'ug_group IS NULL'; |
||
| 65 | $jconds['user_groups'] = [ |
||
| 66 | 'LEFT JOIN', |
||
| 67 | [ |
||
| 68 | 'ug_group' => $groupsWithBotPermission, |
||
| 69 | 'ug_user = img_user' |
||
| 70 | ] |
||
| 71 | ]; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | if ( $this->hidePatrolled ) { |
||
| 76 | $tables[] = 'recentchanges'; |
||
| 77 | $conds['rc_type'] = RC_LOG; |
||
| 78 | $conds['rc_log_type'] = 'upload'; |
||
| 79 | $conds['rc_patrolled'] = 0; |
||
| 80 | $conds['rc_namespace'] = NS_FILE; |
||
| 81 | $jconds['recentchanges'] = [ |
||
| 82 | 'INNER JOIN', |
||
| 83 | [ |
||
| 84 | 'rc_title = img_name', |
||
| 85 | 'rc_user = img_user', |
||
| 86 | 'rc_timestamp = img_timestamp' |
||
| 87 | ] |
||
| 88 | ]; |
||
| 89 | // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first. |
||
| 90 | // It sometimes decides to query `recentchanges` first and filesort the result set later |
||
| 91 | // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880 |
||
| 92 | $options[] = 'STRAIGHT_JOIN'; |
||
| 93 | } |
||
| 94 | |||
| 95 | if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) { |
||
| 96 | $dbr = wfGetDB( DB_SLAVE ); |
||
| 97 | $likeObj = Title::newFromText( $this->like ); |
||
| 98 | if ( $likeObj instanceof Title ) { |
||
| 99 | $like = $dbr->buildLike( |
||
| 100 | $dbr->anyString(), |
||
| 101 | strtolower( $likeObj->getDBkey() ), |
||
| 102 | $dbr->anyString() |
||
| 103 | ); |
||
| 104 | $conds[] = "LOWER(img_name) $like"; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $query = [ |
||
| 109 | 'tables' => $tables, |
||
| 110 | 'fields' => $fields, |
||
| 111 | 'join_conds' => $jconds, |
||
| 112 | 'conds' => $conds, |
||
| 113 | 'options' => $options, |
||
| 114 | ]; |
||
| 115 | |||
| 116 | return $query; |
||
| 117 | } |
||
| 118 | |||
| 208 |
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: