IntegerItem::__construct()   A
last analyzed

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 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
/*
4
 * Copyright (C) 2019 Sebastian Böttger <[email protected]>
5
 * You may use, distribute and modify this code under the
6
 * terms of the MIT license.
7
 *
8
 * You should have received a copy of the MIT license with
9
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
10
 */
11
12
namespace Seboettg\Forest\Item;
13
14
use Seboettg\Collection\Comparable\Comparable;
15
16
class IntegerItem implements ItemInterface {
17
18
    /**
19
     * @var int
20
     */
21
    protected $value;
22
23
    /**
24
     * Item constructor.
25
     * @param int $value
26
     */
27 10
    public function __construct(int $value)
28
    {
29 10
        $this->value = $value;
30 10
    }
31
32
    /**
33
     * @return int
34
     */
35 11
    public function getValue(): int
36
    {
37 11
        return $this->value;
38
    }
39
40
    /**
41
     * @param Comparable|IntegerItem $b
42
     * @return int
43
     */
44 11
    public function compareTo(Comparable $b): int
45
    {
46
        /** @var IntegerItem $b */
47 11
        if ($this->value === $b->getValue()) {
48 4
            return 0;
49
        }
50 11
        return $this->value < $b->getValue() ? -1 : 1;
51
52
    }
53
54
    /**
55
     * @param ItemInterface|IntegerItem $item
56
     * @return bool
57
     */
58
    public function equals(ItemInterface $item): bool
59
    {
60
        return $this->compareTo($item) === 0;
61
    }
62
}
63