| Conditions | 5 |
| Paths | 13 |
| Total Lines | 32 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | public function call() |
||
| 24 | { |
||
| 25 | $builder = $this->getBuilder(); |
||
| 26 | |||
| 27 | try { |
||
| 28 | $uri = $this->getUri(); |
||
| 29 | |||
| 30 | /** @var \Psr\Http\Message\ResponseInterface $response */ |
||
| 31 | $response = $this->getHttpClient()->get($uri); |
||
| 32 | |||
| 33 | $statusCode = $response->getStatusCode(); |
||
| 34 | $status = ''; |
||
| 35 | |||
| 36 | if ($response->getStatusCode() == 200) { |
||
| 37 | $response = json_decode($response->getBody()->getContents()); |
||
| 38 | $status = $response->status ?? 'n/a'; |
||
| 39 | |||
| 40 | if ($status == 'green' || $status == 'yellow') { |
||
| 41 | $builder->up(); |
||
| 42 | } else { |
||
| 43 | $builder->down(); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | $builder->withData('uri', $uri) |
||
| 48 | ->withData('status', $status) |
||
| 49 | ->withData('http_status', $statusCode); |
||
| 50 | } catch (\Exception $exception) { |
||
| 51 | $builder->down()->withData('error', $exception->getMessage()); |
||
| 52 | } |
||
| 53 | |||
| 54 | return $builder->build(); |
||
| 55 | } |
||
| 70 |