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

GeneratedIntegerIdEntity   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getId() 0 4 1
A isPersisted() 0 4 1
A isSame() 0 18 4
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