Failed Conditions
Push — master ( e9ca52...479d22 )
by Adrien
10:20
created

IsOwner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl\Assertion;
6
7
use Application\Model\AbstractModel;
8
use Application\Model\User;
9
use Zend\Permissions\Acl\Acl;
10
use Zend\Permissions\Acl\Assertion\AssertionInterface;
11
use Zend\Permissions\Acl\Resource\ResourceInterface;
12
use Zend\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 \Application\Acl\Acl $acl
20
     * @param RoleInterface $role
21
     * @param ResourceInterface $resource
22
     * @param string $privilege
23
     *
24
     * @return bool
25
     */
26 4
    public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
27
    {
28
        /** @var AbstractModel $object */
29 4
        $object = $resource->getInstance();
0 ignored issues
show
Bug introduced by
The method getInstance() does not exist on Zend\Permissions\Acl\Resource\ResourceInterface. It seems like you code against a sub-type of Zend\Permissions\Acl\Resource\ResourceInterface such as Application\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 4
        if (User::getCurrent() && User::getCurrent() === $object->getOwner()) {
32 4
            return true;
33
        }
34
35
        return $acl->reject('the object does not belong to the user');
0 ignored issues
show
introduced by
The method reject() does not exist on Zend\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