Source::buildFromArray()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CompoLab\Domain;
4
5
use CompoLab\Domain\Type\Factory;
6
use CompoLab\Domain\Type\Git;
7
use CompoLab\Domain\Type\Type;
8
use CompoLab\Domain\Utils\JsonConvertible;
9
use CompoLab\Domain\Utils\JsonConvertibleTrait;
10
use CompoLab\Domain\ValueObject\Reference;
11
use CompoLab\Domain\ValueObject\Url;
12
13
final class Source implements JsonConvertible
14
{
15
    use JsonConvertibleTrait;
16
17
    /** @var Type */
18
    private $type;
19
20
    /** @var Url */
21
    private $url;
22
23
    /** @var Reference */
24
    private $reference;
25
26 7
    public function __construct(Type $type, Url $url, Reference $reference)
27
    {
28 7
        $this->type = $type;
29 7
        $this->url = $url;
30 7
        $this->reference = $reference;
31 7
    }
32
33 6
    public static function buildFromArray(array $data): self
34
    {
35 6
        return new self(
36 6
            isset($data['type']) ? Factory::buildFromString($data['type']) : new Git,
37 6
            new Url($data['url']),
38 6
            new Reference($data['reference'])
39
        );
40
    }
41
}
42