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

GeneratedIntegerIdEntity   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 15.38%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 49
ccs 2
cts 13
cp 0.1538
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
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
/**
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