Test Failed
Push — b0.27.0 ( 7070d1...8acaa0 )
by Sebastian
03:51
created

UuidDomainObjectAbstract::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\DataMapper;
13
14
use UnexpectedValueException;
15
16
/**
17
 * Abstract Class for Domain Object, UUID version.
18
 */
19
abstract class UuidDomainObjectAbstract implements UuidDomainObjectInterface
20
{
21
    /**
22
     * @var string Read only objectId
23
     */
24
    public $rId = '';
25
26
    /**
27
     * @var int Object uuid, same of db record
28
     */
29
    protected $objectId = '';
30
31
    /**
32
     * Get the UUID of the object (unique to the object type).
33
     *
34
     * <pre><code class="php">$object = new DomainObject($dependencies);
35
     *
36
     * $object->getId();
37
     * </code></pre>
38
     *
39
     * @return string Current object uuid.
40
     */
41
    public function getId(): string
42
    {
43
        return $this->objectId;
44
    }
45
46
    /**
47
     * Set the uuid for the object.
48
     *
49
     * <pre><code class="php">$object = new DomainObject($dependencies);
50
     *
51
     * $object->setId('10f6bace-22f3-4b42-9dda-659c89a3a3c9');
52
     * </code></pre>
53
     *
54
     * @param string $objectId New object uuid.
55
     *
56
     * @throws UnexpectedValueException If the uuid on the object is already set.
57
     *
58
     * @return string New object uid.
59
     */
60
    public function setId(string $objectId): string
61
    {
62
        if ($this->objectId !== '') {
0 ignored issues
show
introduced by
The condition $this->objectId !== '' is always true.
Loading history...
63
            throw new UnexpectedValueException('ObjectId property is immutable.');
64
        }
65
66
        $this->objectId = $objectId;
67
        $this->rId = $objectId;
68
69
        return $objectId;
70
    }
71
}
72