| Conditions | 15 |
| Paths | 673 |
| Total Lines | 77 |
| Code Lines | 47 |
| Lines | 17 |
| Ratio | 22.08 % |
| 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 |
||
| 114 | protected function getContributors( $cnt, $showIfMax ) { |
||
| 115 | $contributors = $this->page->getContributors(); |
||
| 116 | |||
| 117 | $others_link = false; |
||
| 118 | |||
| 119 | # Hmm... too many to fit! |
||
| 120 | if ( $cnt > 0 && $contributors->count() > $cnt ) { |
||
| 121 | $others_link = $this->othersLink(); |
||
| 122 | if ( !$showIfMax ) { |
||
| 123 | return $this->msg( 'othercontribs' )->rawParams( |
||
| 124 | $others_link )->params( $contributors->count() )->escaped(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | $real_names = []; |
||
| 129 | $user_names = []; |
||
| 130 | $anon_ips = []; |
||
| 131 | |||
| 132 | # Sift for real versus user names |
||
| 133 | /** @var $user User */ |
||
| 134 | foreach ( $contributors as $user ) { |
||
| 135 | $cnt--; |
||
| 136 | if ( $user->isLoggedIn() ) { |
||
| 137 | $link = $this->link( $user ); |
||
| 138 | if ( $this->canShowRealUserName() && $user->getRealName() ) { |
||
| 139 | $real_names[] = $link; |
||
| 140 | } else { |
||
| 141 | $user_names[] = $link; |
||
| 142 | } |
||
| 143 | } else { |
||
| 144 | $anon_ips[] = $this->link( $user ); |
||
| 145 | } |
||
| 146 | |||
| 147 | if ( $cnt == 0 ) { |
||
| 148 | break; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | $lang = $this->getLanguage(); |
||
| 153 | |||
| 154 | if ( count( $real_names ) ) { |
||
| 155 | $real = $lang->listToText( $real_names ); |
||
| 156 | } else { |
||
| 157 | $real = false; |
||
| 158 | } |
||
| 159 | |||
| 160 | # "ThisSite user(s) A, B and C" |
||
| 161 | View Code Duplication | if ( count( $user_names ) ) { |
|
| 162 | $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params( |
||
| 163 | count( $user_names ) )->escaped(); |
||
| 164 | } else { |
||
| 165 | $user = false; |
||
| 166 | } |
||
| 167 | |||
| 168 | View Code Duplication | if ( count( $anon_ips ) ) { |
|
| 169 | $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params( |
||
| 170 | count( $anon_ips ) )->escaped(); |
||
| 171 | } else { |
||
| 172 | $anon = false; |
||
| 173 | } |
||
| 174 | |||
| 175 | # This is the big list, all mooshed together. We sift for blank strings |
||
| 176 | $fulllist = []; |
||
| 177 | View Code Duplication | foreach ( [ $real, $user, $anon, $others_link ] as $s ) { |
|
| 178 | if ( $s !== false ) { |
||
| 179 | array_push( $fulllist, $s ); |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | $count = count( $fulllist ); |
||
| 184 | |||
| 185 | # "Based on work by ..." |
||
| 186 | return $count |
||
| 187 | ? $this->msg( 'othercontribs' )->rawParams( |
||
| 188 | $lang->listToText( $fulllist ) )->params( $count )->escaped() |
||
| 189 | : ''; |
||
| 190 | } |
||
| 191 | |||
| 242 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: