Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.48% |
19 / 21 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| PermissionList | |
90.48% |
19 / 21 |
|
50.00% |
2 / 4 |
11.10 | |
0.00% |
0 / 1 |
| offsetGet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toStringList | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasOverlap | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Lists; |
| 3 | |
| 4 | use Apie\Core\Permissions\PermissionInterface; |
| 5 | |
| 6 | final class PermissionList extends ItemList |
| 7 | { |
| 8 | public function offsetGet(mixed $offset): PermissionInterface|string |
| 9 | { |
| 10 | return parent::offsetGet($offset); |
| 11 | } |
| 12 | |
| 13 | public function toStringList(): StringSet |
| 14 | { |
| 15 | $res = []; |
| 16 | foreach ($this as $value) { |
| 17 | if ($value instanceof PermissionInterface) { |
| 18 | foreach ($value->getPermissionIdentifiers()->toStringList() as $identifier) { |
| 19 | $res[] = $identifier; |
| 20 | } |
| 21 | } else { |
| 22 | $res[] = (string) $value; |
| 23 | } |
| 24 | } |
| 25 | return new StringSet($res); |
| 26 | } |
| 27 | |
| 28 | public function jsonSerialize(): array |
| 29 | { |
| 30 | return $this->toStringList()->toArray(); |
| 31 | } |
| 32 | |
| 33 | public function hasOverlap(PermissionList $permissionList): bool |
| 34 | { |
| 35 | $currentList = $this->toStringList()->toArray(); |
| 36 | $compareList = $permissionList->toStringList(); |
| 37 | if (empty($currentList)) { |
| 38 | return (isset($compareList[''])) ; |
| 39 | } |
| 40 | $compareList = $compareList->toArray(); |
| 41 | if (empty($compareList)) { |
| 42 | $compareList[] = ''; |
| 43 | } |
| 44 | $currentList = array_combine($currentList, $currentList); |
| 45 | foreach ($compareList as $item) { |
| 46 | if (isset($currentList[$item])) { |
| 47 | return true; |
| 48 | } |
| 49 | } |
| 50 | return false; |
| 51 | } |
| 52 | } |