Failed Conditions
Push — master ( cdc595...f2bb18 )
by Adrien
02:12
created

IsOwner::assert()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 12
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\Assertion\AssertionInterface;
11
use Laminas\Permissions\Acl\Resource\ResourceInterface;
12
use Laminas\Permissions\Acl\Role\RoleInterface;
13
14
class IsOwner implements AssertionInterface
15
{
16
    /**
17
     * Assert that the object belongs to the current user
18
     *
19
     * @param \Ecodev\Felix\Acl\Acl $acl
20
     * @param RoleInterface $role
21
     * @param ResourceInterface $resource
22
     * @param string $privilege
23
     *
24
     * @return bool
25
     */
26
    public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
27
    {
28
        /** @var HasOwner $object */
29
        $object = $resource->getInstance();
1 ignored issue
show
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

29
        /** @scrutinizer ignore-call */ 
30
        $object = $resource->getInstance();
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

29
        /** @scrutinizer ignore-call */ 
30
        $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...
30
31
        if (CurrentUser::get() && CurrentUser::get() === $object->getOwner()) {
32
            return true;
33
        }
34
35
        return $acl->reject('the object does not belong to the user');
1 ignored issue
show
introduced by
The method reject() does not exist on Laminas\Permissions\Acl\Acl. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        return $acl->/** @scrutinizer ignore-call */ reject('the object does not belong to the user');
Loading history...
36
    }
37
}
38