Conditions | 3 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 4.7861 |
Changes | 0 |
1 | <?php |
||
15 | 1 | public static function build(): array |
|
16 | { |
||
17 | return |
||
18 | [ |
||
19 | 1 | 'name' => 'userByToken', |
|
20 | 1 | 'type' => Type::nonNull(_types()->getOutput(User::class)), |
|
21 | 1 | 'description' => 'Get a user by its temporary token', |
|
22 | 'args' => [ |
||
23 | 1 | 'token' => Type::nonNull(_types()->get('Token')), |
|
1 ignored issue
–
show
|
|||
24 | ], |
||
25 | 'resolve' => function ($root, array $args): User { |
||
26 | /** @var UserRepository $repository */ |
||
27 | $repository = _em()->getRepository(User::class); |
||
28 | |||
29 | /** @var User $user */ |
||
30 | $user = $repository->getAclFilter()->runWithoutAcl(function () use ($repository, $args) { |
||
31 | return $repository->findOneByToken($args['token']); |
||
1 ignored issue
–
show
|
|||
32 | }); |
||
33 | |||
34 | if (!$user || !$user->isTokenValid()) { |
||
35 | throw new Exception('User not found for token `' . $args['token'] . '`.'); |
||
36 | } |
||
37 | |||
38 | // Set current user for his ACL, but not in persisted session, only for the remaining execution time. |
||
39 | // He will have to go through a proper login to persist the session. |
||
40 | User::setCurrent($user); |
||
41 | |||
42 | return $user; |
||
43 | 1 | }, |
|
47 |