Passed
Push — master ( dd3a40...b9ffdf )
by Hirofumi
07:38
created

GatewayRegistry::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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