Cancelled
Pull Request — master (#46)
by Baptiste
02:34
created

EchoerAdapter::dump()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 5
nop 2
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
namespace Behapi\Debug\Introspection\Response;
3
4
use Psr\Http\Message\MessageInterface;
5
use Psr\Http\Message\ResponseInterface;
6
7
use Behapi\Debug\Introspection\Adapter;
0 ignored issues
show
Bug introduced by
The type Behapi\Debug\Introspection\Adapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Behapi\Debug\Introspection\UnsupportedMessage;
0 ignored issues
show
Bug introduced by
The type Behapi\Debug\Introspection\UnsupportedMessage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
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
    public function dump(MessageInterface $message, array $headers): void
17
    {
18
        if (!$this->supports($message)) {
19
            throw new UnsupportedMessage($message, ResponseInterface::class);
20
        }
21
22
        echo "\n";
23
24
        printf(self::TEMPLATE, 'Response status', "{$message->getStatusCode()} {$message->getReasonPhrase()}");
25
26
        foreach ($headers as $header) {
27
            printf(self::TEMPLATE, "Response {$header}", $message->getHeaderLine($header));
28
        }
29
30
        $body = (string) $message->getBody();
31
32
        if (!empty($body)) {
33
            echo "\n{$body}";
34
        }
35
36
        echo "\n";
37
    }
38
39
    public function supports(MessageInterface $message): bool
40
    {
41
        return $message instanceof ResponseInterface;
42
    }
43
}
44