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

DomainObjectTimeTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 40
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setLastUpdate() 0 5 1
A setCreated() 0 9 2
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