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

TransferStrategyProvider::getTransferStrategy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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