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