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

Year::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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