IsOwner::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
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Acl\Assertion;
6
7
use Ecodev\Felix\Model\CurrentUser;
8
use Ecodev\Felix\Model\HasOwner;
9
use Laminas\Permissions\Acl\Acl;
10
use Laminas\Permissions\Acl\Resource\ResourceInterface;
11
use Laminas\Permissions\Acl\Role\RoleInterface;
12
13
final class IsOwner implements NamedAssertion
14
{
15
    /**
16
     * Assert that the object belongs to the current user.
17
     *
18
     * @param \Ecodev\Felix\Acl\Acl $acl
19
     * @param ?string $privilege
20
     */
21
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null): bool
22
    {
23
        /** @var HasOwner $object */
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

24
        /** @scrutinizer ignore-call */ 
25
        $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...
25
26
        if (CurrentUser::get() && CurrentUser::get() === $object->getOwner()) {
27
            return true;
28
        }
29
30
        return $acl->reject('the object does not belong to the user');
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

30
        return $acl->/** @scrutinizer ignore-call */ reject('the object does not belong to the user');
Loading history...
31
    }
32
33
    public function getName(): string
34
    {
35
        return _tr("l'objet m'appartient");
36
    }
37
}
38