Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| RestrictedEntity | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRequiredPermissions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUserId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests\Apie\TypeDemo\Resources; |
| 3 | |
| 4 | use Apie\Core\Attributes\Context; |
| 5 | use Apie\Core\Attributes\LoggedIn; |
| 6 | use Apie\Core\Attributes\RemovalCheck; |
| 7 | use Apie\Core\Attributes\StaticCheck; |
| 8 | use Apie\Core\ContextConstants; |
| 9 | use Apie\Core\Entities\EntityInterface; |
| 10 | use Apie\Core\Lists\PermissionList; |
| 11 | use Apie\Core\Permissions\RequiresPermissionsInterface; |
| 12 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\RestrictedEntityIdentifier; |
| 13 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\UserIdentifier; |
| 14 | use Apie\TextValueObjects\CompanyName; |
| 15 | |
| 16 | #[RemovalCheck(new StaticCheck(new LoggedIn()))] |
| 17 | final class RestrictedEntity implements EntityInterface, RequiresPermissionsInterface |
| 18 | { |
| 19 | private ?UserIdentifier $userId = null; |
| 20 | |
| 21 | public function __construct( |
| 22 | private RestrictedEntityIdentifier $id, |
| 23 | public CompanyName $companyName, |
| 24 | #[Context(ContextConstants::AUTHENTICATED_USER)] |
| 25 | ?User $user = null |
| 26 | ) { |
| 27 | $this->userId = $user?->getId(); |
| 28 | } |
| 29 | |
| 30 | public function getRequiredPermissions(): PermissionList |
| 31 | { |
| 32 | if ($this->userId) { |
| 33 | return new PermissionList([$this->userId->toPermission()]); |
| 34 | } |
| 35 | return new PermissionList(); |
| 36 | } |
| 37 | |
| 38 | public function getId(): RestrictedEntityIdentifier |
| 39 | { |
| 40 | return $this->id; |
| 41 | } |
| 42 | |
| 43 | public function getUserId(): ?UserIdentifier |
| 44 | { |
| 45 | return $this->userId; |
| 46 | } |
| 47 | } |