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

IntegerValue   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A increaseBy() 0 5 1
A isGreaterThanOrEqual() 0 3 1
A __construct() 0 4 1
A equals() 0 3 1
A isGreaterThan() 0 3 1
A validate() 0 2 1
A diff() 0 3 1
A get() 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 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