Completed
Push — master ( 0012a2...099852 )
by Dmitry
08:38
created

TariffManagerFactory::buildClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\logic;
4
5
use hipanel\modules\finance\models\Tariff;
6
use Yii;
7
use yii\web\NotFoundHttpException;
8
9
class TariffManagerFactory
10
{
11
    /**
12
     * @param integer $id Tariff ID
13
     * @return TariffManager|object
14
     * @throws NotFoundHttpException
15
     */
16
    public static function createById($id)
17
    {
18
        $model = Tariff::find()->byId($id)->details()->one();
19
20
        if ($model === null) {
21
            throw new NotFoundHttpException('Tariff was not found');
22
        }
23
24
        return Yii::createObject(static::buildClassName($model->type), [$model]);
25
    }
26
27
    /**
28
     * @param string $type Tariff type
29
     * @return \hipanel\modules\finance\logic\TariffManager|object
30
     */
31
    public static function createByType($type)
32
    {
33
        return Yii::createObject(static::buildClassName($type));
34
    }
35
36
    /**
37
     * @param string $type Tariff type
38
     * @return string
39
     */
40
    protected static function buildClassName($type)
41
    {
42
        return 'hipanel\modules\finance\logic\\' . ucfirst($type) . 'TariffManager';
43
    }
44
}
45