Completed
Pull Request — master (#64)
by Frederik
03:38 queued 01:09
created

EhloResponse::__construct()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6.0163

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
rs 8.9297
c 0
b 0
f 0
cc 6
nc 6
nop 1
crap 6.0163
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Smtp\Response;
5
6
use Genkgo\Mail\Protocol\Smtp\Reply;
7
8
final class EhloResponse
9
{
10
    /**
11
     * @var string
12
     */
13
    private $greeting = '';
14
15
    /**
16
     * @var array<string, bool>
17
     */
18
    private $advertisements = [];
19
20
    /**
21
     * @param Reply $reply
22
     */
23 10
    public function __construct(Reply $reply)
24
    {
25 10
        $messages = $reply->getMessages();
26
27 10
        if (\count($messages) > 0) {
28 10
            $this->greeting = $messages[0];
29
30 10
            foreach (\array_slice($messages, 1) as $message) {
31 10
                $advertisement = \preg_split('/[\s]+/', $message);
32 10
                if ($advertisement === false) {
33
                    $advertisement = [];
34
                }
35
36 10
                if (\count($advertisement) > 1) {
37 9
                    foreach (\array_slice($advertisement, 1) as $command) {
38 9
                        $this->advertisements[$advertisement[0] . ' ' . $command] = true;
39
                    }
40
                } else {
41 7
                    $this->advertisements[$advertisement[0]] = true;
42
                }
43
            }
44
        }
45 10
    }
46
47
    /**
48
     * @param string $command
49
     * @return bool
50
     */
51 10
    public function isAdvertising(string $command)
52
    {
53 10
        if ($command === '') {
54 1
            return false;
55
        }
56
57 10
        return isset($this->advertisements[$command]);
58
    }
59
}
60