Passed
Push — master ( 947512...97c1fb )
by Paweł
03:48
created

IntegerValue::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Shared;
6
7
class IntegerValue implements \Stringable
8
{
9 18
    final public function __construct(
10
        protected int $value,
11
    ) {
12 18
        $this->validate();
13 17
    }
14
15 16
    public function get(): int
16
    {
17 16
        return $this->value;
18
    }
19
20 3
    public function equals(self $value): bool
21
    {
22 3
        return $this->value === $value->get();
23
    }
24
25 5
    public function isGreaterThan(self $value): bool
26
    {
27 5
        return $this->value > $value->get();
28
    }
29
30 4
    public function isGreaterThanOrEqual(self $value): bool
31
    {
32 4
        return $this->value >= $value->get();
33
    }
34
35 1
    public function diff(self $value): static
36
    {
37 1
        return new static($this->value - $value->get());
38
    }
39
40 5
    public function increment(): static
41
    {
42 5
        $this->value += 1;
43
44 5
        return $this;
45
    }
46
47 5
    public function increaseBy(self $value): static
48
    {
49 5
        $this->value += $value->get();
50
51 5
        return $this;
52
    }
53
54 1
    public function __toString(): string
55
    {
56 1
        return (string) $this->value;
57
    }
58
59 10
    protected function validate(): void
60
    {
61 10
    }
62
}
63