Completed
Push — master ( 34d4a4...058229 )
by Sam
06:33
created

TerminateBooking::build()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.679

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 1
nop 0
dl 0
loc 26
ccs 6
cts 14
cp 0.4286
crap 4.679
rs 9.7333
c 0
b 0
f 0
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\Model\Booking;
10
use Application\Utility;
11
use GraphQL\Type\Definition\Type;
12
use Zend\Expressive\Session\SessionInterface;
13
14
abstract class TerminateBooking implements FieldInterface
15
{
16 1
    public static function build(): array
17
    {
18
        return [
19 1
            'name' => 'terminateBooking',
20 1
            'type' => Type::nonNull(_types()->getOutput(Booking::class)),
21 1
            'description' => 'Terminate a booking',
22
            'args' => [
23 1
                'id' => Type::nonNull(_types()->getId(Booking::class)),
24 1
                'comment' => Type::string(),
25
            ],
26
            'resolve' => function ($root, array $args, SessionInterface $session): Booking {
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

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

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...
27
                $booking = $args['id']->getEntity();
28
29
                // Check ACL
30
                Helper::throwIfDenied($booking, 'update');
31
32
                // Booking can only be terminated once
33
                if (!$booking->getEndDate()) {
0 ignored issues
show
Bug introduced by
The method getEndDate() does not exist on Application\Model\AbstractModel. It seems like you code against a sub-type of Application\Model\AbstractModel such as Application\Model\Booking. ( Ignorable by Annotation )

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

33
                if (!$booking->/** @scrutinizer ignore-call */ getEndDate()) {
Loading history...
34
                    $booking->setEndDate(Utility::getNow());
0 ignored issues
show
Bug introduced by
The method setEndDate() does not exist on Application\Model\AbstractModel. It seems like you code against a sub-type of Application\Model\AbstractModel such as Application\Model\Booking. ( Ignorable by Annotation )

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

34
                    $booking->/** @scrutinizer ignore-call */ 
35
                              setEndDate(Utility::getNow());
Loading history...
35
                    if (@$args['comment']) {
36
                        $booking->setEndComment($args['comment']);
0 ignored issues
show
Bug introduced by
The method setEndComment() does not exist on Application\Model\AbstractModel. It seems like you code against a sub-type of Application\Model\AbstractModel such as Application\Model\Booking. ( Ignorable by Annotation )

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

36
                        $booking->/** @scrutinizer ignore-call */ 
37
                                  setEndComment($args['comment']);
Loading history...
37
                    }
38
                    _em()->flush();
39
                }
40
41
                return $booking;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $booking returns the type Application\Model\AbstractModel which includes types incompatible with the type-hinted return Application\Model\Booking.
Loading history...
42 1
            },
43
        ];
44
    }
45
}
46