EmailBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 55
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 6 1
A build() 0 11 2
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