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

PageState::isOffline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
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