Passed
Push — 1.0.x ( 6cfe9a...16fd64 )
by Koldo
02:42
created

SegmentFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
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 as ISegment;
9
use Pheature\Core\Toggle\Read\SegmentFactory as ISegmentFactory;
10
11
final class SegmentFactory implements ISegmentFactory
12
{
13 3
    public function create(string $segmentId, string $segmentType, array $payload): ISegment
14
    {
15 3
        if (Segment::NAME === $segmentType) {
16 1
            return new Segment($segmentId, $payload);
17
        }
18 2
        if (IdentitySegment::NAME === $segmentType) {
19 1
            return new IdentitySegment($segmentId, $payload);
20
        }
21
22 1
        throw InvalidSegmentTypeGiven::withType($segmentType);
23
    }
24
25 1
    public function types(): array
26
    {
27
        return [
28 1
            Segment::NAME,
29
            IdentitySegment::NAME,
30
        ];
31
    }
32
}
33