EmailBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace JDR\Mailer;
4
5
use JDR\Mailer\Email\Email;
6
use JDR\Mailer\Part\EmailPart;
7
8
class EmailBuilder
9
{
10
    /**
11
     * @var PartResolverRegistry
12
     */
13
    private $registry;
14
15
    /**
16
     * @var EmailPart[]
17
     */
18
    private $parts;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param PartResolverRegistry $registry
24
     */
25 2
    public function __construct(PartResolverRegistry $registry)
26
    {
27 2
        $this->registry = $registry;
28 2
    }
29
30
    /**
31
     * Add part to email.
32
     *
33
     * @param EmailPart $part
34
     *
35
     * @return self
36
     */
37 2
    public function add(EmailPart $part): self
38
    {
39 2
        $this->parts[] = $part;
40
41 2
        return $this;
42
    }
43
44
    /**
45
     * Build email from parts.
46
     *
47
     * @param Email $email
48
     *
49
     * @return Email
50
     */
51 1
    public function build(Email $email): Email
52
    {
53 1
        foreach ($this->parts as $part) {
54 1
            $resolver = $this->registry->getResolverForPart($part);
55 1
            $resolver->addPart($email, $part);
56
        }
57
58 1
        $this->parts = [];
59
60 1
        return $email;
61
    }
62
}
63