Completed
Pull Request — master (#42)
by Frederik
03:52
created

DataLogConnection::upgrade()   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
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol;
5
6
use Psr\Log\LoggerInterface;
7
8
final class DataLogConnection implements ConnectionInterface
9
{
10
11
    /**
12
     * @var ConnectionInterface
13
     */
14
    private $decoratedConnection;
15
    /**
16
     * @var LoggerInterface
17
     */
18
    private $logger;
19
20
    /**
21
     * LogConnection constructor.
22
     * @param ConnectionInterface $decoratedConnection
23
     * @param LoggerInterface $logger
24
     */
25
    public function __construct(ConnectionInterface $decoratedConnection, LoggerInterface $logger)
26
    {
27
        $this->decoratedConnection = $decoratedConnection;
28
        $this->logger = $logger;
29
    }
30
31
    /**
32
     * @param string $name
33
     * @param \Closure $callback
34
     */
35
    public function addListener(string $name, \Closure $callback): void
36
    {
37
        $this->decoratedConnection->addListener($name, $callback);
38
    }
39
40
    /**
41
     * @return void
42
     */
43
    public function connect(): void
44
    {
45
        $this->decoratedConnection->connect();
46
    }
47
48
    /**
49
     * @return void
50
     */
51
    public function disconnect(): void
52
    {
53
        $this->decoratedConnection->disconnect();
54
    }
55
56
    /**
57
     * @param string $request
58
     * @return int
59
     */
60
    public function send(string $request): int
61
    {
62
        $this->logger->info('-> ' . $request);
63
        return $this->decoratedConnection->send($request);
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function receive(): string
70
    {
71
        $data = $this->decoratedConnection->receive();
72
        $this->logger->info('<- ' . $data);
73
        return $data;
74
    }
75
76
    /**
77
     * @param int $type
78
     */
79
    public function upgrade(int $type): void
80
    {
81
        $this->decoratedConnection->upgrade($type);
82
    }
83
84
    /**
85
     * @param float $timeout
86
     */
87
    public function timeout(float $timeout): void
88
    {
89
        $this->decoratedConnection->timeout($timeout);
90
    }
91
92
    /**
93
     * @param array $keys
94
     * @return array
95
     */
96
    public function getMetaData(array $keys = []): array
97
    {
98
        return $this->decoratedConnection->getMetaData($keys);
99
    }
100
}