Passed
Push — ft/states ( 728e57...af2f8a )
by Ben
08:47
created

InvitationState::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Thinktomorrow\Chief\Users\Invites;
4
5
use Thinktomorrow\Chief\States\State\StateMachine;
6
7
class InvitationState extends StateMachine
8
{
9
    const KEY = 'state';
10
11
    /**
12
     * Possible states of the invitation process:
13
     *
14
     * NONE - no invitation sent; nothing has happened so far
15
     * PENDING - invitation sent or resent and awaiting acceptance
16
     * EXPIRED - invitation is no longer valid due to the time restriction
17
     * ACCEPTED - new user has accepted the invite
18
     * DENIED - new user has denied the invite explicitly
19
     * REVOKED - invitation is revoked by an admin
20
     */
21
    const NONE = 'none';
22
    const PENDING = 'pending';
23
    const EXPIRED = 'expired';
24
    const ACCEPTED = 'accepted';
25
    const DENIED = 'denied';
26
    const REVOKED = 'revoked';
27
28
    protected $states = [
29
        self::NONE,
30
        self::PENDING,
31
        self::EXPIRED,
32
        self::REVOKED,
33
        self::ACCEPTED,
34
        self::DENIED,
35
    ];
36
37
    protected $transitions = [
38
        'invite' => [
39
            'from' => [self::NONE, self::EXPIRED, self::REVOKED],
40
            'to'   => self::PENDING,
41
        ],
42
        'expire' => [
43
            'from' => [self::PENDING],
44
            'to'   => self::EXPIRED,
45
        ],
46
        'revoke' => [
47
            'from' => [self::PENDING, self::EXPIRED],
48
            'to' => self::REVOKED,
49
        ],
50
        'accept' => [
51
            'from' => [self::PENDING],
52
            'to' => self::ACCEPTED,
53
        ],
54
        'deny' => [
55
            'from' => [self::PENDING],
56
            'to' => self::DENIED,
57
        ],
58
    ];
59
}
60