Passed
Pull Request — master (#5)
by Alex
02:32
created

EntityTrait::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\Entity;
6
7
/**
8
 * Default trait implementation of the \Arp\Entity\EntityInterface
9
 *
10
 * @author  Alex Patterson <[email protected]>
11
 * @package Arp\Entity
12
 */
13
trait EntityTrait
14
{
15
    /**
16
     * @var string|null
17
     */
18
    protected ?string $id = null;
19
20
    /**
21
     * Return the entity's identity.
22
     *
23
     * @return string|null
24
     */
25
    public function getId(): ?string
26
    {
27
        return $this->id;
28
    }
29
30
    /**
31
     * Set the entity's identity.
32
     *
33
     * @param string|null $id The identity that should be set.
34
     */
35
    public function setId(?string $id): void
36
    {
37
        $this->id = $id;
38
    }
39
40
    /**
41
     * Check if the identity has been set.
42
     *
43
     * @return bool
44
     */
45
    public function hasId(): bool
46
    {
47
        return !empty($this->id);
48
    }
49
50
    /**
51
     * Check if the provided id matches the $id provided.
52
     *
53
     * @param string $id The identity that should be compared.
54
     *
55
     * @return bool
56
     */
57
    public function isId(string $id): bool
58
    {
59
        return ($id === $this->id);
60
    }
61
}
62