Passed
Push — master ( f2dea1...58a092 )
by Nate
04:47
created

RecordWithState::stateRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 6
nop 0
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/spark/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/spark
7
 */
8
9
namespace flipbox\spark\records\traits;
10
11
use flipbox\spark\helpers\RecordHelper;
12
13
/**
14
 * @property bool $enabled
15
 *
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.2.0
18
 */
19
trait RecordWithState
20
{
21
22
    /**
23
     * @var bool Enabled
24
     */
25
    public $enabled;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    protected function stateRules()
31
    {
32
33
        return [
34
            [
35
                [
36
                    'enabled'
37
                ],
38
                'safe',
39
                'on' => [
40
                    RecordHelper::SCENARIO_DEFAULT
41
                ]
42
            ]
43
        ];
44
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function isEnabled()
51
    {
52
        return (bool)$this->enabled;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function isDisabled()
59
    {
60
        return !$this->isEnabled();
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function toEnabled()
67
    {
68
        $this->enabled = true;
69
        return $this;
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function toDisabled()
76
    {
77
        $this->enabled = false;
78
        return $this;
79
    }
80
81
}
82