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

BookingIsPendingApplication   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 33
ccs 7
cts 11
cp 0.6364
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assert() 0 16 4
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\DBAL\Types\BookingStatusType;
8
use Application\DBAL\Types\BookingTypeType;
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 RoleInterface $role
27
     * @param ResourceInterface $resource
28
     * @param string $privilege
29
     *
30
     * @return bool
31
     */
32 1
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
33
    {
34
        /** @var Booking $booking */
35 1
        $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

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

35
        /** @scrutinizer ignore-call */ 
36
        $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...
36
37 1
        $bookable = $booking->getBookable();
38 1
        if (!$bookable) {
39
            return false;
40
        }
41
42 1
        $bookingType = $bookable->getBookingType();
43 1
        if ($booking->getStatus() === BookingStatusType::APPLICATION && in_array($bookingType, [BookingTypeType::APPLICATION, BookingTypeType::ADMIN_APPROVED], true)) {
44 1
            return true;
45
        }
46
47
        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

47
        return $acl->/** @scrutinizer ignore-call */ reject('you cannot delete a processed application');
Loading history...
48
    }
49
}
50