Passed
Push — master ( 3ec415...9f2f47 )
by Daniel
16:25
created

Route   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Test Coverage

Coverage 24.32%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 104
ccs 9
cts 37
cp 0.2432
rs 10
c 0
b 0
f 0
wmc 15

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setRedirect() 0 5 1
A getPage() 0 3 1
A setRedirectedFrom() 0 5 1
A setPage() 0 8 2
A getRedirectedFrom() 0 3 1
A getName() 0 3 1
A setName() 0 5 1
A setPageData() 0 8 2
A setPath() 0 5 1
A getPageData() 0 3 1
A __construct() 0 3 1
A getPath() 0 3 1
A getRedirect() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components 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\ApiComponentsBundle\Entity\Core;
15
16
use ApiPlatform\Core\Annotation\ApiResource;
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use Silverback\ApiComponentsBundle\Annotation as Silverback;
20
use Silverback\ApiComponentsBundle\Entity\Utility\IdTrait;
21
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
22
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
23
use Symfony\Component\Validator\Constraints as Assert;
24
25
/**
26
 * Although a user will be able to get the routes and the tree of data down to getting the ID for a component
27
 * fetching a component will be restricted based on the route it is within.
28
 *
29
 * @author Daniel West <[email protected]>
30
 *
31
 * @Silverback\Timestamped
32
 * @ApiResource(
33
 *     mercure=true,
34
 *     collectionOperations={
35
 *         "get",
36
 *         "post"
37
 *     },
38
 *     itemOperations={
39
 *         "get"={ "requirements"={"id"="(.+)"}, "security"="is_granted(object)" }
40
 *     }
41
 * )
42
 * @Assert\Expression(
43
 *     "!(this.getPage() == null & this.getPageData() == null)",
44
 *     message="Please specify either page or pageData."
45
 * )
46
 * @Assert\Expression(
47
 *     "!(this.getPage() != null & this.getPageData() != null)",
48
 *     message="Please specify either page or pageData, not both."
49
 * )
50
 * @UniqueEntity("name", message="The route name must be unique.")
51
 * @UniqueEntity("path", message="The route path must be unique.")
52
 */
53
class Route
54
{
55
    use IdTrait;
56
    use TimestampedTrait;
57
58
    /**
59
     * @Assert\NotNull()
60
     */
61
    private string $path;
62
63
    /**
64
     * @Assert\NotNull()
65
     */
66
    private string $name;
67
68
    private ?Route $redirect = null;
69
70
    private Collection $redirectedFrom;
71
72
    private ?Page $page = null;
73
74
    private ?AbstractPageData $pageData = null;
75
76 3
    public function __construct()
77
    {
78 3
        $this->redirectedFrom = new ArrayCollection();
79 3
    }
80
81
    public function getPath(): string
82
    {
83
        return $this->path;
84
    }
85
86 1
    public function setPath(string $path): self
87
    {
88 1
        $this->path = $path;
89
90 1
        return $this;
91
    }
92
93
    public function getName(): string
94
    {
95
        return $this->name;
96
    }
97
98 1
    public function setName(string $name): self
99
    {
100 1
        $this->name = $name;
101
102 1
        return $this;
103
    }
104
105
    public function getRedirect(): ?self
106
    {
107
        return $this->redirect;
108
    }
109
110
    public function setRedirect(?self $redirect): self
111
    {
112
        $this->redirect = $redirect;
113
114
        return $this;
115
    }
116
117
    public function getRedirectedFrom()
118
    {
119
        return $this->redirectedFrom;
120
    }
121
122
    public function setRedirectedFrom($redirectedFrom): self
123
    {
124
        $this->redirectedFrom = $redirectedFrom;
125
126
        return $this;
127
    }
128
129
    public function getPage(): ?Page
130
    {
131
        return $this->page;
132
    }
133
134
    public function setPage(?Page $page): self
135
    {
136
        $this->page = $page;
137
        if ($this->page) {
138
            $this->page->setRoute($this);
139
        }
140
141
        return $this;
142
    }
143
144
    public function getPageData(): ?AbstractPageData
145
    {
146
        return $this->pageData;
147
    }
148
149
    public function setPageData(?AbstractPageData $pageData): self
150
    {
151
        $this->pageData = $pageData;
152
        if ($this->pageData) {
153
            $this->pageData->setRoute($this);
154
        }
155
156
        return $this;
157
    }
158
}
159