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

TimestampedTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
eloc 10
c 3
b 0
f 1
dl 0
loc 42
ccs 7
cts 11
cp 0.6364
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreated() 0 3 1
A getModified() 0 3 1
A setModified() 0 5 1
A setCreated() 0 7 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