Passed
Push — master ( 4633d8...be0c82 )
by Alain
02:10
created

Recipients   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A add() 0 6 1
1
<?php
2
/**
3
 * BrightNucleus Chainmail Component.
4
 *
5
 * @package   BrightNucleus/Chainmail
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   MIT
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\ChainMail;
13
14
use BrightNucleus\ChainMail\Support\EmailAddress;
15
use Doctrine\Common\Collections\ArrayCollection;
16
17
/**
18
 * Class Recipients.
19
 *
20
 * @since   1.0.0
21
 *
22
 * @package BrightNucleus\ChainMail
23
 * @author  Alain Schlesser <[email protected]>
24
 */
25
class Recipients extends ArrayCollection
26
{
27
28
    public function __construct(array $emails)
29
    {
30
        parent::__construct(array_filter(
31
            array_map(function ($value) {
32
                if ($value instanceof EmailAddress) {
33
                    return $value;
34
                }
35
36
                return new EmailAddress($value);
37
            }, $emails)
38
        ));
39
    }
40
41
    /**
42
     * Add an email address to the Recipients collection.
43
     *
44
     * @param mixed $email Email address to add.
45
     *
46
     * @return static
47
     */
48
    public function add($email)
49
    {
50
        parent::add(new EmailAddress($email));
51
52
        return $this;
53
    }
54
}