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

GatewayRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 4 1
A get() 0 14 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