| Conditions | 6 |
| Paths | 7 |
| Total Lines | 25 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public static function hasRoles($user, $roles, bool $or = true): bool { |
||
| 33 | |||
| 34 | if (false === ($user instanceof UserInterface)) { |
||
| 35 | return false; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (false === is_array($roles)) { |
||
| 39 | $roles = [$roles]; |
||
| 40 | } |
||
| 41 | |||
| 42 | $result = 1 <= count($roles); |
||
|
|
|||
| 43 | |||
| 44 | foreach ($roles as $role) { |
||
| 45 | |||
| 46 | $buffer = in_array($role, $user->getRoles()); |
||
| 47 | |||
| 48 | if (true === $buffer && true === $or) { |
||
| 49 | $result = $buffer; |
||
| 50 | break; |
||
| 51 | } |
||
| 52 | |||
| 53 | $result &= $buffer; |
||
| 54 | } |
||
| 55 | |||
| 56 | return $result; |
||
| 57 | } |
||
| 59 |