Visibility   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
c 0
b 0
f 0
dl 0
loc 37
rs 10
ccs 5
cts 7
cp 0.7143

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assert() 0 6 1
A __construct() 0 3 1
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\Enum\CollectionVisibility;
8
use Application\Model\Card;
9
use Application\Model\Collection;
10
use Ecodev\Felix\Acl\Assertion\NamedAssertion;
11
use Ecodev\Felix\Acl\ModelResource;
12
use Laminas\Permissions\Acl\Acl;
13
use Laminas\Permissions\Acl\Resource\ResourceInterface;
14
use Laminas\Permissions\Acl\Role\RoleInterface;
15
16
class Visibility implements NamedAssertion
17
{
18
    /**
19
     * @var string[]
20
     */
21
    private readonly array $allowedVisibilitiesValues;
22
23
    public function getName(): string
24
    {
25
        return 'la visibilité est ' . implode(' ou ', $this->allowedVisibilitiesValues);
26
    }
27
28
    /**
29
     * @param CollectionVisibility[] $allowedVisibilities
30
     */
31 35
    public function __construct(private readonly array $allowedVisibilities)
32
    {
33 35
        $this->allowedVisibilitiesValues = array_map(fn (CollectionVisibility $type) => $type->value, $this->allowedVisibilities);
0 ignored issues
show
Bug introduced by
The property allowedVisibilitiesValues is declared read-only in Application\Acl\Assertion\Visibility.
Loading history...
34
    }
35
36
    /**
37
     * Assert that the object is the given visibility,
38
     * or belongs to the current user,
39
     * or has been created by the current user.
40
     *
41
     * @param \Application\Acl\Acl $acl
42
     * @param ModelResource $resource
43
     * @param string $privilege
44
     *
45
     * @return bool
46
     */
47 1
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null)
48
    {
49
        /** @var Card|Collection $object */
50 1
        $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

50
        /** @scrutinizer ignore-call */ 
51
        $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

50
        /** @scrutinizer ignore-call */ 
51
        $object = $resource->getInstance();
Loading history...
51
52 1
        return in_array($object->getVisibility(), $this->allowedVisibilities, true);
53
    }
54
}
55