GeneratedIntegerIdEntity   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
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 44
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
    /** @var int */
13
    private $id;
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 12
    public function getId(): ?int
19
    {
20 12
        return $this->id;
21
    }
22
23
    public function isPersisted(): bool
24
    {
25
        return null !== $this->id;
26
    }
27
28
    /**
29
     * Checks if this entity represents the same entity as another one. Usually this is checked via the class and id.
30
     *
31
     * @param mixed $other
32
     *
33
     * @return bool
34
     */
35
    public function isSame($other): bool
36
    {
37
        if (null === $other || !is_object($other)) {
38
            return false;
39
        }
40
41
        $thisClass = ClassUtils::getRealClass(get_class($this));
42
        $otherClass = ClassUtils::getRealClass(get_class($other));
43
44
        if ($thisClass !== $otherClass) {
45
            return false;
46
        }
47
48
        /** @var EntityInterface $otherEntity */
49
        $otherEntity = $other;
50
51
        return $this->getId() === $otherEntity->getId();
52
    }
53
}
54