Failed Conditions
Push — master ( dfb37d...2871bb )
by Adrien
06:38
created

BookingIsSelfApproved   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 27
ccs 7
cts 8
cp 0.875
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\DBAL\Types\BookingTypeType;
8
use Application\Model\Booking;
9
use Laminas\Permissions\Acl\Acl;
10
use Laminas\Permissions\Acl\Assertion\AssertionInterface;
11
use Laminas\Permissions\Acl\Resource\ResourceInterface;
12
use Laminas\Permissions\Acl\Role\RoleInterface;
13
14
class BookingIsSelfApproved implements AssertionInterface
15
{
16
    /**
17
     * Assert that booking's bookable is self approved (boats) or has no bookable
18
     *
19
     * @param \Application\Acl\Acl $acl
20
     * @param RoleInterface $role
21
     * @param ResourceInterface $resource
22
     * @param string $privilege
23
     *
24
     * @return bool
25
     */
26 3
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
27
    {
28
        /** @var Booking $booking */
29 3
        $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

29
        /** @scrutinizer ignore-call */ 
30
        $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...
30
31 3
        if (!$booking->getBookable()) {
32
            return true;
33
        }
34
35 3
        $bookingType = $booking->getBookable()->getBookingType();
36 3
        if ($bookingType === BookingTypeType::SELF_APPROVED) {
37 1
            return true;
38
        }
39
40 2
        return $acl->reject('the booking type for this booking is not self approved, but : ' . $bookingType);
41
    }
42
}
43