Lines
75.00%
6 / 8
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RemoveActionController | 75.00% | 6 / 8 | 50.00% | 1 / 2 | 3.14 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| __invoke | 71.42% | 5 / 7 | 0.00% | 0 / 1 | 2.09 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Districts\Editor\UI\Controller; | |
| 6 | ||
| 7 | use Districts\Core\Infrastructure\NotFoundInRepositoryException; | |
| 8 | use Districts\Editor\Application\DistrictService; | |
| 9 | use Districts\Editor\UI\Factory\RemoveDistrictCommandFactory; | |
| 10 | use Districts\Editor\UI\Session; | |
| 11 | use Fig\Http\Message\StatusCodeInterface as StatusCode; | |
| 12 | use Psr\Http\Message\ResponseFactoryInterface as ResponseFactory; | |
| 13 | use Psr\Http\Message\ResponseInterface as Response; | |
| 14 | use Psr\Http\Message\ServerRequestInterface as Request; | |
| 15 | use Slim\Exception\HttpNotFoundException; | |
| 16 | use Slim\Interfaces\RouteParserInterface; | |
| 17 | ||
| 18 | final readonly class RemoveActionController | |
| 19 | { | |
| 20 | public function __construct( | |
| 21 | private DistrictService $districtService, | |
| 22 | private RemoveDistrictCommandFactory $commandFactory, | |
| 23 | private Session $session, | |
| 24 | private RouteParserInterface $routeParser, | |
| 25 | private ResponseFactory $responseFactory, | |
| 26 | ) { | |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * @param array<string, string> $args | |
| 31 | */ | |
| 32 | // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | |
| 33 | public function __invoke(Request $request, Response $response, array $args): Response | |
| 34 | { | |
| 35 | $command = $this->commandFactory->fromRoute($args, $request); | |
| 36 | try { | |
| 37 | $this->districtService->remove($command); | |
| 38 | $this->session->set("success.message", "District data removed."); | |
| 39 | } catch (NotFoundInRepositoryException) { | |
| 40 | throw new HttpNotFoundException($request); | |
| 41 | } | |
| 42 | $url = $this->routeParser->relativeUrlFor("list"); | |
| 43 | return $this->responseFactory->createResponse(StatusCode::STATUS_FOUND)->withHeader("Location", $url); | |
| 44 | } | |
| 45 | } |