Issues (8)

src/Traits/HasDeletedAtDate.php (1 issue)

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