Completed
Push — master ( a33098...401d22 )
by Johan de
03:55
created

EmailBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 6 1
A build() 0 9 2
1
<?php declare(strict_types = 1);
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 1.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
        return $email;
59
    }
60
}
61