| Conditions | 5 |
| Paths | 5 |
| Total Lines | 31 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | public function getHealth(array $checks) |
||
| 17 | { |
||
| 18 | $health = new Health(); |
||
| 19 | $health->setState(HealthCheck::STATE_UP); |
||
| 20 | |||
| 21 | foreach ($checks as $check) { |
||
| 22 | $class = $check['class'] ?? null; |
||
| 23 | $params = $check['params'] ?? []; |
||
| 24 | |||
| 25 | if (! $class || ! class_exists($class)) { |
||
| 26 | |||
| 27 | /** @var Health\Checks\HealthCheckInterface $healthCheck */ |
||
| 28 | $healthCheck = new ErrorCheck([ |
||
| 29 | 'message' => 'Health Check configuration error. Missing check class. - ' . $class |
||
| 30 | ]); |
||
| 31 | $checkResponse = $healthCheck->call(); |
||
| 32 | } else { |
||
| 33 | |||
| 34 | /** @var Health\Checks\HealthCheckInterface $healthCheck */ |
||
| 35 | $healthCheck = new $class($params); |
||
| 36 | $checkResponse = $healthCheck->call(); |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($checkResponse->getState() !== HealthCheck::STATE_UP) { |
||
| 40 | $health->setState(HealthCheck::STATE_DOWN); |
||
| 41 | } |
||
| 42 | |||
| 43 | $health->setCheck($checkResponse); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $health; |
||
| 47 | } |
||
| 49 |