TimeTrait::getLastChangedAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the TheAlternativeZurich/events project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Entity\Traits;
13
14
use DateTime;
15
use Doctrine\ORM\Mapping as ORM;
16
use Exception;
17
18
/*
19
 * automatically keeps track of creation time & last change time
20
 */
21
22
trait TimeTrait
23
{
24
    /**
25
     * @var DateTime
26
     *
27
     * @ORM\Column(type="datetime")
28
     */
29
    private $createdAt;
30
31
    /**
32
     * @var DateTime
33
     *
34
     * @ORM\Column(type="datetime")
35
     */
36
    private $lastChangedAt;
37
38
    /**
39
     * @ORM\PrePersist()
40
     *
41
     * @throws Exception
42
     * @throws Exception
43
     */
44
    public function prePersistTime()
45
    {
46
        $this->createdAt = new DateTime();
47
        $this->lastChangedAt = new DateTime();
48
    }
49
50
    /**
51
     * @ORM\PreUpdate()
52
     *
53
     * @throws Exception
54
     */
55
    public function preUpdateTime()
56
    {
57
        $this->lastChangedAt = new DateTime();
58
    }
59
60
    /**
61
     * @return DateTime
62
     */
63
    public function getCreatedAt()
64
    {
65
        return $this->createdAt;
66
    }
67
68
    /**
69
     * @return DateTime
70
     */
71
    public function getLastChangedAt()
72
    {
73
        return $this->lastChangedAt;
74
    }
75
}
76