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

EhloResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 20 5
A isAdvertising() 0 8 2
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
     * @var array
16
     */
17
    private $advertisements = [];
18
19
    /**
20
     * EhloResponse constructor.
21
     * @param Reply $reply
22
     */
23 8
    public function __construct(Reply $reply)
24
    {
25 8
        $messages = $reply->getMessages();
26
27 8
        if (count($messages) > 0) {
28 8
            $this->greeting = $messages[0];
29
30 8
            foreach (array_slice($messages, 1) as $message) {
31 4
                $advertisement = preg_split('/[\s]+/', $message);
32
33 4
                if (count($advertisement) > 1) {
34 2
                    foreach (array_slice($advertisement, 1) as $command) {
35 2
                        $this->advertisements[$advertisement[0] . ' ' . $command] = true;
36
                    }
37
                } else {
38 2
                    $this->advertisements[$advertisement[0]] = true;
39
                }
40
            }
41
        }
42 8
    }
43
44
    /**
45
     * @param string $command
46
     * @return bool
47
     */
48 8
    public function isAdvertising(string $command)
49
    {
50 8
        if ($command === '') {
51 1
            return false;
52
        }
53
54 8
        return isset($this->advertisements[$command]);
55
    }
56
}