Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
InAppNotificationStatus
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 userSettable
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 canTransitionTo
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Enums;
4
5/**
6 * Status values for in-app notification lifecycle.
7 *
8 * Transitions: pending -> sent (auto) -> viewed -> clicked
9 * Any status can transition to dismissed.
10 */
11enum InAppNotificationStatus: string
12{
13    case PENDING = 'pending';
14    case SENT = 'sent';
15    case VIEWED = 'viewed';
16    case CLICKED = 'clicked';
17    case DISMISSED = 'dismissed';
18
19    /**
20     * Get statuses that users can set via the PATCH endpoint.
21     *
22     * @return array<string>
23     */
24    public static function userSettable(): array
25    {
26        return [
27            self::VIEWED->value,
28            self::CLICKED->value,
29            self::DISMISSED->value,
30        ];
31    }
32
33    /**
34     * Check if the transition from current status to the new one is valid.
35     */
36    public function canTransitionTo(self $new): bool
37    {
38        // Any status can transition to dismissed
39        if ($new === self::DISMISSED) {
40            return true;
41        }
42
43        return match ($this) {
44            self::SENT => in_array($new, [self::VIEWED, self::CLICKED]),
45            self::VIEWED => $new === self::CLICKED,
46            default => false,
47        };
48    }
49}