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

ExpenseClaimStatusIsNew::assert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 4
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
crap 2.0116
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\Model\AccountingDocument;
8
use Application\Model\ExpenseClaim;
9
use Ecodev\Felix\Acl\Assertion\NamedAssertion;
10
use Ecodev\Felix\Acl\ModelResource;
1 ignored issue
show
Bug introduced by
The type Ecodev\Felix\Acl\ModelResource was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Laminas\Permissions\Acl\Acl;
12
use Laminas\Permissions\Acl\Resource\ResourceInterface;
13
use Laminas\Permissions\Acl\Role\RoleInterface;
14
15
class ExpenseClaimStatusIsNew implements NamedAssertion
16
{
17
    public function getName(): string
18
    {
19
        return "la demande liée n'est pas encore traitée";
20
    }
21
22
    /**
23
     * Assert that the accounting document's expense claim is new (not processed yet).
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 3
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
33
    {
34
        /** @var AccountingDocument $instance */
35 3
        $instance = $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
        $instance = $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
        $instance = $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 3
        $expenseClaim = $instance->getExpenseClaim();
37
38 3
        if (!$expenseClaim) {
39
            return true;
40
        }
41
42 3
        $assertion = new StatusIsNew();
43
44 3
        return $assertion->assert($acl, $role, new ModelResource(ExpenseClaim::class, $expenseClaim), $privilege);
45
    }
46
}
47