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

GatewayRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
ccs 7
cts 11
cp 0.6364
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
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