StrategyFactory::types()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Model\Toggle;
6
7
use Pheature\Core\Toggle\Exception\InvalidStrategyTypeGiven;
8
use Pheature\Core\Toggle\Read\Segments;
9
use Pheature\Core\Toggle\Read\ToggleStrategy;
10
use Pheature\Core\Toggle\Read\ToggleStrategyFactory;
11
12
final class StrategyFactory implements ToggleStrategyFactory
13
{
14 3
    public function create(string $strategyId, string $strategyType, ?Segments $segments = null): ToggleStrategy
15
    {
16 3
        $segments = $segments ?? new Segments();
17 3
        if (EnableByMatchingSegment::NAME === $strategyType) {
18 1
            return new EnableByMatchingSegment($strategyId, $segments);
19
        }
20 2
        if (EnableByMatchingIdentityId::NAME === $strategyType) {
21 1
            return new EnableByMatchingIdentityId($strategyId, $segments);
22
        }
23
24 1
        throw InvalidStrategyTypeGiven::withType($strategyType);
25
    }
26
27 1
    public function types(): array
28
    {
29
        return [
30 1
            EnableByMatchingSegment::NAME,
31
            EnableByMatchingIdentityId::NAME,
32
        ];
33
    }
34
}
35