SoftDeletes::isDeleted()   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
c 0
b 0
f 0
dl 0
loc 4
rs 10
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 SoftDeletes
7
{
8
9
    /**
10
     * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
11
     *
12
     * @var Carbon
13
     */
14
    private $deletedAt;
15
16
17
    /**
18
     *
19
     */
20
    public function trash()
21
    {
22
        if ($this->isDeleted()) {
23
            return;
24
        }
25
26
        $this->deletedAt = Carbon::now();
27
    }
28
29
30
    /**
31
     * @return mixed
32
     */
33
    public function getDeletedAt()
34
    {
35
        return $this->deletedAt;
36
    }
37
38
39
    /**
40
     * @return int|null
41
     */
42
    public function getDeletedAtTimestamp()
43
    {
44
        return $this->deletedAt instanceof Carbon ? $this->deletedAt->getTimestamp() : null;
45
    }
46
47
48
    /**
49
     * @return bool
50
     */
51
    private function isDeleted()
52
    {
53
        return $this->deletedAt === null;
54
    }
55
}
56