Timestamps   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 73
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreatedAt() 0 4 1
A prePersist() 0 4 1
A preUpdate() 0 4 1
A getUpdatedAt() 0 4 1
A getCreatedAtTimestamp() 0 4 1
A getUpdatedAtTimestamp() 0 4 2
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