1 | <?php |
||||
2 | |||||
3 | declare(strict_types = 1); |
||||
4 | |||||
5 | namespace WebPresentation\ApplicationController; |
||||
6 | |||||
7 | use WebPresentation\Forward; |
||||
8 | use Psr\Http\Message\ResponseInterface as ServerResponse; |
||||
9 | use Psr\Http\Message\ServerRequestInterface as ServerRequest; |
||||
10 | |||||
11 | class FrontServlet |
||||
12 | { |
||||
13 | private ?ServerResponse $response = null; |
||||
14 | |||||
15 | 2 | public function service(ServerRequest $request, ServerResponse $response): void |
|||
16 | { |
||||
17 | 2 | $params = $this->getParameterMap($request); |
|||
18 | 2 | $appController = $this->getApplicationController($request); |
|||
19 | 2 | $commandString = $params["command"] ?? ''; |
|||
20 | 2 | $domainCommand = $appController->getDomainCommand($commandString, $params); |
|||
21 | 2 | $domainCommand->run($params); |
|||
22 | |||||
23 | 2 | $viewPage = sprintf( |
|||
24 | 2 | "/%s.php", |
|||
25 | 2 | $appController->getView($commandString, $params) |
|||
26 | ); |
||||
27 | |||||
28 | 2 | $this->response = $this->forward($viewPage, $request, $response); |
|||
29 | 2 | } |
|||
30 | |||||
31 | 2 | public function getResponse(): ServerResponse |
|||
32 | { |
||||
33 | 2 | return $this->response; |
|||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||
34 | } |
||||
35 | |||||
36 | 2 | protected function getParameterMap(ServerRequest $request): array |
|||
37 | { |
||||
38 | 2 | return array_merge( |
|||
39 | 2 | $request->getQueryParams() ?? [], |
|||
40 | 2 | $request->getParsedBody() ?? [] |
|||
0 ignored issues
–
show
It seems like
$request->getParsedBody() ?? array() can also be of type object ; however, parameter $arrays of array_merge() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
41 | ); |
||||
42 | } |
||||
43 | |||||
44 | 2 | protected function forward( |
|||
45 | string $viewPage, |
||||
46 | ServerRequest $request, |
||||
47 | ServerResponse $response |
||||
48 | ): ServerResponse { |
||||
49 | 2 | $f = new Forward($request, $response); |
|||
50 | |||||
51 | 2 | return $f->sendResponse($viewPage); |
|||
52 | } |
||||
53 | |||||
54 | 2 | private function getApplicationController(ServerRequest $request): ApplicationController |
|||
55 | { |
||||
56 | 2 | $target = trim($request->getUri()->getPath(), "/"); |
|||
57 | |||||
58 | 2 | $class = sprintf("%s\%sApplicationController", __NAMESPACE__, $target); |
|||
59 | |||||
60 | 2 | return new $class(); |
|||
61 | } |
||||
62 | } |
||||
63 |