Lines
100.00%
10 / 10
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AddFormController | 100.00% | 10 / 10 | 100.00% | 2 / 2 | 2 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| __invoke | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Districts\Editor\UI\Controller; | |
| 6 | ||
| 7 | use Districts\Editor\Application\CityIterator; | |
| 8 | use Districts\Editor\UI\Session; | |
| 9 | use Psr\Http\Message\ResponseInterface as Response; | |
| 10 | use Psr\Http\Message\ServerRequestInterface as Request; | |
| 11 | use Slim\Views\Twig as View; | |
| 12 | ||
| 13 | final readonly class AddFormController | |
| 14 | { | |
| 15 | public function __construct( | |
| 16 | private CityIterator $cityIterator, | |
| 17 | private Session $session, | |
| 18 | private View $view, | |
| 19 | ) { | |
| 20 | } | |
| 21 | ||
| 22 | /** | |
| 23 | * @param array<string, string> $args | |
| 24 | */ | |
| 25 | // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | |
| 26 | public function __invoke(Request $request, Response $response, array $args): Response | |
| 27 | { | |
| 28 | $cities = iterator_to_array($this->cityIterator); | |
| 29 | $templateData = [ | |
| 30 | "title" => "Add a district", | |
| 31 | "cities" => $cities, | |
| 32 | "district" => $this->session->getAndDelete("form.add.values"), | |
| 33 | "errors" => $this->session->getAndDelete("form.add.errors"), | |
| 34 | "errorMessage" => $this->session->getAndDelete("form.add.error.message"), | |
| 35 | ]; | |
| 36 | return $this->view->render($response, "add.html", $templateData); | |
| 37 | } | |
| 38 | } |