Completed
Push — master ( ffd91f...6083ab )
by Philip
02:51
created

GeneratedIntegerIdEntity::isSame()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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