StatusModel::isStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace andmemasin\myabstract;
3
4
use Yii;
5
use andmemasin\myabstract\interfaces\StatusInterface;
6
7
/**
8
 * Class StatusModel
9
 * @property integer $id
10
 * @property string $label
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 function getModelAttributes()
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 ((new static)->getModelAttributes() as $attributes) {
50
            $out[] = $attributes['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 isActive($id)
79
    {
80
        throw new \Exception('not implemented');
81
    }
82
}