| Conditions | 10 |
| Paths | 257 |
| Total Lines | 56 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 42 | public function getFormattedResults() |
||
| 43 | { |
||
| 44 | $formattedResult = []; |
||
| 45 | $checks = []; |
||
| 46 | $status = Result::STATUS_PASS; |
||
| 47 | |||
| 48 | foreach ($this->results as $result) { |
||
| 49 | $check = [ |
||
| 50 | 'status' => $result->getStatus(), |
||
| 51 | 'output' => $result->getMessage() |
||
| 52 | ]; |
||
| 53 | |||
| 54 | if (is_numeric($result->getLimit())) { |
||
| 55 | $check['limit'] = $result->getLimit(); |
||
| 56 | } |
||
| 57 | |||
| 58 | if (!is_null($result->getLimitType())) { |
||
| 59 | $check['limitType'] = $result->getLimitType(); |
||
| 60 | } |
||
| 61 | |||
| 62 | if (!is_null($result->getObservedValue())) { |
||
| 63 | $check['observedValue'] = $result->getObservedValue(); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (!is_null($result->getObservedValueUnit())) { |
||
| 67 | $check['observedUnit'] = $result->getObservedValueUnit(); |
||
| 68 | } |
||
| 69 | |||
| 70 | if (!is_null($result->getObservedValuePrecision())) { |
||
| 71 | $check['observedValuePrecision'] = $result->getObservedValuePrecision(); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!is_null($result->getType())) { |
||
| 75 | $check['metricType'] = $result->getType(); |
||
| 76 | } |
||
| 77 | |||
| 78 | $attributes = $result->getAttributes(); |
||
| 79 | if (count($attributes) > 0) { |
||
| 80 | $check['attributes'] = $attributes; |
||
| 81 | } |
||
| 82 | |||
| 83 | $checks[$result->getKey()] = $check; |
||
| 84 | |||
| 85 | if ($result->getStatus() == Result::STATUS_FAIL) { |
||
| 86 | $status = Result::STATUS_FAIL; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | $formattedResult['status'] = $status; |
||
| 91 | $formattedResult['output'] = $this->getOutput($status); |
||
| 92 | |||
| 93 | $formattedResult['checks'] = $checks; |
||
| 94 | |||
| 95 | $formattedResult['info'] = $this->getInfoBlock(); |
||
| 96 | |||
| 97 | return $formattedResult; |
||
| 98 | } |
||
| 130 |