Passed
Push — master ( eae9c0...9cc093 )
by Tõnis
02:30
created

StatusModel::getIsActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace andmemasin\myabstract;
3
4
use Yii;
5
6
/**
7
 * Class StatusModel
8
 * @property integer $id
9
 * @property string $label
10
 * @property boolean $isActive
11
 *
12
 * @package andmemasin\myabstract
13
 */
14
class StatusModel extends StaticModel implements StatusInterface
15
{
16
    const STATUS_CREATED = "created";
17
    const STATUS_ACTIVE = "active";
18
19
    /** @var  integer $id*/
20
    public $id;
21
22
    /** @var  string $label */
23
    public $label;
24
25
    /** @var string */
26
    public $description;
27
28
    public static $keyColumn = 'id';
29
30
    public static function getModels()
31
    {
32
        return [
33
            self::STATUS_CREATED => [
34
                'id' => self::STATUS_CREATED,
35
                'label' => Yii::t('app', 'Created'),
36
                'description' => Yii::t('app', 'Was created'),
37
            ],
38
39
        ];
40
    }
41
42
    /**
43
     * Returns all status names in plain array without labels
44
     * @return string[]
45
     */
46
    public static function getAllStatusNames()
47
    {
48
        $out = [];
49
        foreach (self::getModels() as $status) {
50
            $out[] = $status->label;
51
        }
52
        return $out;
53
    }
54
55
    /**
56
     * @param string $id
57
     * @return bool
58
     */
59
    public static function isStatus($id) {
60
        return (!self::getById($id) === false);
61
    }
62
63
    /**
64
     * @param string $id
65
     * @return null|string
66
     */
67
    public static function getStatusLabel($id) {
68
        $status = self::getById($id);
69
        if (!empty($status)) {
70
            return $status->label;
71
        }
72
        return null;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getIsActive()
79
    {
80
        return true;
81
    }
82
}