This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace PhpBoot\Controller; |
||
3 | |||
4 | use PhpBoot\Application; |
||
5 | use Symfony\Component\HttpFoundation\Request; |
||
6 | use Symfony\Component\HttpFoundation\Response; |
||
7 | |||
8 | class Route |
||
9 | { |
||
10 | 4 | public function __construct( |
|
11 | $method='', |
||
12 | $uri='', |
||
13 | RequestHandler $requestHandler=null, |
||
14 | ResponseHandler $responseHandler=null, |
||
15 | ExceptionHandler $exceptionHandler=null, |
||
16 | $hooks=[], |
||
17 | $summary = '', |
||
18 | $description = '') |
||
19 | { |
||
20 | 4 | $this->method = $method; |
|
21 | 4 | $this->uri = $uri; |
|
22 | 4 | $this->requestHandler = $requestHandler; |
|
23 | 4 | $this->responseHandler = $responseHandler; |
|
24 | 4 | $this->exceptionHandler = $exceptionHandler; |
|
25 | 4 | $this->hooks = $hooks; |
|
26 | 4 | $this->summary = $summary; |
|
27 | 4 | $this->description = $description; |
|
28 | 4 | } |
|
29 | |||
30 | /** |
||
31 | * @param Application $app |
||
32 | * @param callable $function |
||
33 | * @param Request $request |
||
34 | * @return Response |
||
35 | */ |
||
36 | 1 | public function invoke(Application $app, callable $function, Request $request) |
|
37 | { |
||
38 | 1 | $this->requestHandler or \PhpBoot\abort('undefined requestHandler'); |
|
39 | 1 | $this->responseHandler or \PhpBoot\abort('undefined responseHandler'); |
|
40 | 1 | $this->exceptionHandler or \PhpBoot\abort('undefined exceptionHandler'); |
|
41 | |||
42 | 1 | $res = $this->exceptionHandler->handler( |
|
43 | 1 | $app, |
|
44 | function()use($app, $request, $function){ |
||
45 | |||
46 | $next = function($request)use($app, $function){ |
||
47 | 1 | $params = []; |
|
48 | 1 | $reference = []; |
|
49 | 1 | $this->requestHandler->handle($app, $request, $params, $reference); |
|
50 | 1 | $res = call_user_func_array($function, $params); |
|
51 | 1 | return $this->responseHandler->handle($app, $res, $reference); |
|
52 | 1 | }; |
|
53 | 1 | View Code Duplication | foreach (array_reverse($this->hooks) as $hookName){ |
0 ignored issues
–
show
|
|||
54 | 1 | $next = function($request)use($app, $hookName, $next){ |
|
55 | 1 | $hook = $app->get($hookName); |
|
56 | /**@var $hook HookInterface*/ |
||
57 | 1 | return $hook->handle($request, $next); |
|
58 | 1 | }; |
|
59 | 1 | } |
|
60 | 1 | return $next($request); |
|
61 | 1 | }); |
|
62 | 1 | return $res; |
|
63 | } |
||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | 1 | public function getSummary() |
|
68 | { |
||
69 | 1 | return $this->summary; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param string $summary |
||
74 | */ |
||
75 | public function setSummary($summary) |
||
76 | { |
||
77 | $this->summary = $summary; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 1 | public function getDescription() |
|
84 | { |
||
85 | 1 | return $this->description; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param string $description |
||
90 | */ |
||
91 | public function setDescription($description) |
||
92 | { |
||
93 | $this->description = $description; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | */ |
||
99 | 5 | public function getMethod() |
|
100 | { |
||
101 | 5 | return $this->method; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param string $method |
||
106 | */ |
||
107 | public function setMethod($method) |
||
108 | { |
||
109 | $this->method = $method; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | 5 | public function getUri() |
|
116 | { |
||
117 | 5 | return $this->uri; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param string $uri |
||
122 | */ |
||
123 | public function setUri($uri) |
||
124 | { |
||
125 | $this->uri = $uri; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @return RequestHandler |
||
130 | */ |
||
131 | 6 | public function getRequestHandler() |
|
132 | { |
||
133 | 6 | return $this->requestHandler; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * @param RequestHandler $requestHandler |
||
138 | */ |
||
139 | public function setRequestHandler($requestHandler) |
||
140 | { |
||
141 | $this->requestHandler = $requestHandler; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @return ResponseHandler |
||
146 | */ |
||
147 | 5 | public function getResponseHandler() |
|
148 | { |
||
149 | 5 | return $this->responseHandler; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param ResponseHandler $responseHandler |
||
154 | */ |
||
155 | public function setResponseHandler($responseHandler) |
||
156 | { |
||
157 | $this->responseHandler = $responseHandler; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @return ExceptionHandler |
||
162 | */ |
||
163 | 3 | public function getExceptionHandler() |
|
164 | { |
||
165 | 3 | return $this->exceptionHandler; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * @param ExceptionHandler $exceptionHandler |
||
170 | */ |
||
171 | public function setExceptionHandler($exceptionHandler) |
||
172 | { |
||
173 | $this->exceptionHandler = $exceptionHandler; |
||
174 | } |
||
175 | |||
176 | |||
177 | /** |
||
178 | * @return string[] |
||
179 | */ |
||
180 | public function getHooks() |
||
181 | { |
||
182 | return $this->hooks; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param string[] $hooks |
||
187 | */ |
||
188 | public function setHooks($hooks) |
||
189 | { |
||
190 | $this->hooks = $hooks; |
||
191 | } |
||
192 | |||
193 | 2 | public function addHook($className) |
|
194 | { |
||
195 | 2 | $this->hooks[] = $className; |
|
196 | 2 | } |
|
197 | |||
198 | /** |
||
199 | * @return string[] |
||
200 | */ |
||
201 | 3 | public function getPathParams() |
|
202 | { |
||
203 | 3 | return $this->pathParams; |
|
204 | } |
||
205 | |||
206 | /** |
||
207 | * @param string[] $pathParams |
||
208 | */ |
||
209 | public function setPathParams($pathParams) |
||
210 | { |
||
211 | $this->pathParams = $pathParams; |
||
212 | } |
||
213 | /** |
||
214 | * @param string $pathParam |
||
215 | */ |
||
216 | 3 | public function addPathParam($pathParam) |
|
217 | { |
||
218 | 3 | $this->pathParams[] = $pathParam; |
|
219 | 3 | array_unique($this->pathParams); |
|
220 | 3 | } |
|
221 | |||
222 | /** |
||
223 | * @param string $name |
||
224 | * @return bool |
||
225 | */ |
||
226 | 3 | public function hasPathParam($name) |
|
227 | { |
||
228 | 3 | return in_array($name, $this->pathParams); |
|
229 | } |
||
230 | |||
231 | /** |
||
232 | * @var RequestHandler |
||
233 | */ |
||
234 | private $requestHandler; |
||
235 | |||
236 | /** |
||
237 | * @var ResponseHandler |
||
238 | */ |
||
239 | private $responseHandler; |
||
240 | |||
241 | /** |
||
242 | * @var ExceptionHandler |
||
243 | */ |
||
244 | private $exceptionHandler; |
||
245 | |||
246 | /** |
||
247 | * http method |
||
248 | * @var string |
||
249 | */ |
||
250 | private $method; |
||
251 | |||
252 | /** |
||
253 | * uri |
||
254 | * @var string |
||
255 | */ |
||
256 | private $uri; |
||
257 | |||
258 | /** |
||
259 | * @var string |
||
260 | */ |
||
261 | private $summary = ''; |
||
262 | /** |
||
263 | * @var string |
||
264 | */ |
||
265 | private $description=''; |
||
266 | |||
267 | /** |
||
268 | * hook class names |
||
269 | * @var string[] |
||
270 | */ |
||
271 | private $hooks=[]; |
||
272 | |||
273 | /** |
||
274 | * @var string[] |
||
275 | */ |
||
276 | private $pathParams =[]; |
||
277 | |||
278 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.