Passed
Branch master (861137)
by Tõnis
07:04
created

StatusModel::getIsActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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