Completed
Push — master ( 83485f...ef2c0c )
by Dmitry
04:50
created

ServerResource::getAvailableTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Finance module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-finance
7
 * @package   hipanel-module-finance
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\finance\models;
13
14
use hipanel\base\ModelTrait;
15
use Yii;
16
17
/**
18
 * Class DomainResource
19
 * @package hipanel\modules\finance\models
20
 */
21
class ServerResource extends Resource
22
{
23
    use ModelTrait;
24
25
    public static function index()
26
    {
27
        return 'resources';
28
    }
29
30
    public static function type()
31
    {
32
        return 'resource';
33
    }
34
35
    const MODEL_TYPE_CPU = 'cpu';
36
    const MODEL_TYPE_RAM = 'ram';
37
    const MODEL_TYPE_HDD = 'hdd';
38
    const MODEL_TYPE_CHASSIS = 'chassis';
39
40
    const TYPE_ISP5 = 'isp5';
41
    const TYPE_ISP = 'isp';
42
    const TYPE_SUPPORT_TIME = 'support_time';
43
    const TYPE_IP_NUMBER = 'ip_num';
44
    const TYPE_SERVER_TRAF_MAX = 'server_traf_max';
45
    const TYPE_SERVER_TRAF95_MAX = 'server_traf95_max';
46
    const TYPE_BACKUP_DU = 'backup_du';
47
48
    public function rules()
49
    {
50
        $rules = parent::rules();
51
        $rules[] = [['model_type', 'partno'], 'safe'];
52
53
        return $rules;
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getModelTypes()
60
    {
61
        return [
62
            static::MODEL_TYPE_CPU => Yii::t('hipanel/finance/tariff', 'CPU'),
63
            static::MODEL_TYPE_RAM => Yii::t('hipanel/finance/tariff', 'RAM'),
64
            static::MODEL_TYPE_HDD => Yii::t('hipanel/finance/tariff', 'HDD'),
65
            static::MODEL_TYPE_CHASSIS => Yii::t('hipanel/finance/tariff', 'Chassis'),
66
        ];
67
    }
68
69
    public function isModelTypeCorrect()
70
    {
71
        return isset($this->getModelTypes()[$this->model_type]);
0 ignored issues
show
Documentation introduced by
The property model_type does not exist on object<hipanel\modules\f...\models\ServerResource>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
72
    }
73
74
75
    public function getAvailableTypes()
76
    {
77
        return [
78
            static::TYPE_ISP5 => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
79
            static::TYPE_ISP => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
80
            static::TYPE_SUPPORT_TIME => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
81
            static::TYPE_IP_NUMBER => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
82
            static::TYPE_SERVER_TRAF_MAX => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
83
            static::TYPE_SERVER_TRAF95_MAX => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
84
            static::TYPE_BACKUP_DU => Yii::t('hipanel/finance/tariff', 'ISP Manager'),
85
        ];
86
    }
87
}
88