Completed
Push — master ( 0622f1...018a2f )
by Dmitry
04:34
created

DomainResource::getAvailableTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

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 11
ccs 0
cts 11
cp 0
rs 9.4285
cc 1
eloc 8
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 Yii;
15
16
/**
17
 * Class DomainResource
18
 * @package hipanel\modules\finance\models
19
 */
20
class DomainResource extends Resource
21
{
22
    public static function index()
23
    {
24
        return 'resources';
25
    }
26
27
    public static function type()
28
    {
29
        return 'resource';
30
    }
31
32
    const TYPE_DOMAIN_REGISTRATION = 'dregistration';
33
    const TYPE_DOMAIN_TRANSFER = 'dtransfer';
34
    const TYPE_DOMAIN_RENEWAL = 'drenewal';
35
    const TYPE_DOMAIN_DELETE_AGP = 'ddelete_agp';
36
    const TYPE_DOMAIN_RESTORE_EXPIRED = 'drestore_expired';
37
    const TYPE_DOMAIN_RESTORE_DELETED = 'drestore_deleted';
38
39
    const TYPE_PREMIUM_DNS = 'premium_dns';
40
41
    public function rules()
42
    {
43
        $rules = parent::rules();
44
        $rules['create-required'] = [
45
            ['object_id'],
46
            'required',
47
            'on' => ['create', 'update'],
48
            'when' => function ($model) {
49
                return $model->isTypeCorrect();
50
            }
51
        ];
52
        $rules['create-required-price'] = [['price'], 'required', 'on' => ['create', 'update']];
53
54
        return $rules;
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getTypes()
61
    {
62
        return [
63
            static::TYPE_DOMAIN_REGISTRATION => Yii::t('hipanel/finance/tariff', 'Registration'),
64
            static::TYPE_DOMAIN_TRANSFER => Yii::t('hipanel/finance/tariff', 'Transfer'),
65
            static::TYPE_DOMAIN_RENEWAL => Yii::t('hipanel/finance/tariff', 'Renewal'),
66
            static::TYPE_DOMAIN_DELETE_AGP => Yii::t('hipanel/finance/tariff', 'Delete in AGP'),
67
            static::TYPE_DOMAIN_RESTORE_EXPIRED => Yii::t('hipanel/finance/tariff', 'Restoring expired'),
68
            static::TYPE_DOMAIN_RESTORE_DELETED => Yii::t('hipanel/finance/tariff', 'Restoring deleted'),
69
        ];
70
    }
71
72
    public function getServiceTypes()
73
    {
74
        return [
75
            static::TYPE_PREMIUM_DNS => Yii::t('hipanel/finance/tariff', 'Premium DNS')
76
        ];
77
    }
78
79
    public function isTypeCorrect()
80
    {
81
        return isset($this->getTypes()[$this->type]);
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<hipanel\modules\f...\models\DomainResource>. 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...
82
    }
83
}
84