Failed Conditions
Push — master ( 40346e...66da44 )
by Sylvain
06:49
created

BookableIsAdminOnly   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 2
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\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 the bookable's booking type 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 2
        if ($resource === null) {
29
            return false;
30
        }
31
32
        /** @var Bookable $bookable */
33 2
        $bookable = $resource->getInstance();
34
35 2
        $bookingType = $bookable->getBookingType();
36 2
        if ($bookingType === BookingTypeType::ADMIN_ONLY) {
37 1
            return true;
38
        }
39
40 1
        return $acl->reject('the booking type for this bookable is not admin only, but : ' . $bookingType);
41
    }
42
}
43