Failed Conditions
Push — master ( 986579...afd61f )
by
unknown
06:25
created

TerminateBooking::build()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.944

Importance

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

27
            '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...
28
                $booking = $args['id']->getEntity();
29
30
                // Check ACL
31
                Helper::throwIfDenied($booking, 'update');
32
33
                // Booking can only be terminated once
34
                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

34
                if (!$booking->/** @scrutinizer ignore-call */ getEndDate()) {
Loading history...
35
                    $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

35
                    $booking->/** @scrutinizer ignore-call */ 
36
                              setEndDate(Utility::getNow());
Loading history...
36
                    $booking->setStatus(BookingStatusType::BOOKED);
0 ignored issues
show
Bug introduced by
The method setStatus() 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
                              setStatus(BookingStatusType::BOOKED);
Loading history...
37
                    if (@$args['comment']) {
38
                        $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

38
                        $booking->/** @scrutinizer ignore-call */ 
39
                                  setEndComment($args['comment']);
Loading history...
39
                    }
40
                    _em()->flush();
41
                }
42
43
                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...
44 1
            },
45
        ];
46
    }
47
}
48