Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — 0.13 (#633)
by Jérémiah
41:38 queued 16:44
created

Security::hasAnyPermission()

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 8
c 1
b 0
f 0
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Security;
6
7
use Symfony\Component\Security\Core\Security as CoreSecurity;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
10
final class Security
11
{
12
    private $coreSecurity;
13
14
    public function __construct(?CoreSecurity $security)
15
    {
16
        $this->coreSecurity = $security ?? new class() {
17
            public function isGranted(): void
18
            {
19
                throw new \LogicException('The "symfony/security-core" component is required.');
20
            }
21
22
            public function getUser(): void
23
            {
24
                throw new \LogicException('The "symfony/security-core" component is required.');
25
            }
26
        };
27
    }
28
29
    public function getUser(): ?UserInterface
30
    {
31
        return $this->coreSecurity->getUser();
32
    }
33
34
    public function isGranted($attributes, $subject = null): bool
35
    {
36
        return $this->coreSecurity->isGranted($attributes, $subject);
0 ignored issues
show
Unused Code introduced by
The call to anonymous//src/Security/...rity.php$0::isGranted() has too many arguments starting with $attributes. ( Ignorable by Annotation )

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

36
        return $this->coreSecurity->/** @scrutinizer ignore-call */ isGranted($attributes, $subject);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
37
    }
38
39
    public function hasAnyPermission($object, array $permissions): bool
40
    {
41
        return \array_reduce(
42
            $permissions,
43
            function ($isGranted, $permission) use ($object) {
44
                return $isGranted || $this->isGranted($permission, $object);
45
            },
46
            false
47
        );
48
    }
49
50
    public function hasAnyRole(array $roles): bool
51
    {
52
        return \array_reduce(
53
            $roles,
54
            function ($isGranted, $role) {
55
                return $isGranted || $this->isGranted($role);
56
            },
57
            false
58
        );
59
    }
60
61
    public function hasPermission($object, $permission): bool
62
    {
63
        return $this->isGranted($permission, $object);
64
    }
65
66
    public function hasRole($role): bool
67
    {
68
        return $this->isGranted($role);
69
    }
70
71
    public function isAnonymous(): bool
72
    {
73
        return $this->isGranted('IS_AUTHENTICATED_ANONYMOUSLY');
74
    }
75
76
    public function isAuthenticated(): bool
77
    {
78
        return $this->hasAnyRole(['IS_AUTHENTICATED_REMEMBERED', 'IS_AUTHENTICATED_FULLY']);
79
    }
80
81
    public function isFullyAuthenticated(): bool
82
    {
83
        return $this->isGranted('IS_AUTHENTICATED_FULLY');
84
    }
85
86
    public function isRememberMe(): bool
87
    {
88
        return $this->isGranted('IS_AUTHENTICATED_REMEMBERED');
89
    }
90
}
91