RejectChange::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\Change;
9
use Ecodev\Felix\Api\Field\FieldInterface;
10
use GraphQL\Type\Definition\Type;
11
12
class RejectChange implements FieldInterface
13
{
14 1
    public static function build(): iterable
15
    {
16 1
        yield 'rejectChange' => fn () => [
17 1
            'type' => Type::nonNull(Type::boolean()),
18 1
            'description' => 'Reject the change',
19 1
            'args' => [
20 1
                'id' => Type::nonNull(_types()->getId(Change::class)),
21 1
            ],
22 1
            'resolve' => function ($root, array $args): bool {
23
                /** @var Change $change */
24 1
                $change = $args['id']->getEntity();
25
26 1
                Helper::throwIfDenied($change, 'update');
27
28 1
                _em()->remove($change);
29 1
                _em()->flush();
30
31 1
                return true;
32 1
            },
33 1
        ];
34
    }
35
}
36