HasDeletedAtDate::setDeletedAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bone\BoneDoctrine\Traits;
6
7
use DateTimeImmutable;
8
use DateTimeInterface;
9
use DateTimeZone;
10
use Doctrine\ORM\Mapping as ORM;
11
12
#[ORM\HasLifecycleCallbacks]
13
trait HasDeletedAtDate
14
{
15
    #[ORM\Column(type: 'datetime_immutable', nullable:true)]
16
    private ?DateTimeImmutable $deletedAt = null;
17
18 1
    public function getDeletedAt(): DateTimeInterface
19
    {
20 1
        return $this->deletedAt;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->deletedAt could return the type null which is incompatible with the type-hinted return DateTimeInterface. Consider adding an additional type-check to rule them out.
Loading history...
21
    }
22
23 1
    #[ORM\PreUpdate]
24
    public function setDeletedAt(): void
25
    {
26 1
        $this->deletedAt = new DateTimeImmutable('now', new DateTimeZone('UTC'));
27
    }
28
}
29