TransportChain   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addTransport() 0 4 1
A send() 0 6 2
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