StatusIsNew::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\Enum\ExpenseClaimStatus;
8
use Application\Model\ExpenseClaim;
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 StatusIsNew implements NamedAssertion
15
{
16
    public function getName(): string
17
    {
18
        return "la demande n'est pas encore traitée";
19
    }
20
21
    /**
22
     * Assert that the expense claim is new (not processed yet).
23
     *
24
     * @param \Application\Acl\Acl $acl
25
     * @param string $privilege
26
     *
27
     * @return bool
28
     */
29 4
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
30
    {
31
        /** @var ExpenseClaim $expenseClaim */
32 4
        $expenseClaim = $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

32
        /** @scrutinizer ignore-call */ 
33
        $expenseClaim = $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...
33
34 4
        if ($expenseClaim->getStatus() === ExpenseClaimStatus::New) {
35 4
            return true;
36
        }
37
38 2
        return $acl->reject('the expense claim status is not new but instead: ' . $expenseClaim->getStatus()->value);
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

38
        return $acl->/** @scrutinizer ignore-call */ reject('the expense claim status is not new but instead: ' . $expenseClaim->getStatus()->value);
Loading history...
39
    }
40
}
41