| Conditions | 5 |
| Paths | 9 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | 4 | public function handle(string $routeName, Crawler $crawler, Client $client, array $options = []): void |
|
| 16 | { |
||
| 17 | 4 | $expectedResponseCode = Response::HTTP_OK; |
|
| 18 | 4 | $configuration = $this->configuration[$routeName]['handlers'][$this->getName()]; |
|
| 19 | |||
| 20 | 4 | if (!is_array($configuration)) { |
|
| 21 | 4 | $expectedResponseCode = $configuration; |
|
| 22 | 1 | } elseif (key_exists('code', $configuration)) { |
|
| 23 | 1 | $expectedResponseCode = $configuration['code']; |
|
| 24 | } |
||
| 25 | |||
| 26 | 4 | if (null === $client->getResponse()) { |
|
| 27 | 1 | throw new Exception('The client has no response. It should make a request before handle a response'); |
|
| 28 | } |
||
| 29 | 3 | $responseCode = $client->getResponse()->getStatusCode(); |
|
| 30 | |||
| 31 | 3 | if ((string) $expectedResponseCode !== (string) $responseCode) { |
|
| 32 | 1 | throw new Exception('Excepted code '.$expectedResponseCode.', got '.$responseCode.' for route '.$routeName); |
|
| 33 | } |
||
| 44 |