Total Complexity | 6 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
10 | final class EchoerAdapter implements Adapter |
||
11 | { |
||
12 | // 1 - key |
||
13 | // 2 - value |
||
14 | private const TEMPLATE = "\033[36m| \033[1m%s : \033[0;36m%s\033[0m\n"; |
||
15 | |||
16 | /** @var iterable<string> */ |
||
17 | private $headers; |
||
18 | |||
19 | /** @param iterable<string> $headers */ |
||
20 | public function __construct(iterable $headers) |
||
23 | } |
||
24 | |||
25 | public function introspect(MessageInterface $message): void |
||
26 | { |
||
27 | if (!$this->supports($message)) { |
||
28 | throw new UnsupportedMessage($message, ResponseInterface::class); |
||
29 | } |
||
30 | |||
31 | assert($message instanceof ResponseInterface); |
||
32 | |||
33 | echo "\n"; |
||
34 | |||
35 | printf(self::TEMPLATE, 'Response status', "{$message->getStatusCode()} {$message->getReasonPhrase()}"); |
||
36 | |||
37 | foreach ($this->headers as $header) { |
||
38 | printf(self::TEMPLATE, "Response {$header}", $message->getHeaderLine($header)); |
||
39 | } |
||
40 | |||
41 | $body = (string) $message->getBody(); |
||
42 | |||
43 | if (!empty($body)) { |
||
44 | echo "\n{$body}"; |
||
45 | } |
||
46 | |||
47 | echo "\n"; |
||
48 | } |
||
49 | |||
50 | public function supports(MessageInterface $message): bool |
||
53 | } |
||
54 | } |
||
55 |