StrategyFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 3
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
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