Passed
Push — master ( ab171b...3e1bb9 )
by Philip
14:43
created

GeneratedIntegerIdEntity::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Dontdrinkandroot\Entity;
4
5
use Doctrine\Common\Util\ClassUtils;
6
7
/**
8
 * @author Philip Washington Sorst <[email protected]>
9
 */
10
class GeneratedIntegerIdEntity implements IntegerIdEntityInterface
11
{
12
    /**
13
     * @var int
14
     */
15
    private $id;
16
17
    /**
18
     * @return int
19
     */
20 12
    public function getId(): ?int
21
    {
22 12
        return $this->id;
23
    }
24
25
    /**
26
     * @return bool
27
     */
28
    public function isPersisted(): bool
29
    {
30
        return null !== $this->id;
31
    }
32
33
    /**
34
     * Checks if this entity represents the same entity as another one. Usually this is checked via the class and id.
35
     *
36
     * @param mixed $other
37
     *
38
     * @return bool
39
     */
40
    public function isSame($other): bool
41
    {
42
        if (null === $other || !is_object($other)) {
43
            return false;
44
        }
45
46
        $thisClass = ClassUtils::getRealClass(get_class($this));
47
        $otherClass = ClassUtils::getRealClass(get_class($other));
48
49
        if ($thisClass !== $otherClass) {
50
            return false;
51
        }
52
53
        /** @var EntityInterface $otherEntity */
54
        $otherEntity = $other;
55
56
        return $this->getId() === $otherEntity->getId();
57
    }
58
}
59