Failed Conditions
Push — master ( 2695cf...ba7e19 )
by Sylvain
08:48 queued 11s
created

BookingIsPendingApplication   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
dl 0
loc 28
ccs 7
cts 9
cp 0.7778
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\DBAL\Types\BookingStatusType;
8
use Application\DBAL\Types\BookingTypeType;
9
use Application\Model\Booking;
10
use Laminas\Permissions\Acl\Acl;
11
use Laminas\Permissions\Acl\Assertion\AssertionInterface;
12
use Laminas\Permissions\Acl\Resource\ResourceInterface;
13
use Laminas\Permissions\Acl\Role\RoleInterface;
14
15
class BookingIsPendingApplication implements AssertionInterface
16
{
17
    /**
18
     * Assert that a booking is a pending application
19
     *
20
     * @param \Application\Acl\Acl $acl
21
     * @param RoleInterface $role
22
     * @param ResourceInterface $resource
23
     * @param string $privilege
24
     *
25
     * @return bool
26
     */
27 1
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
28
    {
29
        /** @var Booking $booking */
30 1
        $booking = $resource->getInstance();
0 ignored issues
show
Bug introduced by
The method getInstance() does not exist on null. ( Ignorable by Annotation )

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

30
        /** @scrutinizer ignore-call */ 
31
        $booking = $resource->getInstance();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
32 1
        $bookable = $booking->getBookable();
33 1
        if (!$bookable) {
34
            return false;
35
        }
36
37 1
        $bookingType = $bookable->getBookingType();
38 1
        if ($booking->getStatus() === BookingStatusType::APPLICATION && in_array($bookingType, [BookingTypeType::APPLICATION, BookingTypeType::ADMIN_APPROVED], true)) {
39 1
            return true;
40
        }
41
42
        return $acl->reject('you cannot delete a processed application');
43
    }
44
}
45