SuggestDeletion   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 16
c 0
b 0
f 0
dl 0
loc 28
ccs 17
cts 17
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 26 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\Enum\ChangeType;
9
use Application\Enum\Site;
10
use Application\Model\Card;
11
use Application\Model\Change;
12
use Application\Repository\ChangeRepository;
13
use Ecodev\Felix\Api\Field\FieldInterface;
14
use GraphQL\Type\Definition\Type;
15
16
class SuggestDeletion implements FieldInterface
17
{
18 1
    public static function build(): iterable
19
    {
20 1
        yield 'suggestDeletion' => fn () => [
21 1
            'type' => Type::nonNull(_types()->getOutput(Change::class)),
22 1
            'description' => 'Suggest the deletion of an existing image',
23 1
            'args' => [
24 1
                'id' => Type::nonNull(_types()->getId(Card::class)),
25 1
                'request' => Type::nonNull(Type::string()),
26 1
            ],
27 1
            'resolve' => function ($root, array $args): Change {
28
                /** @var Site $site */
29 1
                $site = $root['site'];
30
31 1
                $original = $args['id']->getEntity();
32
33
                /** @var ChangeRepository $changeRepository */
34 1
                $changeRepository = _em()->getRepository(Change::class);
35 1
                $change = $changeRepository->getOrCreate(ChangeType::Delete, $original, $args['request'], $site);
36
37 1
                Helper::throwIfDenied($change, 'create');
38
39 1
                if (!$change->getId()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $change->getId() of type integer|null is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
40 1
                    _em()->flush();
41
                }
42
43 1
                return $change;
44 1
            },
45 1
        ];
46
    }
47
}
48