Failed Conditions
Push — master ( 4252f4...9d8e13 )
by Adrien
07:13
created

UpdatePassword   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 27 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Api\Field\FieldInterface;
8
use Application\Api\Scalar\PasswordType;
9
use Application\Api\Scalar\TokenType;
10
use Application\Model\User;
11
use Application\Repository\UserRepository;
12
use GraphQL\Type\Definition\Type;
13
use Zend\Expressive\Session\SessionInterface;
14
15
abstract class UpdatePassword implements FieldInterface
16
{
17 2
    public static function build(): array
18
    {
19
        return [
20 1
            'name' => 'updatePassword',
21 1
            'type' => Type::nonNull(Type::boolean()),
22 1
            'description' => 'Update the password for the user identified by the token. Return false if token is invalid',
23
            'args' => [
24 1
                'token' => Type::nonNull(_types()->get(TokenType::class)),
25 1
                'password' => Type::nonNull(_types()->get(PasswordType::class)),
26
            ],
27
            'resolve' => function ($root, array $args, SessionInterface $session): bool {
1 ignored issue
show
Unused Code introduced by
The parameter $session is not used and could be removed. ( Ignorable by Annotation )

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

27
            'resolve' => function ($root, array $args, /** @scrutinizer ignore-unused */ SessionInterface $session): bool {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
                /** @var UserRepository $repository */
29 2
                $repository = _em()->getRepository(User::class);
30
31
                /** @var User $user */
32 2
                $repository->getAclFilter()->setEnabled(false);
33 2
                $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

33
                /** @scrutinizer ignore-call */ 
34
                $user = $repository->findOneByToken($args['token']);
Loading history...
34 2
                $repository->getAclFilter()->setEnabled(true);
35
36 2
                if (!$user || !$user->isTokenValid()) {
37 1
                    return false;
38
                }
39
40 1
                $user->setPassword($args['password']);
41 1
                _em()->flush();
42
43 1
                return true;
44 1
            },
45
        ];
46
    }
47
}
48