| Total Complexity | 4 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | trait StateTrait |
||
| 16 | { |
||
| 17 | use Immutable\With; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Current authenticated user |
||
| 21 | */ |
||
| 22 | protected ?User $user = null; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The authorization context. This could be an organization, where a user has specific roles per organization |
||
| 26 | * rather than roles globally. |
||
| 27 | */ |
||
| 28 | protected ?Context $context = null; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get a copy of the service for the given user. |
||
| 32 | * |
||
| 33 | * @param User|null $user |
||
| 34 | * @return static&Authz |
||
| 35 | */ |
||
| 36 | 25 | public function forUser(?User $user): Authz |
|
| 37 | { |
||
| 38 | 25 | return $this->withProperty('user', $user); |
|
|
1 ignored issue
–
show
|
|||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get a copy of the service for the given context. |
||
| 43 | * Returns $this if authz hasn't changed. |
||
| 44 | * |
||
| 45 | * @param Context|null $context |
||
| 46 | * @return static&Authz |
||
| 47 | */ |
||
| 48 | 1 | public function inContextOf(?Context $context): Authz |
|
| 49 | { |
||
| 50 | 1 | return $this->withProperty('context', $context); |
|
|
1 ignored issue
–
show
|
|||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Get current authenticated user. |
||
| 55 | * |
||
| 56 | * @return User|null |
||
| 57 | */ |
||
| 58 | 1 | final public function user(): ?User |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get the current context. |
||
| 65 | */ |
||
| 66 | 1 | final public function context(): ?Context |
|
| 69 | } |
||
| 70 | } |
||
| 71 |