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

PositiveNumber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 3 1
A __construct() 0 8 2
A toNative() 0 3 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