Lines
75.00%
6 / 8
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 | 71.42% | 5 / 7 | 0.00% | 0 / 1 | 2.09 | ||
| 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 | } |