Code Duplication    Length = 36-36 lines in 2 locations

src/Debug/Dumper/Request/VarDumper.php 1 location

@@ 12-47 (lines=36) @@
9
use Behapi\Debug\Dumper;
10
use Behapi\Debug\Dumper\UnsupportedMessage;
11
12
final class VarDumper implements Dumper
13
{
14
    public function dump(MessageInterface $message, array $headers): void
15
    {
16
        if (!$this->supports($message)) {
17
            throw new UnsupportedMessage($message, RequestInterface::class);
18
        }
19
20
        // mandatory, clearing the line
21
        // todo : check how to clear without this echo...
22
        echo "\n";
23
24
        $dump = [
25
            'Request' => "{$message->getMethod()} {$message->getUri()}",
26
        ];
27
28
        foreach ($headers as $header) {
29
            $dump["Request {$header}"] = $message->getHeaderLine($header);
30
        }
31
32
        $body = (string) $message->getBody();
33
34
        if (!empty($body)) {
35
            $dump['Request Body'] = $body;
36
        }
37
38
        SfDumper::dump($dump);
39
    }
40
41
    public function supports(MessageInterface $message): bool
42
    {
43
        return class_exists(SfDumper::class)
44
            && $message instanceof RequestInterface
45
        ;
46
    }
47
}
48

src/Debug/Dumper/Response/VarDumper.php 1 location

@@ 12-47 (lines=36) @@
9
use Behapi\Debug\Dumper;
10
use Behapi\Debug\Dumper\UnsupportedMessage;
11
12
final class VarDumper implements Dumper
13
{
14
    public function dump(MessageInterface $message, array $headers): void
15
    {
16
        if (!$this->supports($message)) {
17
            throw new UnsupportedMessage($message, ResponseInterface::class);
18
        }
19
20
        // mandatory, clearing the line
21
        // todo : check how to clear without this echo...
22
        echo "\n";
23
24
        $dump = [
25
            'Response Status' => "{$message->getStatusCode()} {$message->getReasonPhrase()}",
26
        ];
27
28
        foreach ($headers as $header) {
29
            $dump["Response {$header}"] = $message->getHeaderLine($header);
30
        }
31
32
        $body = (string) $message->getBody();
33
34
        if (!empty($body)) {
35
            $dump['Response Body'] = $body;
36
        }
37
38
        SfDumper::dump($dump);
39
    }
40
41
    public function supports(MessageInterface $message): bool
42
    {
43
        return class_exists(SfDumper::class)
44
            && $message instanceof ResponseInterface
45
        ;
46
    }
47
}
48