| Conditions | 4 |
| Paths | 2 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | public function hasRole($role, UserInterface $user = null) |
||
| 35 | { |
||
| 36 | if (null === $user) { |
||
| 37 | return $this->authorizationChecker->isGranted($role); |
||
| 38 | } |
||
| 39 | |||
| 40 | $roles = $this->roleHierarchy->getReachableRoles(array_map(function ($role) { |
||
| 41 | if (is_string($role)) { |
||
| 42 | return new Role($role); |
||
| 43 | } elseif (!$role instanceof RoleInterface) { |
||
| 44 | throw new \InvalidArgumentException(sprintf('$roles must be an array of strings, or RoleInterface instances, but got %s.', gettype($role))); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $role; |
||
| 48 | }, $user->getRoles())); |
||
| 49 | |||
| 50 | return in_array(new Role($role), $roles); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |