Passed
Push — master ( b9ffdf...6f7a22 )
by Hirofumi
04:56
created

GatewayRegistry::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 4
cts 8
cp 0.5
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.5
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Domain\Model;
5
6
use InvalidArgumentException;
7
8
class GatewayRegistry
9
{
10
    /**
11
     * @var Gateway[]
12
     */
13
    protected $gateways = [];
14
15
    /**
16
     * @param Gateway $gateway
17
     */
18 1
    public function set(Gateway $gateway)
19
    {
20 1
        $this->gateways[$gateway->destinationType()] = $gateway;
21 1
    }
22
23
    /**
24
     * @param Destination $destination
25
     * @return Gateway
26
     */
27 1
    public function get(Destination $destination): Gateway
28
    {
29 1
        $destinationType = $destination->destinationType();
30 1
        if (!isset($this->gateways[$destinationType])) {
31
            new InvalidArgumentException(
32
                sprintf(
33
                    'No gateway for destination type (%s) is supported.',
34
                    $destinationType
35
                )
36
            );
37
        }
38
39 1
        return $this->gateways[$destinationType];
40
    }
41
}
42