Lines 77.77% 7 / 9
Functions and Methods 50.00% 1 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RemoveFormController 77.77% 7 / 9 50.00% 1 / 2 3.10 0.00% 0 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 __invoke 75.00% 6 / 8 0.00% 0 / 1 2.06
1<?php
2
3declare(strict_types=1);
4
5namespace Districts\Editor\UI\Controller;
6
7use Districts\Core\Infrastructure\NotFoundInRepositoryException;
8use Districts\Editor\Application\DistrictService;
9use Districts\Editor\UI\Factory\GetDistrictQueryFactory;
10use Psr\Http\Message\ResponseInterface as Response;
11use Psr\Http\Message\ServerRequestInterface as Request;
12use Slim\Exception\HttpNotFoundException;
13use Slim\Views\Twig as View;
14
15final readonly class RemoveFormController
16{
17    public function __construct(
18        private DistrictService $districtService,
19        private GetDistrictQueryFactory $queryFactory,
20        private View $view,
21    ) {
22    }
23
24    /**
25     * @param array<string, string> $args
26     */
27    public function __invoke(Request $request, Response $response, array $args): Response
28    {
29        try {
30            $district = $this->districtService->get($this->queryFactory->fromRoute($args, $request));
31        } catch (NotFoundInRepositoryException) {
32            throw new HttpNotFoundException($request);
33        }
34        $templateData = [
35            "title" => "Remove a district",
36            "district" => $district,
37        ];
38        return $this->view->render($response, "remove.html", $templateData);
39    }
40}