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

SegmentFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 3
A types() 0 5 1
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