Completed
Push — master ( 11971b...eeafb3 )
by Nate
01:16
created

DateCreatedMutatorTrait::getDateCreated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\objects;
10
11
use craft\helpers\DateTimeHelper;
12
use DateTime;
13
14
/**
15
 * @property DateTime|null $dateCreated
16
 *
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 2.0.0
19
 */
20
trait DateCreatedMutatorTrait
21
{
22
    /**
23
     * @param $value
24
     * @return $this
25
     */
26
    public function setDateCreated($value)
27
    {
28
        if ($value) {
29
            $value = DateTimehelper::toDateTime($value);
30
        }
31
32
        $this->dateCreated = $value ?: null;
33
34
        return $this;
35
    }
36
37
    /**
38
     * @return DateTime
39
     */
40
    public function getDateCreated()
41
    {
42
        if (empty($this->dateCreated)) {
43
            return DateTimeHelper::toDateTime(
44
                new DateTime('now')
45
            );
46
        }
47
48
        return $this->dateCreated;
49
    }
50
}
51