Passed
Pull Request — feature/publishable (#43)
by Daniel
05:24
created

PublishableTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 1
b 0
f 0
dl 0
loc 42
ccs 0
cts 14
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPublishedResource() 0 3 1
A isPublished() 0 3 2
A setPublishedAt() 0 5 1
A setPublishedResource() 0 5 1
A getDraftResource() 0 3 1
A getPublishedAt() 0 3 1
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