Test Failed
Push — ft/states ( eebc9c )
by Ben
29:42 queued 08:49
created

PageState   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 33
c 1
b 0
f 0
dl 0
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isOnline() 0 4 1
A __construct() 0 3 1
A isOffline() 0 6 1
1
<?php
2
3
namespace Thinktomorrow\Chief\States;
4
5
use Thinktomorrow\Chief\States\State\StateMachine;
6
use Thinktomorrow\Chief\States\State\StatefulContract;
7
8
class PageState extends StateMachine
9
{
10
    // Offline states
11
    const DRAFT = 'draft';
12
    const ARCHIVED = 'archived';
13
    const DELETED = 'deleted'; // soft deleted
14
15
    // Online states
16
    const PUBLISHED = 'published';
17
18
    protected $states = [
19
        self::DRAFT,
20
        self::ARCHIVED,
21
        self::DELETED,
22
23
        self::PUBLISHED,
24
    ];
25
26
    protected $transitions = [
27
        'publish' => [
28
            'from' => [self::DRAFT],
29
            'to'   => self::PUBLISHED,
30
        ],
31
        'unpublish' => [
32
            'from' => [self::PUBLISHED],
33
            'to'   => self::DRAFT,
34
        ],
35
        'archive' => [
36
            'from' => [self::PUBLISHED, self::DRAFT],
37
            'to'   => self::ARCHIVED,
38
        ],
39
        'unarchive' => [
40
            'from' => [self::ARCHIVED],
41
            'to'   => self::DRAFT,
42
        ],
43
        'delete' => [
44
            'from' => [self::ARCHIVED],
45
            'to'   => self::DELETED,
46
        ],
47
    ];
48
49
    public function __construct(StatefulContract $order)
50
    {
51
        parent::__construct($order);
52
    }
53
54
    public function isOffline(): bool
55
    {
56
        return in_array($this->statefulContract->state(), [
57
            static::DRAFT,
58
            static::ARCHIVED,
59
            static::DELETED,
60
        ]);
61
    }
62
63
    public function isOnline(): bool
64
    {
65
        return in_array($this->statefulContract->state(), [
66
            static::PUBLISHED,
67
        ]);
68
    }
69
}
70