Passed
Branch pretty-dump (f26c5c)
by Baptiste
02:47
created

Echoer::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\Dumper\Request;
3
4
use Psr\Http\Message\MessageInterface;
5
use Psr\Http\Message\RequestInterface;
6
7
use Behapi\Debug\Dumper;
8
use Behapi\Debug\Dumper\UnsupportedMessage;
9
10
final class Echoer implements Dumper
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, RequestInterface::class);
20
        }
21
22
        echo "\n";
23
24
        printf(self::TEMPLATE, 'Request', "{$message->getMethod()} {$message->getUri()}");
2 ignored issues
show
Bug introduced by
The method getUri() does not exist on Psr\Http\Message\MessageInterface. It seems like you code against a sub-type of Psr\Http\Message\MessageInterface such as Psr\Http\Message\RequestInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        printf(self::TEMPLATE, 'Request', "{$message->getMethod()} {$message->/** @scrutinizer ignore-call */ getUri()}");
Loading history...
Bug introduced by
The method getMethod() does not exist on Psr\Http\Message\MessageInterface. It seems like you code against a sub-type of Psr\Http\Message\MessageInterface such as Psr\Http\Message\RequestInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        printf(self::TEMPLATE, 'Request', "{$message->/** @scrutinizer ignore-call */ getMethod()} {$message->getUri()}");
Loading history...
25
26
        foreach ($headers as $header) {
27
            printf(self::TEMPLATE, "Request {$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 RequestInterface;
42
    }
43
}
44