RcptToCapability   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 46
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A manifest() 0 17 3
A advertise() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Smtp\Capability;
5
6
use Genkgo\Mail\EmailAddress;
7
use Genkgo\Mail\Protocol\ConnectionInterface;
8
use Genkgo\Mail\Protocol\Smtp\BackendInterface;
9
use Genkgo\Mail\Protocol\Smtp\CapabilityInterface;
10
use Genkgo\Mail\Protocol\Smtp\Session;
11
12
final class RcptToCapability implements CapabilityInterface
13
{
14
    /**
15
     * @var BackendInterface
16
     */
17
    private $backend;
18
19
    /**
20
     * @param BackendInterface $backend
21
     */
22 4
    public function __construct(BackendInterface $backend)
23
    {
24 4
        $this->backend = $backend;
25 4
    }
26
27
    /**
28
     * @param ConnectionInterface $connection
29
     * @param Session $session
30
     * @return Session
31
     */
32 3
    public function manifest(ConnectionInterface $connection, Session $session): Session
33
    {
34
        try {
35 3
            $address = new EmailAddress(\substr($session->getCommand(), 9, -1));
36
37 2
            if ($this->backend->contains($address) === false) {
38 1
                $connection->send('550 Unknown mailbox');
39 1
                return $session;
40
            }
41
42 1
            $connection->send('250 OK');
43 1
            return $session->withRecipient($address);
44 1
        } catch (\InvalidArgumentException $e) {
45 1
            $connection->send('501 Invalid recipient');
46 1
            return $session;
47
        }
48
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function advertise(): string
54
    {
55 1
        return 'RCPT TO';
56
    }
57
}
58