HasTimestamps::onPreUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Traits;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
trait HasTimestamps
8
{
9
    /**
10
     * @ORM\Column(type="datetime")
11
     */
12
    private $createdAt;
13
14
    /**
15
     * @ORM\Column(type="datetime", nullable=true)
16
     */
17
    private $updatedAt;
18
19
    /**
20
     * @ORM\PrePersist()
21
     */
22
    public function onPrePersist(): void
23
    {
24
        $this->createdAt = new \DateTime();
25
        $this->updatedAt = new \DateTime();
26
    }
27
28
    /**
29
     * @ORM\PreUpdate()
30
     */
31
    public function onPreUpdate(): void
32
    {
33
        $this->updatedAt = new \DateTime();
34
    }
35
}