Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
80.00% covered (warning)
80.00%
4 / 5
75.00% covered (warning)
75.00%
3 / 4
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserController
92.31% covered (success)
92.31%
12 / 13
80.00% covered (warning)
80.00%
4 / 5
75.00% covered (warning)
75.00%
3 / 4
66.67% covered (warning)
66.67%
2 / 3
4.25
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 me
88.89% covered (warning)
88.89%
8 / 9
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
2.50
 avatar
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\User\Infrastructure\Controller;
4
5use App\Shared\Infrastructure\Service\Base64FileDecoder;
6use App\User\Application\Command\GetUserByIdentityQuery;
7use App\User\Application\Command\UpdateAvatarCommand;
8use App\User\Application\Handler\GetUserHandler;
9use App\User\Application\Handler\UpdateAvatarHandler;
10use App\User\Infrastructure\Dto\UpdateAvatarRequest;
11use App\User\Infrastructure\Dto\UserDto;
12use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
13use Symfony\Component\HttpFoundation\JsonResponse;
14use Symfony\Component\HttpFoundation\Response;
15use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
16use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17use Symfony\Component\ObjectMapper\ObjectMapperInterface;
18use Symfony\Component\Routing\Attribute\Route;
19use Symfony\Component\Security\Core\User\UserInterface;
20use Symfony\Component\Security\Http\Attribute\CurrentUser;
21use Symfony\Component\Security\Http\Attribute\IsGranted;
22
23#[Route('/api/user')]
24class UserController extends AbstractController
25{
26    public function __construct(
27        private readonly GetUserHandler $getUserHandler,
28        private readonly UpdateAvatarHandler $updateAvatarHandler,
29        private readonly ObjectMapperInterface $objectMapper,
30        private readonly Base64FileDecoder $base64FileDecoder
31    ) {
32    }
33
34
35    #[Route('/me', name: 'api_user_me', methods: ['GET'])]
36    #[IsGranted('ROLE_USER')]
37    public function me(#[CurrentUser] ?UserInterface $user) :JsonResponse
38    {
39        $user = ($this->getUserHandler)(new GetUserByIdentityQuery($user->getUserIdentifier()));
40
41        if (!$user) {
42            throw new NotFoundHttpException('User not found');
43        }
44        return $this->json(
45            $this->objectMapper->map(
46                $user,
47                UserDto::class
48            )
49        );
50    }
51
52    #[Route('/me/avatar', name: 'api_user_me_avatar', methods: ['PUT'])]
53    #[IsGranted('ROLE_USER')]
54    public function avatar(
55        #[MapRequestPayload] UpdateAvatarRequest $updateAvatarRequest,
56        #[CurrentUser] ?UserInterface $user
57    ) :JsonResponse {
58        $tempFile = $this->base64FileDecoder->decodeToTempFile($updateAvatarRequest->getContents(), $updateAvatarRequest->getFileName());
59        $u = ($this->updateAvatarHandler)(new UpdateAvatarCommand($user->getUserIdentifier(), $tempFile));
60        return $this->json([], Response::HTTP_NO_CONTENT);
61    }
62}

Paths

Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once. Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

UserController->__construct
26    public function __construct(
27        private readonly GetUserHandler $getUserHandler,
28        private readonly UpdateAvatarHandler $updateAvatarHandler,
29        private readonly ObjectMapperInterface $objectMapper,
30        private readonly Base64FileDecoder $base64FileDecoder
31    ) {
32    }
UserController->avatar
54    public function avatar(
55        #[MapRequestPayload] UpdateAvatarRequest $updateAvatarRequest,
56        #[CurrentUser] ?UserInterface $user
57    ) :JsonResponse {
58        $tempFile = $this->base64FileDecoder->decodeToTempFile($updateAvatarRequest->getContents(), $updateAvatarRequest->getFileName());
59        $u = ($this->updateAvatarHandler)(new UpdateAvatarCommand($user->getUserIdentifier(), $tempFile));
60        return $this->json([], Response::HTTP_NO_CONTENT);
61    }
UserController->me
37    public function me(#[CurrentUser] ?UserInterface $user) :JsonResponse
38    {
39        $user = ($this->getUserHandler)(new GetUserByIdentityQuery($user->getUserIdentifier()));
40
41        if (!$user) {
 
42            throw new NotFoundHttpException('User not found');
37    public function me(#[CurrentUser] ?UserInterface $user) :JsonResponse
38    {
39        $user = ($this->getUserHandler)(new GetUserByIdentityQuery($user->getUserIdentifier()));
40
41        if (!$user) {
 
44        return $this->json(
45            $this->objectMapper->map(
46                $user,
47                UserDto::class
48            )
49        );
50    }
{main}
3namespace App\User\Infrastructure\Controller;
4
5use App\Shared\Infrastructure\Service\Base64FileDecoder;
6use App\User\Application\Command\GetUserByIdentityQuery;
7use App\User\Application\Command\UpdateAvatarCommand;
8use App\User\Application\Handler\GetUserHandler;
9use App\User\Application\Handler\UpdateAvatarHandler;
10use App\User\Infrastructure\Dto\UpdateAvatarRequest;
11use App\User\Infrastructure\Dto\UserDto;
12use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
13use Symfony\Component\HttpFoundation\JsonResponse;
14use Symfony\Component\HttpFoundation\Response;
15use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
16use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17use Symfony\Component\ObjectMapper\ObjectMapperInterface;
18use Symfony\Component\Routing\Attribute\Route;
19use Symfony\Component\Security\Core\User\UserInterface;
20use Symfony\Component\Security\Http\Attribute\CurrentUser;
21use Symfony\Component\Security\Http\Attribute\IsGranted;
22
23#[Route('/api/user')]
24class UserController extends AbstractController
25{
26    public function __construct(
27        private readonly GetUserHandler $getUserHandler,
28        private readonly UpdateAvatarHandler $updateAvatarHandler,
29        private readonly ObjectMapperInterface $objectMapper,
30        private readonly Base64FileDecoder $base64FileDecoder
31    ) {
32    }
33
34
35    #[Route('/me', name: 'api_user_me', methods: ['GET'])]
36    #[IsGranted('ROLE_USER')]
37    public function me(#[CurrentUser] ?UserInterface $user) :JsonResponse
38    {
39        $user = ($this->getUserHandler)(new GetUserByIdentityQuery($user->getUserIdentifier()));
40
41        if (!$user) {
42            throw new NotFoundHttpException('User not found');
43        }
44        return $this->json(
45            $this->objectMapper->map(
46                $user,
47                UserDto::class
48            )
49        );
50    }
51
52    #[Route('/me/avatar', name: 'api_user_me_avatar', methods: ['PUT'])]
53    #[IsGranted('ROLE_USER')]
54    public function avatar(
55        #[MapRequestPayload] UpdateAvatarRequest $updateAvatarRequest,
56        #[CurrentUser] ?UserInterface $user
57    ) :JsonResponse {
58        $tempFile = $this->base64FileDecoder->decodeToTempFile($updateAvatarRequest->getContents(), $updateAvatarRequest->getFileName());
59        $u = ($this->updateAvatarHandler)(new UpdateAvatarCommand($user->getUserIdentifier(), $tempFile));
60        return $this->json([], Response::HTTP_NO_CONTENT);
61    }