Passed
Push — master ( c28736...a1fc90 )
by Tarmo
08:09
created

RolesController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Controller/Profile/RolesController.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Controller\Profile;
10
11
use App\Entity\User;
12
use App\Security\RolesService;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
14
use Swagger\Annotations as SWG;
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
use Symfony\Component\Routing\Annotation\Route;
17
18
/**
19
 * Class RolesController
20
 *
21
 * @package App\Controller\Profile
22
 * @author TLe, Tarmo Leppänen <[email protected]>
23
 */
24
class RolesController
25
{
26
    private RolesService $rolesService;
27
28
    /**
29
     * RolesController constructor.
30
     */
31 12
    public function __construct(RolesService $rolesService)
32
    {
33 12
        $this->rolesService = $rolesService;
34 12
    }
35
36
    /**
37
     * Endpoint action to get current user roles as an array.
38
     *
39
     * @Route(
40
     *     path="/profile/roles",
41
     *     methods={"GET"},
42
     *  );
43
     *
44
     * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
45
     *
46
     * @SWG\Parameter(
47
     *      type="string",
48
     *      name="Authorization",
49
     *      in="header",
50
     *      required=true,
51
     *      description="Authorization header",
52
     *      default="Bearer _your_jwt_here_",
53
     *  )
54
     * @SWG\Response(
55
     *      response=200,
56
     *      description="User roles",
57
     *      @SWG\Schema(
58
     *          type="array",
59
     *          @SWG\Items(type="string"),
60
     *      ),
61
     *  )
62
     * @SWG\Response(
63
     *      response=401,
64
     *      description="Invalid token",
65
     *      @SWG\Schema(
66
     *          type="object",
67
     *          @SWG\Property(property="code", type="integer", description="Error code"),
68
     *          @SWG\Property(property="message", type="string", description="Error description"),
69
     *      ),
70
     *      examples={
71
     *          "Token not found": "{code: 401, message: 'JWT Token not found'}",
72
     *          "Expired token": "{code: 401, message: 'Expired JWT Token'}",
73
     *      },
74
     *  )
75
     * @SWG\Tag(name="Profile")
76
     */
77 5
    public function __invoke(User $loggedInUser): JsonResponse
78
    {
79 5
        return new JsonResponse($this->rolesService->getInheritedRoles($loggedInUser->getRoles()));
80
    }
81
}
82