TransportChain::addTransport()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Communicator (https://github.com/waltertamboer/communicator)
4
 *
5
 * @link https://github.com/waltertamboer/communicator for the canonical source repository
6
 * @copyright Copyright (c) 2017 Communicator (https://github.com/waltertamboer/communicator)
7
 * @license https://github.com/waltertamboer/communicator/blob/master/LICENSE.md MIT
8
 */
9
10
namespace Communicator\Transport;
11
12
use Communicator\Message;
13
14
/**
15
 * The transport chain will send a notification to all instances in the chain.
16
 */
17
class TransportChain implements TransportInterface
18
{
19
    /**
20
     * @var TransportInterface[]
21
     */
22
    private $chain;
23
24
    /**
25
     * Initializes a new instance of this class.
26
     */
27
    public function __construct()
28
    {
29
        $this->chain = [];
30
    }
31
32
    /**
33
     * Adds the given transport to the chain.
34
     *
35
     * @param TransportInterface $transport The transport to add.
36
     */
37
    public function addTransport(TransportInterface $transport): void
38
    {
39
        $this->chain[] = $transport;
40
    }
41
42
    /**
43
     * Sends the message.
44
     *
45
     * @param array $recipients A list with all recipients that should receive the message.
46
     * @param Message $message The message to send.
47
     * @return void
48
     */
49
    public function send(array $recipients, Message $message): void
50
    {
51
        foreach ($this->chain as $transport) {
52
            $transport->send($recipients, $message);
53
        }
54
    }
55
}
56