Passed
Push — develop ( 4895f7...2b6cea )
by Daniel
08:09
created

Page::setRoutable()   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 1
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 ApiPlatform\Core\Annotation\ApiResource;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use Silverback\ApiComponentBundle\Entity\Layout\Layout;
10
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareInterface;
11
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareTrait;
12
use Symfony\Component\Serializer\Annotation\Groups;
13
14
/**
15
 * Class Page
16
 * @package Silverback\ApiComponentBundle\Entity\Content
17
 * @author Daniel West <[email protected]>
18
 * @ApiResource()
19
 * @ORM\Entity()
20
 */
21
class Page extends AbstractContent implements RouteAwareInterface
22
{
23
    use RouteAwareTrait;
24
25
    /**
26
     * @ORM\Column()
27
     * @Groups({"content", "route"})
28
     * @var string
29
     */
30
    protected $title;
31
32
    /**
33
     * @ORM\Column()
34
     * @Groups({"content", "route"})
35
     * @var string
36
     */
37
    protected $metaDescription;
38
39
    /**
40
     * @ORM\ManyToOne(targetEntity="Page")
41
     * @ORM\JoinColumn(nullable=true)
42
     * @Groups({"route"})
43
     * @var null|Page
44
     */
45
    protected $parent;
46
47
    /**
48
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Layout\Layout")
49
     * @ORM\JoinColumn(onDelete="SET NULL")
50
     * @ApiProperty()
51
     * @Groups({"content","route"})
52
     * @var Layout|null
53
     */
54
    protected $layout;
55
56
    /**
57
     * @ORM\Column(type="boolean")
58
     * @Groups({"content"})
59
     * @var boolean
60
     */
61
    protected $routable = true;
62
63 7
    public function __construct()
64
    {
65 7
        parent::__construct();
66 7
        $this->routes = new ArrayCollection;
67 7
    }
68
69
    /**
70
     * @return string
71
     */
72 3
    public function getTitle(): string
73
    {
74 3
        return $this->title;
75
    }
76
77
    /**
78
     * @param string $title
79
     */
80 3
    public function setTitle(string $title): void
81
    {
82 3
        $this->title = $title;
83 3
    }
84
85
    /**
86
     * @return string
87
     */
88 1
    public function getMetaDescription(): string
89
    {
90 1
        return $this->metaDescription;
91
    }
92
93
    /**
94
     * @param string $metaDescription
95
     */
96 2
    public function setMetaDescription(string $metaDescription): void
97
    {
98 2
        $this->metaDescription = $metaDescription;
99 2
    }
100
101
    /**
102
     * @return null|Page
103
     */
104 2
    public function getParent(): ?Page
105
    {
106 2
        return $this->parent;
107
    }
108
109
    /**
110
     * @param null|Page $parent
111
     */
112 2
    public function setParent(?Page $parent): void
113
    {
114 2
        $this->parent = $parent;
115 2
    }
116
117
    /**
118
     * @return Layout|null
119
     */
120 1
    public function getLayout(): ?Layout
121
    {
122 1
        return $this->layout;
123
    }
124
125
    /**
126
     * @param Layout|null $layout
127
     */
128 2
    public function setLayout(?Layout $layout): void
129
    {
130 2
        $this->layout = $layout;
131 2
    }
132
133
    /**
134
     * @return bool
135
     */
136
    public function isRoutable(): bool
137
    {
138
        return $this->routable;
139
    }
140
141
    /**
142
     * @param bool $routable
143
     */
144 3
    public function setRoutable(bool $routable): void
145
    {
146 3
        $this->routable = $routable;
147 3
    }
148
149
    /**
150
     * @inheritdoc
151
     */
152 1
    public function getDefaultRoute(): string
153
    {
154 1
        return $this->routable ? $this->getTitle() : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->routable ?...his->getTitle() : false could return the type false which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
155
    }
156
}
157