Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DeleteBookController | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| deleteBook | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace AppDemo\Library\Application\Http; |
| 11 | |
| 12 | use AppDemo\Library\Application\Command\DeleteBookCommand; |
| 13 | use AppDemo\Shared\Application\AbstractHttpController; |
| 14 | use AppDemo\Shared\Domain\Interface\SessionServiceInterface; |
| 15 | use Phexium\Application\ControllerInterface; |
| 16 | use Phexium\Plugin\CommandBus\Port\CommandBusInterface; |
| 17 | use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface; |
| 18 | use Phexium\Plugin\Logger\Port\LoggerInterface; |
| 19 | use Phexium\Presentation\ResponseBuilderInterface; |
| 20 | use Psr\Http\Message\ResponseInterface; |
| 21 | use Psr\Http\Message\ServerRequestInterface; |
| 22 | |
| 23 | final readonly class DeleteBookController extends AbstractHttpController implements ControllerInterface |
| 24 | { |
| 25 | public function __construct( |
| 26 | private CommandBusInterface $commandBus, |
| 27 | private SessionServiceInterface $sessionService, |
| 28 | private ResponseBuilderInterface $responseBuilder, |
| 29 | private IdGeneratorInterface $idGenerator, |
| 30 | private LoggerInterface $logger, |
| 31 | ) {} |
| 32 | |
| 33 | public function deleteBook( |
| 34 | ServerRequestInterface $request, // NOSONAR - Slim Framework PSR-15 contract |
| 35 | ResponseInterface $response, |
| 36 | array $args = [] |
| 37 | ): ResponseInterface { |
| 38 | $this->logger->info('DeleteBookController: Processing request'); |
| 39 | |
| 40 | $bookId = $this->idGenerator->from($args['id']); |
| 41 | |
| 42 | $command = new DeleteBookCommand($bookId); |
| 43 | |
| 44 | $this->commandBus->dispatch($command); |
| 45 | |
| 46 | $this->sessionService->addFlashMessage('success', 'Book deleted successfully!'); |
| 47 | |
| 48 | return $this->responseBuilder |
| 49 | ->withResponse($response) |
| 50 | ->withStatus(302) |
| 51 | ->withHeader('Location', '/books') |
| 52 | ->build() |
| 53 | ; |
| 54 | } |
| 55 | } |