Recipients   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A add() 0 18 4
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
    /**
29
     * Instantiate a Recipients object.
30
     *
31
     * @param array $emails Array of email addresses and/or recipients.
32
     */
33 8
    public function __construct(array $emails)
34
    {
35 8
        parent::__construct([]);
36 8
        $this->add($emails);
37 8
    }
38
39
    /**
40
     * Add an email address to the Recipients collection.
41
     *
42
     * @param Recipients|EmailAddress|array|string $email Email address to add.
43
     *
44
     * @return static
45
     */
46 8
    public function add($email)
47
    {
48 8
        if ($email instanceof EmailAddress) {
49 6
            parent::add($email);
50
51 6
            return $this;
52
        }
53
54 8
        if (is_array($email) || $email instanceof Recipients) {
55 8
            array_walk($email, [$this, 'add']);
56
57 8
            return $this;
58
        }
59
60 5
        parent::add(new EmailAddress($email));
61
62 5
        return $this;
63
    }
64
}