Passed
Pull Request — master (#4)
by Alex
09:00
created

DateUpdatedAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 5
c 2
b 1
f 0
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasDateUpdated() 0 3 1
A setDateUpdated() 0 3 1
A getDateUpdated() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\DateTime\Entity;
6
7
/**
8
 * @author  Alex Patterson <[email protected]>
9
 * @package Arp\DateTime\Entity
10
 */
11
trait DateUpdatedAwareTrait
12
{
13
    /**
14
     * @var \DateTimeInterface|null
15
     */
16
    protected ?\DateTimeInterface $dateUpdated;
17
18
    /**
19
     * Check if the updated date has been set.
20
     *
21
     * @return bool
22
     */
23
    public function hasDateUpdated(): bool
24
    {
25
        return isset($this->dateUpdated);
26
    }
27
28
    /**
29
     * Return the updated date.
30
     *
31
     * @return \DateTimeInterface|null
32
     */
33
    public function getDateUpdated(): ?\DateTime
34
    {
35
        return $this->dateUpdated;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->dateUpdated could return the type DateTimeInterface which includes types incompatible with the type-hinted return DateTime|null. Consider adding an additional type-check to rule them out.
Loading history...
36
    }
37
38
    /**
39
     * Set the updated date.
40
     *
41
     * @param \DateTimeInterface|null $dateTime
42
     */
43
    public function setDateUpdated(?\DateTimeInterface $dateTime): void
44
    {
45
        $this->dateUpdated = $dateTime;
46
    }
47
}
48