Lines 84.61% 11 / 13
Methods 50.00% 1 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 __invoke 83.33% 10 / 12 0.00% 0 / 1 3.04
16final readonly class EditFormController
17{
18    public function __construct(
19        private DistrictService $districtService,
20        private GetDistrictQueryFactory $queryFactory,
21        private Session $session,
22        private View $view,
23    ) {
24    }
25
26    /**
27     * @param array<string, string> $args
28     */
29    public function __invoke(Request $request, Response $response, array $args): Response
30    {
31        $district = $this->session->getAndDelete("form.edit.values");
32        if ($district === null) {
33            try {
34                $district = $this->districtService->get($this->queryFactory->fromRoute($args, $request));
35            } catch (NotFoundInRepositoryException) {
36                throw new HttpNotFoundException($request);
37            }
38        }
39        $templateData = [
40            "title" => "Edit a district",
41            "district" => $district,
42            "errors" => $this->session->getAndDelete("form.edit.errors"),
43            "errorMessage" => $this->session->getAndDelete("form.edit.error.message"),
44        ];
45        return $this->view->render($response, "edit.html", $templateData);
46    }
47}