Failed Conditions
Pull Request — master (#13)
by Adrien
05:33 queued 02:11
created

IsMyself   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 26
ccs 6
cts 7
cp 0.8571
rs 10
wmc 4

2 Methods

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

26
        /** @scrutinizer ignore-call */ 
27
        $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...
Bug introduced by
The method getInstance() does not exist on Laminas\Permissions\Acl\Resource\ResourceInterface. ( Ignorable by Annotation )

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

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

32
        return $acl->/** @scrutinizer ignore-call */ reject('it is not himself');
Loading history...
33
    }
34
35 2
    public function getName(): string
36
    {
37 2
        return _tr("c'est moi-même");
38
    }
39
}
40