• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

overblog / GraphQLBundle / 13084981376

19 Dec 2024 02:51PM UTC coverage: 98.368%. Remained the same
13084981376

push

github

web-flow
Merge pull request #1197 from maximecolin/patch-4

Fix typo in attributes documentation

4339 of 4411 relevant lines covered (98.37%)

39.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/src/Security/Security.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Overblog\GraphQLBundle\Security;
6

7
use LogicException;
8
use Symfony\Bundle\SecurityBundle\Security as BundleSecurity;
9
use Symfony\Component\HttpKernel\Kernel;
10
use Symfony\Component\Security\Core\Security as CoreSecurity;
11
use Symfony\Component\Security\Core\User\UserInterface;
12

13
use function array_reduce;
14

15
if (Kernel::VERSION_ID >= 60200) {
2✔
16
    final class Security extends BaseSecurity
17
    {
18
        public function __construct(?BundleSecurity $security)
19
        {
20
            parent::__construct($security);
×
21
        }
×
22
    }
23
} else {
24
    final class Security extends BaseSecurity
25
    {
26
        public function __construct(?CoreSecurity $security)
27
        {
28
            parent::__construct($security);
37✔
29
        }
37✔
30
    }
31
}
32

33
abstract class BaseSecurity
34
{
35
    /**
36
     * @var CoreSecurity|BundleSecurity
37
     */
38
    private $coreSecurity;
39

40
    /**
41
     * @param CoreSecurity|BundleSecurity $security
42
     */
43
    public function __construct($security)
44
    {
45
        // @phpstan-ignore-next-line
46
        $this->coreSecurity = $security ?? new class() {
37✔
47
            public function isGranted(): bool
48
            {
49
                throw new LogicException('The "symfony/security-core" component is required.');
1✔
50
            }
51

52
            public function getUser(): UserInterface
53
            {
54
                throw new LogicException('The "symfony/security-core" component is required.');
1✔
55
            }
56
        };
57
    }
37✔
58

59
    public function getUser(): ?UserInterface
60
    {
61
        return $this->coreSecurity->getUser();
6✔
62
    }
63

64
    /**
65
     * @param mixed $attributes
66
     * @param mixed $subject
67
     */
68
    public function isGranted($attributes, $subject = null): bool
69
    {
70
        return $this->coreSecurity->isGranted($attributes, $subject);
31✔
71
    }
72

73
    public function hasAnyPermission(object $object, array $permissions): bool
74
    {
75
        return array_reduce(
2✔
76
            $permissions,
2✔
77
            fn ($isGranted, $permission) => $isGranted || $this->isGranted($permission, $object),
2✔
78
            false
2✔
79
        );
80
    }
81

82
    public function hasAnyRole(array $roles): bool
83
    {
84
        return array_reduce(
4✔
85
            $roles,
4✔
86
            fn ($isGranted, $role) => $isGranted || $this->isGranted($role),
4✔
87
            false
4✔
88
        );
89
    }
90

91
    /**
92
     * @param mixed $object
93
     * @param mixed $permission
94
     */
95
    public function hasPermission($object, $permission): bool
96
    {
97
        return $this->isGranted($permission, $object);
2✔
98
    }
99

100
    public function hasRole(string $role): bool
101
    {
102
        return $this->isGranted($role);
8✔
103
    }
104

105
    public function isAnonymous(): bool
106
    {
107
        return $this->isGranted('IS_AUTHENTICATED_ANONYMOUSLY');
2✔
108
    }
109

110
    public function isAuthenticated(): bool
111
    {
112
        return $this->hasAnyRole(['IS_AUTHENTICATED_REMEMBERED', 'IS_AUTHENTICATED_FULLY']);
2✔
113
    }
114

115
    public function isFullyAuthenticated(): bool
116
    {
117
        return $this->isGranted('IS_AUTHENTICATED_FULLY');
6✔
118
    }
119

120
    public function isRememberMe(): bool
121
    {
122
        return $this->isGranted('IS_AUTHENTICATED_REMEMBERED');
2✔
123
    }
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc