Completed
Push — master ( 3ff097...503b9d )
by Frederik
06:54
created

Client   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A request() 0 13 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Smtp;
5
6
use Genkgo\Mail\Protocol\ConnectionInterface;
7
8
final class Client
9
{
10
    /**
11
     * @var ConnectionInterface
12
     */
13
    private $connection;
14
15
    /**
16
     * Client constructor.
17
     * @param ConnectionInterface $connection
18
     */
19 18
    public function __construct(ConnectionInterface $connection)
20
    {
21 18
        $this->connection = $connection;
22 18
    }
23
24
    /**
25
     * @param RequestInterface $command
26
     * @return Reply
27
     */
28 9
    public function request(RequestInterface $command): Reply
29
    {
30 9
        $command->execute($this->connection);
31
32 9
        $reply = new Reply($this);
33
        do {
34 9
            $line = $this->connection->receive();
35 9
            list($code, $more, $message) = preg_split('/([\s-]+)/', $line,2,PREG_SPLIT_DELIM_CAPTURE);
36 9
            $reply = $reply->withLine((int)$code, trim($message));
37 9
        } while (strpos($more, '-') === 0);
38
39 9
        return $reply;
40
    }
41
}