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

Entry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 13
c 1
b 0
f 1
dl 0
loc 46
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A fromArray() 0 7 2
A __construct() 0 5 1
A getType() 0 3 1
A getGender() 0 3 1
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