HasStatusModel::getStatusModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace andmemasin\myabstract;
4
5
use yii\base\InvalidConfigException;
6
7
/**
8
 * Class HasStatusModel
9
 *
10
 * @property string $status
11
 *
12
 * @property StatusModel $statusModel
13
 * @package andmemasin\myabstract
14
 */
15
class HasStatusModel extends MyActiveRecord
16
{
17
    public $parentClassName;
18
    public $parentIdColumn;
19
20
    /** @var string */
21
    public $statusModelClass = StatusModel::class;
22
23
24
    /**
25
     * @throws InvalidConfigException
26
     */
27
    public function init()
28
    {
29
        if (!$this->parentClassName) {
30
            throw new InvalidConfigException('parentClassName must be set for ' . static::class);
31
        }
32
33
        /** @var MyActiveRecord $parent */
34
        $parent = new $this->parentClassName;
35
        $this->parentIdColumn = $parent::primaryKey()[0];
36
37
38
        parent::init();
39
    }
40
41
    /**
42
     * @return StatusModel
43
     */
44
    public function getStatusModel()
45
    {
46
        /** @var StatusModel $statusModel */
47
        $statusModel = new $this->statusModelClass;
48
        return $statusModel::getById($this->status);
49
    }
50
51
}