BookingIsPendingApplication::assert()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 4
crap 4.1755
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\Enum\BookingStatus;
8
use Application\Enum\BookingType;
9
use Application\Model\Booking;
10
use Ecodev\Felix\Acl\Assertion\NamedAssertion;
11
use Laminas\Permissions\Acl\Acl;
12
use Laminas\Permissions\Acl\Resource\ResourceInterface;
13
use Laminas\Permissions\Acl\Role\RoleInterface;
14
15
class BookingIsPendingApplication implements NamedAssertion
16
{
17
    public function getName(): string
18
    {
19
        return 'le réservable est pas encore confirmé';
20
    }
21
22
    /**
23
     * Assert that a booking is a pending application.
24
     *
25
     * @param \Application\Acl\Acl $acl
26
     * @param string $privilege
27
     *
28
     * @return bool
29
     */
30 1
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
31
    {
32
        /** @var Booking $booking */
33 1
        $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

33
        /** @scrutinizer ignore-call */ 
34
        $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...
34
35 1
        $bookable = $booking->getBookable();
36 1
        if (!$bookable) {
37
            return false;
38
        }
39
40 1
        $bookingType = $bookable->getBookingType();
41 1
        if ($booking->getStatus() === BookingStatus::Application && in_array($bookingType, [BookingType::Application, BookingType::AdminApproved], true)) {
42 1
            return true;
43
        }
44
45
        return $acl->reject('you cannot delete a processed application');
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('you cannot delete a processed application');
Loading history...
46
    }
47
}
48