Conditions | 13 |
Paths | 578 |
Total Lines | 85 |
Code Lines | 47 |
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 | |||
68 | if (is_string($resultArray['identifier'])) { |
||
69 | $identifier = $resultArray['identifier']; |
||
70 | } else { |
||
71 | $identifier = $check->getIdentifier(); |
||
72 | } |
||
73 | |||
74 | $details[$identifier] = [ |
||
75 | 'status' => $result->getStatus(), |
||
76 | 'output' => $result->getMessage() |
||
77 | ]; |
||
78 | |||
79 | $description = $resultArray['description']; |
||
80 | if ($description) { |
||
81 | $details[$identifier]['description'] = $description; |
||
82 | } |
||
83 | |||
84 | if ($result instanceof MetricAwareResult) { |
||
85 | $details[$identifier]["observedValue"] = $result->getMetricValue(); |
||
86 | $details[$identifier]["observedUnit"] = $result->getMetricUnit(); |
||
87 | |||
88 | if ($result->getMetricType()) { |
||
89 | $details[$identifier]['metricType'] = $result->getMetricType(); |
||
90 | } |
||
91 | |||
92 | if (!is_null($result->getObservedValuePrecision())) { |
||
93 | $details[$identifier]['observedValuePrecision'] = $result->getObservedValuePrecision(); |
||
94 | } |
||
95 | |||
96 | if (is_numeric($result->getLimit())) { |
||
97 | $details[$identifier]['limit'] = $result->getLimit(); |
||
98 | } |
||
99 | |||
100 | if (!is_null($result->getLimitType())) { |
||
101 | $details[$identifier]['limitType'] = $result->getLimitType(); |
||
102 | } |
||
103 | } else { |
||
104 | if ($result->getStatus() == Result::STATUS_PASS) { |
||
105 | $details[$identifier]["observedValue"] = 1; |
||
106 | } else { |
||
107 | $details[$identifier]["observedValue"] = 0; |
||
108 | } |
||
109 | $details[$identifier]["metricType"] = MetricAwareResult::METRIC_TYPE_PERCENT; |
||
110 | $details[$identifier]["observedUnit"] = 'percent'; |
||
111 | } |
||
112 | |||
113 | $attributes = $result->getAttributes(); |
||
114 | if (count($attributes) > 0) { |
||
115 | $details['attributes'] = $attributes; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | $resultArray = [ |
||
120 | 'status' => $runResult->getStatus(), |
||
121 | 'output' => $output, |
||
122 | 'checks' => $details |
||
123 | ]; |
||
124 | |||
125 | $resultJson = json_encode($resultArray, JSON_PRETTY_PRINT); |
||
126 | |||
127 | if ($echoValue) { |
||
128 | echo $resultJson; |
||
129 | } |
||
130 | |||
131 | return $resultArray; |
||
132 | } |
||
153 |