Test Failed
Push — master ( c4aa6a...a5e42e )
by Mathieu
03:19
created

TimestampableTrait::getCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Charcoal\Object;
4
5
use InvalidArgumentException;
6
7
use DateTime;
8
use DateTimeInterface;
9
10
/**
11
 *
12
 */
13
trait TimestampableTrait
14
{
15
    /**
16
     * Object creation date (set automatically on save)
17
     * @var DateTimeInterface
18
     */
19
    private $created;
20
21
    /**
22
     * Object last modified date (set automatically on save and update)
23
     * @var DateTimeInterface
24
     */
25
    private $lastModified;
26
27
    /**
28
     * @param \DateTimeInterface|string|null $created The object's creation timestamp.
29
     * @throws InvalidArgumentException If the provided date/time is invalid.
30
     * @return self
31
     */
32 View Code Duplication
    public function setCreated($created)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        if ($created === null) {
35
            $this->created = null;
36
            return $this;
37
        }
38
        if (is_string($created)) {
39
            $created = new DateTime($created);
40
        }
41
        if (!($created instanceof DateTimeInterface)) {
42
            throw new InvalidArgumentException(
43
                'Invalid "Created" value. Must be a date/time string or a DateTime object.'
44
            );
45
        }
46
        $this->created = $created;
47
        return $this;
48
    }
49
50
    /**
51
     * @return DateTimeInterface|null
52
     */
53
    public function getCreated()
54
    {
55
        return $this->created;
56
    }
57
58
    /**
59
     * @param \DateTimeInterface|string|null $lastModified The object's last modified timestamp.
60
     * @throws InvalidArgumentException If the provided date/time is invalid.
61
     * @return self
62
     */
63 View Code Duplication
    public function setLastModified($lastModified)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        if ($lastModified === null) {
66
            $this->lastModified = null;
67
            return $this;
68
        }
69
        if (is_string($lastModified)) {
70
            $lastModified = new DateTime($lastModified);
71
        }
72
        if (!($lastModified instanceof DateTimeInterface)) {
73
            throw new InvalidArgumentException(
74
                'Invalid "Last Modified" value. Must be a date/time string or a DateTime object.'
75
            );
76
        }
77
        $this->lastModified = $lastModified;
78
        return $this;
79
    }
80
81
    /**
82
     * @return DateTimeInterface|null
83
     */
84
    public function getLastModified()
85
    {
86
        return $this->lastModified;
87
    }
88
}
89