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\Request;
3
4
use Psr\Http\Message\MessageInterface;
5
use Psr\Http\Message\RequestInterface;
6
7
use Behapi\Debug\Introspection;
8
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...
9
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...
10
11
final class EchoerAdapter implements Adapter
12
{
13
    // 1 - key
14
    // 2 - value
15
    private const TEMPLATE = "\033[36m| \033[1m%s : \033[0;36m%s\033[0m\n";
16
17
    public function dump(MessageInterface $message, array $headers): void
18
    {
19
        if (!$this->supports($message)) {
20
            throw new UnsupportedMessage($message, RequestInterface::class);
21
        }
22
23
        echo "\n";
24
25
        printf(self::TEMPLATE, 'Request', "{$message->getMethod()} {$message->getUri()}");
26
27
        foreach ($headers as $header) {
28
            printf(self::TEMPLATE, "Request {$header}", $message->getHeaderLine($header));
29
        }
30
31
        $body = (string) $message->getBody();
32
33
        if (!empty($body)) {
34
            echo "\n{$body}";
35
        }
36
37
        echo "\n";
38
    }
39
40
    public function supports(MessageInterface $message): bool
41
    {
42
        return $message instanceof RequestInterface;
43
    }
44
}
45