Passed
Push — master ( f05eff...e96706 )
by Paweł
02:59
created

IntegerValue   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 61
ccs 26
cts 26
cp 1
rs 10
c 2
b 0
f 0
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A equals() 0 3 1
A get() 0 3 1
A increaseBy() 0 5 1
A isGreaterThanOrEqual() 0 3 1
A isLowerThan() 0 3 1
A isGreaterThan() 0 3 1
A validate() 0 4 2
A diff() 0 3 1
A __toString() 0 3 1
A increment() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Shared;
6
7
class IntegerValue implements \Stringable
8
{
9 32
    final public function __construct(
10
        protected int $value,
11
    ) {
12 32
        $this->validate();
13 29
    }
14
15 28
    public function get(): int
16
    {
17 28
        return $this->value;
18
    }
19
20 3
    public function equals(self $value): bool
21
    {
22 3
        return $this->value === $value->get();
23
    }
24
25 1
    public function isLowerThan(self $value): bool
26
    {
27 1
        return $this->value < $value->get();
28
    }
29
30 8
    public function isGreaterThan(self $value): bool
31
    {
32 8
        return $this->value > $value->get();
33
    }
34
35 4
    public function isGreaterThanOrEqual(self $value): bool
36
    {
37 4
        return $this->value >= $value->get();
38
    }
39
40 3
    public function diff(self $value): static
41
    {
42 3
        return new static(abs($this->value - $value->get()));
0 ignored issues
show
Bug introduced by
It seems like abs($this->value - $value->get()) can also be of type double; however, parameter $value of AardsGerds\Game\Shared\IntegerValue::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        return new static(/** @scrutinizer ignore-type */ abs($this->value - $value->get()));
Loading history...
43
    }
44
45 5
    public function increment(): static
46
    {
47 5
        $this->value += 1;
48
49 5
        return $this;
50
    }
51
52 5
    public function increaseBy(self $value): static
53
    {
54 5
        $this->value += $value->get();
55
56 5
        return $this;
57
    }
58
59 1
    public function __toString(): string
60
    {
61 1
        return (string) $this->value;
62
    }
63
64 23
    protected function validate(): void
65
    {
66 23
        if ($this->value < 0) {
67 1
            throw IntegerValueException::onlyPositive();
68
        }
69 22
    }
70
}
71