| Conditions | 14 |
| Paths | 1154 |
| Total Lines | 91 |
| Code Lines | 50 |
| 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 |
||
| 47 | public function handle(RunResult $runResult, $echoValue = true) |
||
| 48 | { |
||
| 49 | header('Content-Type: application/json'); |
||
| 50 | |||
| 51 | $output = $this->getOutput($runResult, $this->passMessage, $this->failMessage); |
||
| 52 | |||
| 53 | $details = []; |
||
| 54 | |||
| 55 | foreach ($runResult->getResults() as $resultArray) { |
||
| 56 | |||
| 57 | /** @var Result $result */ |
||
| 58 | $result = $resultArray['result']; |
||
| 59 | |||
| 60 | if ($this->dataProctection) { |
||
| 61 | $result = $this->comvertToDataProtectedResult($result); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** @var Check $check */ |
||
| 65 | $check = $resultArray['check']; |
||
| 66 | |||
| 67 | if (is_string($resultArray['identifier'])) { |
||
| 68 | $identifier = $resultArray['identifier']; |
||
| 69 | } else { |
||
| 70 | $identifier = $check->getIdentifier(); |
||
| 71 | } |
||
| 72 | |||
| 73 | $details[$identifier] = [ |
||
| 74 | 'status' => $result->getStatus(), |
||
| 75 | 'output' => $result->getMessage() |
||
| 76 | ]; |
||
| 77 | |||
| 78 | /** @var string $group */ |
||
| 79 | $group = $resultArray['group']; |
||
| 80 | |||
| 81 | if($group) { |
||
| 82 | $details[$identifier]['group'] = $group; |
||
| 83 | } |
||
| 84 | |||
| 85 | $description = $resultArray['description']; |
||
| 86 | if ($description) { |
||
| 87 | $details[$identifier]['description'] = $description; |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($result instanceof MetricAwareResult) { |
||
| 91 | $details[$identifier]["observedValue"] = $result->getMetricValue(); |
||
| 92 | $details[$identifier]["observedUnit"] = $result->getMetricUnit(); |
||
| 93 | |||
| 94 | if ($result->getMetricType()) { |
||
| 95 | $details[$identifier]['metricType'] = $result->getMetricType(); |
||
| 96 | } |
||
| 97 | |||
| 98 | if (!is_null($result->getObservedValuePrecision())) { |
||
| 99 | $details[$identifier]['observedValuePrecision'] = $result->getObservedValuePrecision(); |
||
| 100 | } |
||
| 101 | |||
| 102 | if (is_numeric($result->getLimit())) { |
||
| 103 | $details[$identifier]['limit'] = $result->getLimit(); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (!is_null($result->getLimitType())) { |
||
| 107 | $details[$identifier]['limitType'] = $result->getLimitType(); |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | if ($result->getStatus() == Result::STATUS_PASS) { |
||
| 111 | $details[$identifier]["observedValue"] = 1; |
||
| 112 | } else { |
||
| 113 | $details[$identifier]["observedValue"] = 0; |
||
| 114 | } |
||
| 115 | $details[$identifier]["metricType"] = MetricAwareResult::METRIC_TYPE_PERCENT; |
||
| 116 | $details[$identifier]["observedUnit"] = 'percent'; |
||
| 117 | } |
||
| 118 | |||
| 119 | $attributes = $result->getAttributes(); |
||
| 120 | if (count($attributes) > 0) { |
||
| 121 | $details[$identifier]['attributes'] = $attributes; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $resultArray = [ |
||
| 126 | 'status' => $runResult->getStatus(), |
||
| 127 | 'output' => $output, |
||
| 128 | 'checks' => $details |
||
| 129 | ]; |
||
| 130 | |||
| 131 | $resultJson = json_encode($resultArray, JSON_PRETTY_PRINT); |
||
| 132 | |||
| 133 | if ($echoValue) { |
||
| 134 | echo $resultJson; |
||
| 135 | } |
||
| 136 | |||
| 137 | return $resultArray; |
||
| 138 | } |
||
| 159 |