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

DateCreatedMutatorTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDateCreated() 0 10 3
A getDateCreated() 0 10 2
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