Completed
Push — develop ( e6c657...69ffd6 )
by Daniel
07:10
created

PageTrait::getDefaultRouteName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Content;
4
5
use ApiPlatform\Core\Annotation\ApiProperty;
6
use Doctrine\ORM\Mapping as ORM;
7
use Silverback\ApiComponentBundle\Entity\Layout\Layout;
8
use Silverback\ApiComponentBundle\Entity\Route\Route;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
11
trait PageTrait
12
{
13
    /**
14
     * @ORM\Column()
15
     * @Groups({"content", "route", "component"})
16
     * @var string
17
     */
18
    protected $title;
19
20
    /**
21
     * @ORM\Column()
22
     * @Groups({"content", "route"})
23
     * @var string
24
     */
25
    protected $metaDescription;
26
27
    /**
28
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Page")
29
     * @ORM\JoinColumn(nullable=true)
30
     * @Groups({"route"})
31
     * @var null|Page
32
     */
33
    protected $parent;
34
35
    /**
36
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Layout\Layout")
37
     * @ORM\JoinColumn(onDelete="SET NULL")
38
     * @ApiProperty()
39
     * @Groups({"content","route"})
40
     * @var Layout|null
41
     */
42
    protected $layout;
43
44
    /**
45
     * @return string
46
     */
47 3
    public function getTitle(): string
48
    {
49 3
        return $this->title;
50
    }
51
52
    /**
53
     * @param string $title
54
     */
55 3
    public function setTitle(string $title): void
56
    {
57 3
        $this->title = $title;
58 3
    }
59
60
    /**
61
     * @return string
62
     */
63 1
    public function getMetaDescription(): string
64
    {
65 1
        return $this->metaDescription ?: '';
66
    }
67
68
    /**
69
     * @param string $metaDescription
70
     */
71 2
    public function setMetaDescription(string $metaDescription): void
72
    {
73 2
        $this->metaDescription = $metaDescription;
74 2
    }
75
76
    /**
77
     * @return null|Page
78
     */
79 2
    public function getParent(): ?Page
80
    {
81 2
        return $this->parent;
82
    }
83
84
    /**
85
     * @param null|Page $parent
86
     */
87 2
    public function setParent(?Page $parent): void
88
    {
89 2
        $this->parent = $parent;
90 2
    }
91
92
    /**
93
     * @return Layout|null
94
     */
95 1
    public function getLayout(): ?Layout
96
    {
97 1
        return $this->layout;
98
    }
99
100
    /**
101
     * @param Layout|null $layout
102
     */
103 2
    public function setLayout(?Layout $layout): void
104
    {
105 2
        $this->layout = $layout;
106 2
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111 1
    public function getDefaultRoute(): string
112
    {
113 1
        return $this->getTitle();
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119 1
    public function getDefaultRouteName(): string
120
    {
121 1
        return $this->getTitle();
122
    }
123
124
    /**
125
     * @inheritdoc
126
     */
127 1
    public function getParentRoute(): ?Route
128
    {
129 1
        return $this->getParent() ? $this->getParent()->getRoutes()->first() : null;
130
    }
131
}
132