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

BookingIsSelfApproved::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
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 10
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\Booking;
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 BookingIsSelfApproved implements NamedAssertion
15
{
16
    public function getName(): string
17
    {
18
        return 'la réséveration est un carnet de sortie';
19
    }
20
21
    /**
22
     * Assert that booking's bookable is self approved (boats) or has no bookable.
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 3
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
32
    {
33
        /** @var Booking $booking */
34 3
        $booking = $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

34
        /** @scrutinizer ignore-call */ 
35
        $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...
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

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