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

BookableIsAdminOnly   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 23
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 11 2
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\Bookable;
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 BookableIsAdminOnly implements AssertionInterface
15
{
16
    /**
17
     * Assert that booking is admin only
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 2
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
27
    {
28
        /** @var Bookable $bookable */
29 2
        $bookable = $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
        $bookable = $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 2
        $bookingType = $bookable->getBookingType();
32 2
        if ($bookingType === BookingTypeType::ADMIN_ONLY) {
33 1
            return true;
34
        }
35
36 1
        return $acl->reject('the booking type for this bookable is not admin only, but : ' . $bookingType);
37
    }
38
}
39