Passed
Push — master ( 58ac10...e3c27b )
by Adrien
05:30
created

BookableIsAdminApproved::assert()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 4
crap 3.0175
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 Ecodev\Felix\Acl\Assertion\NamedAssertion;
10
use Laminas\Permissions\Acl\Acl;
11
use Laminas\Permissions\Acl\Resource\ResourceInterface;
12
use Laminas\Permissions\Acl\Role\RoleInterface;
13
14
class BookableIsAdminApproved implements NamedAssertion
15
{
16
    public function getName(): string
17
    {
18
        return 'le réservable est un cours';
19
    }
20
21
    /**
22
     * Assert that the bookable's booking type is admin approved.
23
     *
24
     * @param \Application\Acl\Acl $acl
25
     * @param RoleInterface $role
26
     * @param ResourceInterface $resource
27
     * @param string $privilege
28
     *
29
     * @return bool
30
     */
31 2
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
32
    {
33 2
        if ($resource === null) {
34
            return false;
35
        }
36
37
        /** @var Bookable $bookable */
38 2
        $bookable = $resource->getInstance();
0 ignored issues
show
Bug introduced by
The method getInstance() does not exist on Laminas\Permissions\Acl\Resource\ResourceInterface. ( Ignorable by Annotation )

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

38
        /** @scrutinizer ignore-call */ 
39
        $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...
39
40 2
        $bookingType = $bookable->getBookingType();
41 2
        if ($bookingType === BookingTypeType::ADMIN_APPROVED) {
42 1
            return true;
43
        }
44
45 1
        return $acl->reject('the booking type for this bookable is not admin approved, but : ' . $bookingType);
0 ignored issues
show
Bug introduced by
The method reject() does not exist on Laminas\Permissions\Acl\Acl. It seems like you code against a sub-type of Laminas\Permissions\Acl\Acl such as Ecodev\Felix\Acl\Acl. ( Ignorable by Annotation )

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

45
        return $acl->/** @scrutinizer ignore-call */ reject('the booking type for this bookable is not admin approved, but : ' . $bookingType);
Loading history...
46
    }
47
}
48