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

IsMyself   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Acl\Assertion;
6
7
use Ecodev\Felix\Model\CurrentUser;
8
use Laminas\Permissions\Acl\Acl;
9
use Laminas\Permissions\Acl\Assertion\AssertionInterface;
10
use Laminas\Permissions\Acl\Resource\ResourceInterface;
11
use Laminas\Permissions\Acl\Role\RoleInterface;
12
13
class IsMyself implements AssertionInterface
14
{
15
    /**
16
     * Assert that the user is the current user himself
17
     *
18
     * @param \Ecodev\Felix\Acl\Acl $acl
19
     * @param RoleInterface $role
20
     * @param ResourceInterface $resource
21
     * @param string $privilege
22
     *
23
     * @return bool
24
     */
25 1
    public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
26
    {
27 1
        $user = $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

27
        /** @scrutinizer ignore-call */ 
28
        $user = $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

27
        /** @scrutinizer ignore-call */ 
28
        $user = $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...
28
29 1
        if (CurrentUser::get() && CurrentUser::get() === $user) {
30
            return true;
31
        }
32
33 1
        return $acl->reject('it is not himself');
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

33
        return $acl->/** @scrutinizer ignore-call */ reject('it is not himself');
Loading history...
34
    }
35
}
36