Failed Conditions
Push — master ( 453060...5207b4 )
by Sam
13:38
created

BookingIsSelfApproved   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 14 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
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
27
    {
28
        /** @var Booking $booking */
29
        $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
        if (!$booking->getBookable()) {
32
            return true;
33
        }
34
35
        if ($booking->getBookable()->getBookingType() === BookingTypeType::SELF_APPROVED) {
36
            return true;
37
        }
38
39
        return $acl->reject('the bookable type for this booking is not self approved, but : ' . $booking->getBookable()->getBookingType());
40
    }
41
}
42