Completed
Push — master ( 193c43...77c695 )
by Sebastian
04:11
created

DomainObjectTimeTrait::setCreated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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
 * Provide methods and properties for track the creation and updates of the
18
 * domain objects.
19
 */
20
trait DomainObjectTimeTrait
21
{
22
    /**
23
     * @var string Insertion date on persistent storage.
24
     */
25
    public string $created = '';
26
27
    /**
28
     * @var string Last update date on persistento storage.
29
     */
30
    public string $lastUpdate = '';
31
32
    /**
33
     * Set the creation date for the object.
34
     *
35
     * @return void
36
     *
37
     * @throws UnexpectedValueException If the creation date on the object is already set.
38
     */
39
    public function setCreated(): void
40
    {
41
        $date = \date(DATE_ATOM);
42
43
        if ($this->created !== '') {
44
            throw new UnexpectedValueException('Creation date property is immutable.');
45
        }
46
47
        $this->created = $date;
48
    }
49
50
    /**
51
     * Set the time for the last object changes.
52
     *
53
     * @return void
54
     */
55
    public function setLastUpdate(): void
56
    {
57
        $date = \date(DATE_ATOM);
58
59
        $this->lastUpdate = $date;
60
    }
61
}
62