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

Recipients::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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
}