Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DeleteMyAvatarController
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 delete
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Identity\Infrastructure\Controllers;
6
7use App\Identity\Application\Command\ChangeMyAvatarCommand;
8use App\Identity\Application\Command\ChangeMyAvatarHandler;
9use App\Identity\Domain\Exceptions\UserNotFound;
10use App\Identity\Infrastructure\Http\ResolvesAuthenticatedUser;
11use OpenApi\Attributes as OA;
12use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
13use Symfony\Component\HttpFoundation\JsonResponse;
14use Symfony\Component\HttpFoundation\Response;
15use Symfony\Component\Routing\Attribute\Route;
16
17#[OA\Tag(name: 'Users')]
18class DeleteMyAvatarController extends AbstractController
19{
20    use ResolvesAuthenticatedUser;
21
22    public function __construct(
23        private readonly ChangeMyAvatarHandler $handler,
24    ) {
25    }
26
27    #[Route('/users/me/avatar', name: 'users_avatar_delete', methods: ['DELETE'])]
28    public function delete(): Response
29    {
30        $securityUser = $this->securityUser();
31
32        try {
33            $this->handler->handle(new ChangeMyAvatarCommand($securityUser->userId(), null));
34        } catch (UserNotFound $e) {
35            return new JsonResponse(['error' => $e->getMessage()], 404);
36        }
37
38        return new Response(null, Response::HTTP_NO_CONTENT);
39    }
40}