Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| TripRole | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| canWriteExpense | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| canManageTrip | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isStorableMembership | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Trip\Domain\ValueObject; |
| 6 | |
| 7 | /** |
| 8 | * A user's capability level on a trip. OWNER is synthesised from the |
| 9 | * Trip.ownerId column; only EDITOR/VIEWER are ever stored in trip_members |
| 10 | * (adding a case is all a new role takes — mirrors CategoryType/UserStatus). |
| 11 | */ |
| 12 | enum TripRole: string |
| 13 | { |
| 14 | case OWNER = 'owner'; |
| 15 | case EDITOR = 'editor'; |
| 16 | case VIEWER = 'viewer'; |
| 17 | |
| 18 | /** Owner and editor may add/edit/delete expenses; viewer is read-only. */ |
| 19 | public function canWriteExpense(): bool |
| 20 | { |
| 21 | return $this === self::OWNER || $this === self::EDITOR; |
| 22 | } |
| 23 | |
| 24 | /** Only the owner may edit/delete the trip or manage its members. */ |
| 25 | public function canManageTrip(): bool |
| 26 | { |
| 27 | return $this === self::OWNER; |
| 28 | } |
| 29 | |
| 30 | /** A stored membership role — OWNER is never persisted (it's the column). */ |
| 31 | public function isStorableMembership(): bool |
| 32 | { |
| 33 | return $this === self::EDITOR || $this === self::VIEWER; |
| 34 | } |
| 35 | } |