Passed
Push — master ( 66527c...eb5eca )
by Adrien
07:11
created

LeaveFamily   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 28 1
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\Helper;
9
use Application\DBAL\Types\RelationshipType;
10
use Application\Model\User;
11
use GraphQL\Type\Definition\Type;
12
use Zend\Expressive\Session\SessionInterface;
13
14
abstract class LeaveFamily implements FieldInterface
15
{
16 1
    public static function build(): array
17
    {
18
        return [
19 1
            'name' => 'leaveFamily',
20 1
            'type' => Type::nonNull(_types()->getOutput(User::class)),
21 1
            'description' => 'Make the given user independent from his family and inactive.',
22
            'args' => [
23 1
                'id' => Type::nonNull(_types()->getId(User::class)),
24
            ],
25
            'resolve' => function ($root, array $args, SessionInterface $session): User {
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

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

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...
26
                /** @var User $user */
27 1
                $user = $args['id']->getEntity();
28
29
                // Check ACL
30 1
                Helper::throwIfDenied($user, 'update');
31
32
                // Set owner while pretending we are an admin to workaround normal security things
33 1
                $previousCurrentUser = User::getCurrent();
34 1
                User::setCurrent(new User(User::ROLE_ADMINISTRATOR));
35 1
                $user->setOwner($user);
36 1
                User::setCurrent($previousCurrentUser);
37
38 1
                $user->setFamilyRelationship(RelationshipType::HOUSEHOLDER);
39 1
                $user->setStatus(User::STATUS_INACTIVE);
40
41 1
                _em()->flush();
42
43 1
                return $user;
44 1
            },
45
        ];
46
    }
47
}
48