Completed
Push — master ( e8b19e...87df92 )
by Andrew
02:42
created

Entry::fromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KRDigital\NamesDetector\Entry;
6
7
use KRDigital\NamesDetector\Exception\InvalidEntryInputDataException;
8
9
class Entry
10
{
11
    /**
12
     * @var Type
13
     */
14
    protected $type;
15
16
    /**
17
     * @var Gender
18
     */
19
    protected $gender;
20
21
    /**
22
     * @var string
23
     */
24
    protected $value;
25
26 3
    protected function __construct(Type $type, Gender $gender, string $value)
27
    {
28 3
        $this->type = $type;
29 3
        $this->gender = $gender;
30 3
        $this->value = $value;
31 3
    }
32
33 4
    public static function fromArray(array $data): self
34
    {
35 4
        if ($diff = \array_diff(['type', 'gender', 'value'], \array_keys($data))) {
36 1
            throw new InvalidEntryInputDataException('Input entry keys missing', $diff);
37
        }
38
39 3
        return new static(new Type($data['type']), new Gender($data['gender']), $data['value']);
40
    }
41
42 1
    public function getType(): Type
43
    {
44 1
        return $this->type;
45
    }
46
47 1
    public function getGender(): Gender
48
    {
49 1
        return $this->gender;
50
    }
51
52 1
    public function getValue(): string
53
    {
54 1
        return $this->value;
55
    }
56
}
57