User::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @see https://github.com/ecphp
8
 */
9
10
declare(strict_types=1);
11
12
namespace EcPhp\ApiGwAuthenticationBundle\Controller;
13
14
use EcPhp\ApiGwAuthenticationBundle\Security\Core\User\ApiGwAuthenticationUserInterface;
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
use Symfony\Component\Security\Core\Security;
17
18
final class User
19
{
20
    public function __invoke(Security $security): JsonResponse
21
    {
22
        $user = $security->getUser();
23
24
        if ($user instanceof ApiGwAuthenticationUserInterface) {
25
            return new JsonResponse($user->getAttributes());
26
        }
27
28
        return new JsonResponse([], 404);
29
    }
30
}
31