Completed
Push — master ( e17409...9d6c1e )
by Sergey
04:06
created

LoggerDecoratedIO::peek()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace ButterAMQP\Debug;
4
5
use ButterAMQP\IOInterface;
6
use Psr\Log\LoggerInterface;
7
8
class LoggerDecoratedIO implements IOInterface
9
{
10
    /**
11
     * @var IOInterface
12
     */
13
    private $io;
14
15
    /**
16
     * @var LoggerInterface
17
     */
18
    private $logger;
19
20
    /**
21
     * @param IOInterface     $io
22
     * @param LoggerInterface $logger
23
     */
24
    public function __construct(IOInterface $io, LoggerInterface $logger)
25
    {
26
        $this->io = $io;
27
        $this->logger = $logger;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function open($protocol, $host, $port, array $parameters = [])
34
    {
35
        $this->logger->debug(sprintf('Connecting to "%s://%s:%d"...', $protocol, $host, $port), [
36
            'protocol' => $protocol,
37
            'host' => $host,
38
            'port' => $port,
39
            'parameters' => $parameters,
40
        ]);
41
42
        return $this->io->open($protocol, $host, $port, $parameters);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function close()
49
    {
50
        $this->logger->debug('Closing connection');
51
52
        return $this->io->close();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function peek($length, $blocking = true)
59
    {
60
        return $this->io->peek($length, $blocking);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function read($length, $blocking = true)
67
    {
68
        $data = $this->io->read($length, $blocking);
69
70
        $this->logger->debug(new ReadableBinaryData('Reading', $data));
71
72
        return $data;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function write($data, $length = null)
79
    {
80
        $this->logger->debug(new ReadableBinaryData('Writing', $data));
81
82
        return $this->io->write($data, $length);
83
    }
84
}
85