Total Complexity | 6 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
7 | final class BasicPermission implements PermissionInterface |
||
8 | { |
||
9 | 8 | public function __construct( |
|
14 | 8 | } |
|
15 | |||
16 | /** |
||
17 | * Can match in 3 ways: a single '*' matches everything, ending on '::*' |
||
18 | * means it will only have to match the type, otherwise it needs to be a |
||
19 | * full match. |
||
20 | */ |
||
21 | 5 | public function matchesResource(AuthorizationEntityInterface $resource): bool |
|
22 | { |
||
23 | 5 | if ($this->resourceMatcher === '*') { |
|
24 | 1 | return true; |
|
25 | 4 | } elseif (substr($this->resourceMatcher, -3, 3) === '::*') { |
|
26 | 2 | return $resource->getType() === substr($this->resourceMatcher, 0, -3); |
|
27 | } |
||
28 | 2 | return ($resource->getType() . '::' . $resource->getId()) === $this->resourceMatcher; |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * Can match in 2 ways: either a single '*' matches everything, or it needs |
||
33 | * to be a full match. |
||
34 | */ |
||
35 | 4 | public function matchesAction(string $action): bool |
|
41 | } |
||
42 | } |
||
43 |