SegmentFactory::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 2
b 0
f 0
nc 4
nop 3
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Model\Toggle;
6
7
use Pheature\Core\Toggle\Exception\InvalidSegmentTypeGiven;
8
use Pheature\Core\Toggle\Read\Segment;
9
use Pheature\Core\Toggle\Read\SegmentFactory as ISegmentFactory;
10
11
final class SegmentFactory implements ISegmentFactory
12
{
13 4
    public function create(string $segmentId, string $segmentType, array $criteria): Segment
14
    {
15 4
        if (StrictMatchingSegment::NAME === $segmentType) {
16 1
            return new StrictMatchingSegment($segmentId, $criteria);
17
        }
18 3
        if (IdentitySegment::NAME === $segmentType) {
19 1
            return new IdentitySegment($segmentId, $criteria);
20
        }
21 2
        if (InCollectionMatchingSegment::NAME === $segmentType) {
22 1
            return new InCollectionMatchingSegment($segmentId, $criteria);
23
        }
24
25 1
        throw InvalidSegmentTypeGiven::withType($segmentType);
26
    }
27
28 1
    public function types(): array
29
    {
30
        return [
31 1
            StrictMatchingSegment::NAME,
32
            IdentitySegment::NAME,
33
            InCollectionMatchingSegment::NAME,
34
        ];
35
    }
36
}
37