Passed
Push — master ( b9ffdf...6f7a22 )
by Hirofumi
04:56
created

EmailDestination::toObjectArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Domain\Model;
5
6
use Tanigami\ValueObjects\Web\EmailAddress;
7
8
class EmailDestination implements Destination
9
{
10
    /**
11
     * @var string[]
12
     */
13
    private $to;
14
15
    /**
16
     * @var string[]
17
     */
18
    private $cc;
19
20
    /**
21
     * @var string[]
22
     */
23
    private $bcc;
24
25
    /**
26
     * @param EmailAddress[] $to
27
     * @param EmailAddress[] $cc
28
     * @param EmailAddress[] $bcc
29
     */
30 7
    public function __construct(array $to, array $cc = [], array $bcc = [])
31
    {
32 7
        $this->to = $this->toStringArray($to);
33 7
        $this->cc = $this->toStringArray($cc);
34 7
        $this->bcc = $this->toStringArray($bcc);
35 7
    }
36
37
    /**
38
     * @return EmailAddress[]
39
     */
40 2
    public function to(): array
41
    {
42 2
        return $this->toObjectArray($this->to);
43
    }
44
45
    /**
46
     * @return EmailAddress[]
47
     */
48 2
    public function cc(): array
49
    {
50 2
        return $this->toObjectArray($this->cc);
51
    }
52
53
    /**
54
     * @return EmailAddress[]
55
     */
56 2
    public function bcc(): array
57
    {
58 2
        return $this->toObjectArray($this->bcc);
59
    }
60
61
    /**
62
     * @param EmailAddress[] $emailAddresses
63
     * @return string[[
0 ignored issues
show
Documentation introduced by
The doc-type string[[ could not be parsed: Expected "]" at position 2, but found "". [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
64
     */
65 7
    private function toStringArray(array $emailAddresses)
66
    {
67
        return array_map(function (EmailAddress $emailAddress) {
68 7
            return $emailAddress->emailAddress();
69 7
        }, $emailAddresses);
70
    }
71
72
    /**
73
     * @param string[] $emailAddresses
74
     * @return EmailAddress[]
75
     */
76 2
    private function toObjectArray(array $emailAddresses): array
77
    {
78
        return array_map(function (string $emailAddress) {
79 2
            return new EmailAddress($emailAddress);
80 2
        }, $emailAddresses);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 3
    public function destinationType(): string
87
    {
88 3
        return get_class($this);
89
    }
90
}
91