Passed
Pull Request — feature/publishable (#43)
by Daniel
06:23
created

PublishableTrait::setPublishedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
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
/**
17
 * @author Vincent Chalamon <[email protected]>
18
 */
19
trait PublishableTrait
20
{
21
    private ?\DateTimeInterface $publishedAt = null;
22
23
    private ?self $publishedResource = null;
24
25
    private ?self $draftResource = null;
26
27
    /** @return static */
28
    public function setPublishedAt(?\DateTimeInterface $publishedAt)
29
    {
30
        $this->publishedAt = $publishedAt;
31
32
        return $this;
33
    }
34
35
    public function getPublishedAt(): ?\DateTimeInterface
36
    {
37
        return $this->publishedAt;
38
    }
39
40
    public function isPublished(): bool
41
    {
42
        return null !== $this->publishedAt && new \DateTimeImmutable() >= $this->publishedAt;
43
    }
44
45
    /** @return static */
46
    public function setPublishedResource($publishedResource)
47
    {
48
        $this->publishedResource = $publishedResource;
49
50
        return $this;
51
    }
52
53
    public function getPublishedResource(): ?self
54
    {
55
        return $this->publishedResource;
56
    }
57
58
    public function getDraftResource(): ?self
59
    {
60
        return $this->draftResource;
61
    }
62
}
63