TerminateBooking::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 20
ccs 14
cts 14
cp 1
rs 9.8666
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\Booking;
9
use Ecodev\Felix\Api\Field\FieldInterface;
10
use GraphQL\Type\Definition\Type;
11
use Mezzio\Session\SessionInterface;
12
13
abstract class TerminateBooking implements FieldInterface
14
{
15 4
    public static function build(): iterable
16
    {
17 1
        yield 'terminateBooking' => fn () => [
18 1
            'type' => Type::nonNull(_types()->getOutput(Booking::class)),
19 1
            'description' => 'Terminate a booking',
20 1
            'args' => [
21 1
                'id' => Type::nonNull(_types()->getId(Booking::class)),
22 1
                'comment' => Type::string(),
23 1
            ],
24 1
            'resolve' => function ($root, array $args, SessionInterface $session): Booking {
25
                /** @var Booking $booking */
26 4
                $booking = $args['id']->getEntity();
27
28
                // Check ACL
29 4
                Helper::throwIfDenied($booking, 'update');
30
31 3
                $booking->terminate($args['comment'] ?? null);
32 3
                _em()->flush();
33
34 3
                return $booking;
35 1
            },
36 1
        ];
37
    }
38
}
39