| Total Complexity | 9 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | class PermissionRepository extends Repository |
||
| 24 | { |
||
| 25 | 37 | public static function getSuffix(): string |
|
| 26 | { |
||
| 27 | 37 | return 'permissions'; |
|
| 28 | } |
||
| 29 | |||
| 30 | 26 | public function toCollection(PermissionsOwner $owner): Collection |
|
| 31 | { |
||
| 32 | 26 | return $this->remember($owner, function () use ($owner) { |
|
| 33 | 26 | return $this->permissions($owner); |
|
| 34 | 26 | }); |
|
| 35 | } |
||
| 36 | |||
| 37 | 26 | private function permissions(PermissionsOwner $owner): Collection |
|
| 38 | { |
||
| 39 | 26 | $permissions = $owner->permissions()->get(); |
|
| 40 | |||
| 41 | 26 | if ($owner instanceof RolesOwner) { |
|
| 42 | 21 | $names = $permissions->pluck('secret_name')->toArray(); |
|
| 43 | 21 | $permissions = $this->clean($this->permissionsFromRole($owner), $names)->merge($permissions); |
|
| 44 | } |
||
| 45 | |||
| 46 | 26 | return $permissions->filter($this->allowed())->map($this->parse()); |
|
| 47 | } |
||
| 48 | |||
| 49 | 26 | private function allowed(): Closure |
|
| 50 | { |
||
| 51 | 26 | return function (PermissionContract $permission): bool { |
|
| 52 | 17 | return $permission->pivot instanceof Deniable ? ! $permission->pivot->isDenied() : true; |
|
|
|
|||
| 53 | 26 | }; |
|
| 54 | } |
||
| 55 | |||
| 56 | 21 | private function clean(Collection $permissions, array $exceptNames): Collection |
|
| 59 | } |
||
| 60 | |||
| 61 | 21 | private function permissionsFromRole(RolesOwner $owner): Collection |
|
| 62 | { |
||
| 63 | 21 | return $this->extractPermissions($owner)->unique(function (Grantable $grantable): string { |
|
| 64 | 3 | return $grantable->getIdentificationKey(); |
|
| 65 | 21 | }); |
|
| 66 | } |
||
| 67 | |||
| 68 | 21 | private function extractPermissions(RolesOwner $owner): Collection |
|
| 73 | } |
||
| 74 | } |
||
| 75 |