Passed
Pull Request — master (#16)
by steven
04:56
created

PositiveNumber::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Company\ValueObjects;
4
5
class PositiveNumber
6
{
7
8
    /**
9
     * @var int
10
     */
11
    private $value;
12
13
    /**
14
     * @param int $value
15
     */
16
    public function __construct(int $value)
17
    {
18
        if ($value < 1) {
19
            throw new \InvalidArgumentException(
20
                'Value has to be greater than 0, '.$value.' given.'
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 PositiveNumber $positiveNumber
36
     * @return bool
37
     */
38
    public function equals(PositiveNumber $positiveNumber): bool
39
    {
40
        return $this->toNative() === $positiveNumber->toNative();
41
    }
42
}
43