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

UserByToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 41.67%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 26
ccs 5
cts 12
cp 0.4167
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 24 3
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