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

Client::request()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 1
nop 1
crap 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
}