| Conditions | 10 |
| Paths | 21 |
| Total Lines | 68 |
| Code Lines | 44 |
| 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 |
||
| 217 | public function getAssessments() |
||
| 218 | { |
||
| 219 | $projectDomain = $this->project->getDomain(); |
||
| 220 | $config = $this->project->getRepository()->getAssessmentsConfig($projectDomain); |
||
|
1 ignored issue
–
show
|
|||
| 221 | $data = $this->getRepository()->getAssessments($this->project, [$this->getId()]); |
||
|
1 ignored issue
–
show
|
|||
| 222 | |||
| 223 | // Set the default decorations for the overall quality assessment |
||
| 224 | // This will be replaced with the first valid class defined for any WikiProject |
||
| 225 | $overallQuality = $config['class']['Unknown']; |
||
| 226 | $overallQuality['value'] = '???'; |
||
| 227 | |||
| 228 | $decoratedAssessments = []; |
||
| 229 | |||
| 230 | foreach ($data as $assessment) { |
||
| 231 | $classValue = $assessment['class']; |
||
| 232 | |||
| 233 | // Use ??? as the presented value when the class is unknown or is not defined in the config |
||
| 234 | if ($classValue === 'Unknown' || $classValue === '' || !isset($config['class'][$classValue])) { |
||
| 235 | $classAttrs = $config['class']['Unknown']; |
||
| 236 | $assessment['class']['value'] = '???'; |
||
| 237 | $assessment['class']['category'] = $classAttrs['category']; |
||
| 238 | $assessment['class']['badge'] = "https://upload.wikimedia.org/wikipedia/commons/". $classAttrs['badge']; |
||
| 239 | } else { |
||
| 240 | $classAttrs = $config['class'][$classValue]; |
||
| 241 | $assessment['class'] = [ |
||
| 242 | 'value' => $classValue, |
||
| 243 | 'color' => $classAttrs['color'], |
||
| 244 | 'category' => $classAttrs['category'], |
||
| 245 | ]; |
||
| 246 | |||
| 247 | // add full URL to badge icon |
||
| 248 | if ($classAttrs['badge'] !== '') { |
||
| 249 | $assessment['class']['badge'] = $this->project->getAssessmentBadgeURL($classValue); |
||
| 250 | } |
||
| 251 | |||
| 252 | if ($overallQuality['value'] === '???') { |
||
| 253 | $overallQuality = $assessment['class']; |
||
| 254 | $overallQuality['category'] = $classAttrs['category']; |
||
| 255 | } |
||
| 256 | } |
||
| 257 | |||
| 258 | $importanceValue = $assessment['importance']; |
||
| 259 | $importanceUnknown = $importanceValue === 'Unknown' || $importanceValue === ''; |
||
| 260 | |||
| 261 | if ($importanceUnknown || !isset($config['importance'][$importanceValue])) { |
||
| 262 | $importanceAttrs = $config['importance']['Unknown']; |
||
| 263 | $assessment['importance'] = $importanceAttrs; |
||
| 264 | $assessment['importance']['value'] = '???'; |
||
| 265 | $assessment['importance']['category'] = $importanceAttrs['category']; |
||
| 266 | } else { |
||
| 267 | $importanceAttrs = $config['importance'][$importanceValue]; |
||
| 268 | $assessment['importance'] = [ |
||
| 269 | 'value' => $importanceValue, |
||
| 270 | 'color' => $importanceAttrs['color'], |
||
| 271 | 'weight' => $importanceAttrs['weight'], // numerical weight for sorting purposes |
||
| 272 | 'category' => $importanceAttrs['category'], |
||
| 273 | ]; |
||
| 274 | } |
||
| 275 | |||
| 276 | $decoratedAssessments[$assessment['wikiproject']] = $assessment; |
||
| 277 | } |
||
| 278 | |||
| 279 | return [ |
||
| 280 | 'assessment' => $overallQuality, |
||
| 281 | 'wikiprojects' => $decoratedAssessments, |
||
| 282 | 'wikiproject_prefix' => $config['wikiproject_prefix'] |
||
| 283 | ]; |
||
| 284 | } |
||
| 285 | } |
||
| 286 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.