| Total Complexity | 6 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 93.75% |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class PermissionRepository extends Repository |
||
| 20 | { |
||
| 21 | 3 | protected function getSuffix(): string |
|
| 22 | { |
||
| 23 | 3 | return 'permissions'; |
|
| 24 | } |
||
| 25 | |||
| 26 | public function toCollection(PermissionsOwner $owner): Collection |
||
| 27 | { |
||
| 28 | 3 | return $this->remember($owner, function () use ($owner) { |
|
| 29 | 3 | return $this->permissions($owner); |
|
| 30 | 3 | }); |
|
| 31 | } |
||
| 32 | |||
| 33 | 3 | private function permissions(PermissionsOwner $owner): Collection |
|
| 34 | { |
||
| 35 | 3 | $permissions = $owner->getPermissionModels(); |
|
| 36 | |||
| 37 | 3 | if ($owner instanceof RolesOwner) { |
|
| 38 | 3 | return $this->permissionsFromRole($owner)->merge($permissions)->map($this->parse()); |
|
| 39 | } |
||
| 40 | |||
| 41 | return $permissions->map($this->parse()); |
||
| 42 | } |
||
| 43 | |||
| 44 | private function permissionsFromRole(RolesOwner $owner): Collection |
||
| 45 | { |
||
| 46 | 3 | return $this->extractPermissions($owner)->unique(function (Grantable $grantable) { |
|
| 47 | 1 | return $grantable->getIdentificationKey(); |
|
| 48 | 3 | }); |
|
| 49 | } |
||
| 50 | |||
| 51 | private function extractPermissions(RolesOwner $owner): Collection |
||
| 56 | } |
||
| 57 | } |
||
| 58 |