-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDocumentState.php
59 lines (50 loc) · 1.29 KB
/
DocumentState.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace App\Models;
enum DocumentState: string
{
case Submitted = 'submitted';
case Approved = 'approved';
case Declined = 'declined';
case Missing = 'missing';
/**
* @param DocumentState[] $states
* @return DocumentState[]
*/
public static function sort(array $states): array
{
usort($states, function (DocumentState $lhs, DocumentState $rhs): int {
return $lhs->compareTo($rhs);
});
return $states;
}
public function compareTo(DocumentState $other): int
{
$thisIntValue = $this->intValue();
$otherIntValue = $other->intValue();
if ($thisIntValue < $otherIntValue) {
return -1;
}
if ($thisIntValue > $otherIntValue) {
return 1;
}
return 0;
}
private function intValue(): int
{
return match ($this) {
self::Submitted => 2,
self::Approved => 3,
self::Declined => 1,
self::Missing => 0,
};
}
public function displayName(): string
{
return match ($this) {
self::Submitted => '⬆️',
self::Approved => '✅',
self::Declined => '⛔️',
self::Missing => '🤷',
};
}
}