SameSite   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 3
eloc 4
dl 0
loc 22
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A assert() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\Model\User;
8
use Application\Traits\HasSiteInterface;
9
use Ecodev\Felix\Acl\Assertion\NamedAssertion;
10
use Ecodev\Felix\Acl\ModelResource;
11
use Laminas\Permissions\Acl\Acl;
12
use Laminas\Permissions\Acl\Resource\ResourceInterface;
13
use Laminas\Permissions\Acl\Role\RoleInterface;
14
15
class SameSite implements NamedAssertion
16
{
17
    public function getName(): string
18
    {
19
        return "l'objet appartient au même site que moi-même";
20
    }
21
22
    /**
23
     * Assert that the object has been created by the current user.
24
     *
25
     * @param \Application\Acl\Acl $acl
26
     * @param ModelResource $resource
27
     * @param string $privilege
28
     *
29
     * @return bool
30
     */
31 24
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
32
    {
33
        /** @var HasSiteInterface $object */
34 24
        $object = $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

34
        /** @scrutinizer ignore-call */ 
35
        $object = $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 Laminas\Permissions\Acl\Resource\ResourceInterface. It seems like you code against a sub-type of Laminas\Permissions\Acl\Resource\ResourceInterface such as Ecodev\Felix\Acl\ModelResource. ( 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
        $object = $resource->getInstance();
Loading history...
35
36 24
        return User::getCurrent() && User::getCurrent()->getSite() === $object->getSite();
37
    }
38
}
39