Failed Conditions
Push — master ( 0fd122...b2f91e )
by Adrien
06:52
created

UserByToken::build()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.7861

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 1
nop 0
dl 0
loc 24
ccs 5
cts 12
cp 0.4167
crap 4.7861
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Query;
6
7
use Application\Api\Field\FieldInterface;
8
use Application\Model\User;
9
use Application\Repository\UserRepository;
10
use GraphQL\Type\Definition\Type;
11
12
abstract class UserByToken implements FieldInterface
13
{
14 1
    public static function build(): array
15
    {
16
        return
17
            [
18 1
                'name' => 'userByToken',
19 1
                'type' => _types()->getOutput(User::class),
20 1
                'description' => 'Get a user by its temporary token',
21
                'args' => [
22 1
                    'token' => Type::nonNull(_types()->get('Token')),
23
                ],
24
                'resolve' => function ($root, array $args): ?User {
25
                    /** @var UserRepository $repository */
26
                    $repository = _em()->getRepository(User::class);
27
28
                    /** @var User $user */
29
                    $repository->getAclFilter()->setEnabled(false);
30
                    $user = $repository->findOneByToken($args['token']);
1 ignored issue
show
Bug introduced by
The method findOneByToken() does not exist on Application\Repository\UserRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
                    /** @scrutinizer ignore-call */ 
31
                    $user = $repository->findOneByToken($args['token']);
Loading history...
31
                    $repository->getAclFilter()->setEnabled(true);
32
33
                    if ($user && !$user->isTokenValid()) {
34
                        $user = null;
35
                    }
36
37
                    return $user;
38 1
                },
39
            ];
40
    }
41
}
42