Conditions | 11 |
Paths | 145 |
Total Lines | 74 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
31 | public function handle(RunResult $runResult) |
||
32 | { |
||
33 | header('Content-Type: application/json'); |
||
34 | |||
35 | $output = $this->getOutput($runResult, $this->passMessage, $this->failMessage); |
||
36 | |||
37 | $details = []; |
||
38 | |||
39 | foreach ($runResult->getResults() as $resultArray) { |
||
40 | /** @var Result $result */ |
||
41 | $result = $resultArray['result']; |
||
42 | |||
43 | /** @var Check $check */ |
||
44 | $check = $resultArray['check']; |
||
45 | |||
46 | |||
47 | if (is_string($resultArray['identifier'])) { |
||
48 | $identifier = $resultArray['identifier']; |
||
49 | } else { |
||
50 | $identifier = $check->getIdentifier(); |
||
51 | } |
||
52 | |||
53 | $details[$identifier] = [ |
||
54 | 'status' => $result->getStatus(), |
||
55 | 'output' => $result->getMessage() |
||
56 | ]; |
||
57 | |||
58 | $description = $resultArray['description']; |
||
59 | if ($description) { |
||
60 | $details[$identifier]['description'] = $description; |
||
61 | } |
||
62 | |||
63 | if ($result instanceof MetricAwareResult) { |
||
64 | $details[$identifier]["observedValue"] = $result->getMetricValue(); |
||
65 | $details[$identifier]["observedUnit"] = $result->getMetricUnit(); |
||
66 | |||
67 | if ($result->getMetricType()) { |
||
68 | $details[$identifier]['metricType'] = $result->getMetricType(); |
||
69 | } |
||
70 | |||
71 | if (!is_null($result->getObservedValuePrecision())) { |
||
72 | $details[$identifier]['observedValuePrecision'] = $result->getObservedValuePrecision(); |
||
73 | } |
||
74 | |||
75 | if (is_numeric($result->getLimit())) { |
||
76 | $details[$identifier]['limit'] = $result->getLimit(); |
||
77 | } |
||
78 | |||
79 | if (!is_null($result->getLimitType())) { |
||
80 | $details[$identifier]['limitType'] = $result->getLimitType(); |
||
81 | } |
||
82 | } else { |
||
83 | if ($result->getStatus() == Result::STATUS_PASS) { |
||
84 | $details[$identifier]["observedValue"] = 1; |
||
85 | } else { |
||
86 | $details[$identifier]["observedValue"] = 0; |
||
87 | } |
||
88 | $details[$identifier]["metricType"] = MetricAwareResult::METRIC_TYPE_PERCENT; |
||
89 | $details[$identifier]["observedUnit"] = 'percent'; |
||
90 | } |
||
91 | |||
92 | $attributes = $result->getAttributes(); |
||
93 | if (count($attributes) > 0) { |
||
94 | $details['attributes'] = $attributes; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | $resultArray = [ |
||
99 | 'status' => $runResult->getStatus(), |
||
100 | 'output' => $output, |
||
101 | 'checks' => $details |
||
102 | ]; |
||
103 | |||
104 | echo json_encode($resultArray, JSON_PRETTY_PRINT); |
||
105 | } |
||
126 |