Passed
Push — master ( fd4f11...882af9 )
by Nico
25:47
created

TransferStrategyProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getTransferStrategy() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Transfer\Strategy;
6
7
use RuntimeException;
8
use Stu\Lib\Transfer\TransferTypeEnum;
9
10
class TransferStrategyProvider implements TransferStrategyProviderInterface
11
{
12
    /** @param array<TransferStrategyInterface> $transferStrategies */
13 2
    public function __construct(
14
        private array $transferStrategies
15 2
    ) {}
16
17 2
    public function getTransferStrategy(TransferTypeEnum $type): TransferStrategyInterface
18
    {
19 2
        if (!array_key_exists($type->value, $this->transferStrategies)) {
20 1
            throw new RuntimeException(sprintf('transfer strategy with typeValue %d does not exist', $type->value));
21
        }
22
23 1
        return $this->transferStrategies[$type->value];
24
    }
25
}
26