Completed
Push — master ( 5840b0...fcc03f )
by Frederik
04:51
created

ArrayBackend   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 56
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A contains() 0 4 1
A store() 0 16 4
1
<?php
2
3
namespace Genkgo\Mail\Protocol\Smtp\Backend;
4
5
use Genkgo\Mail\EmailAddress;
6
use Genkgo\Mail\MessageInterface;
7
use Genkgo\Mail\Protocol\Smtp\BackendInterface;
8
9
final class ArrayBackend implements BackendInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $addresses;
15
    /**
16
     * @var \ArrayAccess
17
     */
18
    private $backend;
19
20
    /**
21
     * ArrayBackend constructor.
22
     * @param array $addresses
23
     * @param \ArrayAccess $backend
24
     */
25 13
    public function __construct(array $addresses, \ArrayAccess $backend)
26
    {
27 13
        $this->addresses = array_combine(
28 13
            $addresses,
29 13
            array_fill(0, count($addresses), true)
30
        );
31 13
        $this->backend = $backend;
32 13
    }
33
34
    /**
35
     * @param EmailAddress $mailbox
36
     * @return bool
37
     */
38 3
    public function contains(EmailAddress $mailbox): bool
39
    {
40 3
        return isset($this->addresses[(string)$mailbox]);
41
    }
42
43
    /**
44
     * @param EmailAddress $mailbox
45
     * @param MessageInterface $message
46
     * @param string $folder
47
     */
48 3
    public function store(EmailAddress $mailbox, MessageInterface $message, string $folder): void
49
    {
50 3
        if (!isset($this->addresses[(string)$mailbox])) {
51 1
            throw new \UnexpectedValueException('Unknown mailbox');
52
        }
53
54 2
        if (!isset($this->backend[(string)$mailbox])) {
55 2
            $this->backend[(string)$mailbox] = [];
56
        }
57
58 2
        if (!isset($this->backend[(string)$mailbox][$folder])) {
59 2
            $this->backend[(string)$mailbox][$folder] = [];
60
        }
61
62 2
        $this->backend[(string)$mailbox][$folder][] = $message;
63
    }
64
}