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

DataRequest::execute()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 11
cts 11
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 4
nop 1
crap 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Smtp\Request;
5
6
use Genkgo\Mail\Protocol\ConnectionInterface;
7
use Genkgo\Mail\Protocol\Smtp\RequestInterface;
8
use Genkgo\Mail\StreamInterface;
9
10
final class DataRequest implements RequestInterface
11
{
12
    /**
13
     * @var StreamInterface
14
     */
15
    private $stream;
16
17
    /**
18
     * DataRequest constructor.
19
     * @param StreamInterface $stream
20
     */
21 5
    public function __construct(StreamInterface $stream)
22
    {
23 5
        $this->stream = $stream;
24 5
    }
25
26
    /**
27
     * @param ConnectionInterface $connection
28
     * @return void
29
     */
30 5
    public function execute(ConnectionInterface $connection)
31
    {
32 5
        while (!$this->stream->eof()) {
33 5
            $bytes = $this->stream->read(1000);
34 5
            $lines = explode("\r\n", $bytes);
35 5
            foreach ($lines as $line) {
36 5
                $line = rtrim($line, "\r");
37 5
                if (isset($line[0]) && $line[0] === '.') {
38 1
                    $line = '.' . $line;
39
                }
40
41 5
                $connection->send($line . "\r\n");
42
            }
43
        }
44
45 5
        $connection->send(".\r\n");
46
    }
47
}