Passed
Push — feature/unit-tests ( 84c996...7c5ff9 )
by Daniel
05:24
created

TimestampedTrait::setCreated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Entity\Utility;
15
16
use ApiPlatform\Core\Annotation\ApiProperty;
17
use DateTime;
18
use DateTimeImmutable;
19
use Doctrine\ORM\Mapping as ORM;
20
use Symfony\Component\Validator\Constraints as Assert;
21
22
/**
23
 * @author Daniel West <[email protected]>
24
 */
25
trait TimestampedTrait
26
{
27
    /**
28
     * @ORM\Column(type="date_immutable")
29
     * @ApiProperty(writable=false)
30
     * @Assert\NotNull()
31
     */
32
    private ?DateTimeImmutable $created = null;
33
34
    /**
35
     * @ORM\Column(type="datetime")
36
     * @ApiProperty(writable=false)
37
     * @Assert\NotNull()
38
     */
39
    public ?DateTime $modified = null;
40
41
    /** @return static */
42 2
    public function setCreated(DateTimeImmutable $created)
43
    {
44 2
        if (!$this->created) {
45 2
            $this->created = $created;
46
        }
47
48 2
        return $this;
49
    }
50
51
    public function getCreated(): ?DateTimeImmutable
52
    {
53
        return $this->created;
54
    }
55
56
    /** @return static */
57 2
    public function setModified(DateTime $modified)
58
    {
59 2
        $this->modified = $modified;
60
61 2
        return $this;
62
    }
63
64
    public function getModified(): ?DateTime
65
    {
66
        return $this->modified;
67
    }
68
}
69