Timestamps::getUpdatedAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Nord\Lumen\Doctrine\ORM\Traits;
2
3
use Doctrine\ORM\Mapping as ORM;
4
use Carbon\Carbon;
5
6
trait Timestamps
7
{
8
9
    /**
10
     * @ORM\Column(type="datetime", name="created_at")
11
     *
12
     * @var Carbon
13
     */
14
    private $createdAt;
15
16
    /**
17
     * @ORM\Column(type="datetime", name="updated_at", nullable=true)
18
     *
19
     * @var Carbon
20
     */
21
    private $updatedAt;
22
23
24
    /**
25
     * @ORM\PrePersist
26
     */
27
    public function prePersist()
28
    {
29
        $this->createdAt = Carbon::now();
30
    }
31
32
33
    /**
34
     * @ORM\PreUpdate
35
     */
36
    public function preUpdate()
37
    {
38
        $this->updatedAt = Carbon::now();
39
    }
40
41
42
    /**
43
     * @return Carbon
44
     */
45
    public function getCreatedAt()
46
    {
47
        return $this->createdAt;
48
    }
49
50
51
    /**
52
     * @return Carbon
53
     */
54
    public function getUpdatedAt()
55
    {
56
        return $this->updatedAt;
57
    }
58
59
60
    /**
61
     *
62
     *
63
     * @return int
64
     */
65
    public function getCreatedAtTimestamp()
66
    {
67
        return $this->createdAt->getTimestamp();
68
    }
69
70
71
    /**
72
     * @return int|null
73
     */
74
    public function getUpdatedAtTimestamp()
75
    {
76
        return $this->updatedAt instanceof Carbon ? $this->updatedAt->getTimestamp() : null;
77
    }
78
}
79