Passed
Push — feature/VSVGVQ-7 ( ab245d...5131d3 )
by steven
05:54 queued 36s
created

Year   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A toNative() 0 3 1
A equals() 0 3 1
1
<?php
2
3
namespace VSV\GVQ_API\Question;
4
5
class Year
6
{
7
    /**
8
     * @var int
9
     */
10
    private $value;
11
12
    /**
13
     * @param int $value
14
     */
15
    public function __construct(int $value)
16
    {
17
        if ($value <= 2018 || $value >= 2099) {
18
            throw new \InvalidArgumentException(
19
                'Invalid value '.$value.' for year, value has to be above 2018 and below 2100'
20
            );
21
        }
22
23
        $this->value = $value;
24
    }
25
26
    /**
27
     * @return int
28
     */
29
    public function toNative(): int
30
    {
31
        return $this->value;
32
    }
33
34
    /**
35
     * @param Year $year
36
     * @return bool
37
     */
38
    public function equals(Year $year): bool
39
    {
40
        return $this->toNative() === $year->toNative();
41
    }
42
}
43