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

ModelWithState   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnabled() 0 4 1
A isDisabled() 0 4 1
A toEnabled() 0 5 1
A toDisabled() 0 5 1
A stateRules() 0 16 1
A stateAttributeLabel() 0 8 1
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\models\traits;
10
11
use Craft;
12
use flipbox\spark\helpers\ModelHelper;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 1.2.0
17
 */
18
trait ModelWithState
19
{
20
21
    /**
22
     * @var boolean Enabled
23
     */
24
    public $enabled;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function isEnabled()
30
    {
31
        return (bool)$this->enabled;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function isDisabled()
38
    {
39
        return !$this->isEnabled();
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function toEnabled()
46
    {
47
        $this->enabled = true;
48
        return $this;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function toDisabled()
55
    {
56
        $this->enabled = false;
57
        return $this;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function stateRules()
64
    {
65
66
        return [
67
            [
68
                [
69
                    'enabled'
70
                ],
71
                'safe',
72
                'on' => [
73
                    ModelHelper::SCENARIO_DEFAULT
74
                ]
75
            ]
76
        ];
77
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83
    public function stateAttributeLabel()
84
    {
85
86
        return [
87
            'state' => Craft::t('app', 'State')
88
        ];
89
90
    }
91
92
}
93