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

EhloResponse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 52
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 6
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
    /**
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