| Total Complexity | 8 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | final class RoleAliasCollection |
||
| 10 | { |
||
| 11 | private array $aliases = []; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param array<non-empty-string|class-string, array{0: non-empty-string}> $schema |
||
|
|
|||
| 15 | */ |
||
| 16 | public function __construct(array $schema) |
||
| 17 | { |
||
| 18 | foreach ($schema as $key => $value) { |
||
| 19 | $role = $key; |
||
| 20 | |||
| 21 | if (\class_exists($role)) { |
||
| 22 | $role = $value[SchemaInterface::ROLE] ?? 'undefinedRole'; |
||
| 23 | } |
||
| 24 | |||
| 25 | $this->aliases[$key] = $role; |
||
| 26 | } |
||
| 27 | |||
| 28 | foreach ($this->aliases as $key => $role) { |
||
| 29 | if (\preg_match('/[^_a-zA-Z0-9]/u', $role)) { |
||
| 30 | $role = $this->makeAlias($role); |
||
| 31 | $this->aliases[$key] = $role; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param non-empty-string $role |
||
| 38 | * @return non-empty-string |
||
| 39 | */ |
||
| 40 | public function getAlias(string $role): string |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param non-empty-string $role |
||
| 47 | * @return non-empty-string |
||
| 48 | */ |
||
| 49 | private function makeAlias(string $role): string |
||
| 63 |