Failed Conditions
Push — master ( 0b3886...ea22ef )
by Adrien
04:31
created

RequestUserDeletion::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 29
ccs 16
cts 16
cp 1
rs 9.7666
c 1
b 0
f 0
cc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Api\Helper;
8
use Application\Model\User;
9
use Application\Service\MessageQueuer;
10
use Ecodev\Felix\Api\Field\FieldInterface;
11
use Ecodev\Felix\Service\Mailer;
12
use GraphQL\Type\Definition\Type;
13
14
abstract class RequestUserDeletion implements FieldInterface
15
{
16 1
    public static function build(): iterable
17
    {
18 1
        yield 'requestUserDeletion' => fn () => [
19 1
            'type' => Type::nonNull(Type::boolean()),
20 1
            'description' => 'Send an email to admins to delete the given user',
21 1
            'args' => [
22 1
                'id' => Type::nonNull(_types()->getId(User::class)),
23 1
            ],
24 1
            'resolve' => function ($root, array $args): bool {
25
                /** @var User $user */
26 1
                $user = $args['id']->getEntity();
27
28
                // Check ACL
29
                // Assume that if we can update, then we can request to delete
30 1
                Helper::throwIfDenied($user, 'update');
31
32
                global $container;
33
                /** @var Mailer $mailer */
34 1
                $mailer = $container->get(Mailer::class);
35
36
                /** @var MessageQueuer $messageQueuer */
37 1
                $messageQueuer = $container->get(MessageQueuer::class);
38
39 1
                $message = $messageQueuer->queueRequestUserDeletion(User::getCurrent(), $user);
0 ignored issues
show
Bug introduced by
It seems like Application\Model\User::getCurrent() can also be of type null; however, parameter $requestingUser of Application\Service\Mess...ueRequestUserDeletion() does only seem to accept Application\Model\User, maybe add an additional type check? ( Ignorable by Annotation )

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

39
                $message = $messageQueuer->queueRequestUserDeletion(/** @scrutinizer ignore-type */ User::getCurrent(), $user);
Loading history...
40 1
                if ($message) {
41 1
                    $mailer->sendMessageAsync($message);
42
                }
43
44 1
                return true;
45 1
            },
46 1
        ];
47
    }
48
}
49