Conditions | 11 |
Paths | 42 |
Total Lines | 50 |
Code Lines | 30 |
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 |
||
114 | private function sendCollectedResults() |
||
115 | { |
||
116 | $checks = []; |
||
117 | |||
118 | foreach ($this->results as $results) { |
||
119 | foreach ($results as $result) { |
||
|
|||
120 | /* @var CheckResult $result */ |
||
121 | $tool = 'Smoke' . $result->getRuleName(); |
||
122 | $checks[$tool][] = $result; |
||
123 | } |
||
124 | } |
||
125 | |||
126 | foreach ($checks as $toolName => $results) { |
||
127 | $attributes = array(); |
||
128 | |||
129 | if (count($results) === 0) { |
||
130 | continue; |
||
131 | } |
||
132 | |||
133 | $message = 'The smoke test for #system_name# failed (Rule: ' . $toolName . ').<ul>'; |
||
134 | $status = Event::STATUS_SUCCESS; |
||
135 | $failureCount = 0; |
||
136 | $identifier = $toolName . '_' . $this->system; |
||
137 | |||
138 | foreach ($results as $result) { |
||
139 | /** @var CheckResult $result */ |
||
140 | if ($result->getStatus() === CheckResult::STATUS_FAILURE) { |
||
141 | $comingFrom = ''; |
||
142 | if ($this->addComingFrom && $this->retriever->getComingFrom($result->getResponse()->getUri())) { |
||
143 | $comingFrom = ', coming from: ' . $this->retriever->getComingFrom($result->getResponse()->getUri()); |
||
144 | } |
||
145 | $message .= '<li>' . $result->getMessage() . ' (url: ' . (string)$result->getResponse()->getUri() . $comingFrom . ')</li>'; |
||
146 | ++$failureCount; |
||
147 | } |
||
148 | } |
||
149 | if ($failureCount > 0) { |
||
150 | $status = Event::STATUS_FAILURE; |
||
151 | $message .= '</ul>'; |
||
152 | $firstResult = array_pop($results); |
||
153 | if ($firstResult) { |
||
154 | $attributes[] = new Attribute('html-content', (string)$firstResult->getResponse()->getBody(), true); |
||
155 | } |
||
156 | } else { |
||
157 | $message = 'All checks for system "#system_name#" succeeded [SmokeBasic:' . $toolName . '].'; |
||
158 | } |
||
159 | |||
160 | |||
161 | $this->send($identifier, $this->system, $message, $status, $failureCount, $this->tool, $this->system, $attributes); |
||
162 | } |
||
163 | } |
||
164 | |||
222 |