Completed
Push — master ( ae53ec...716429 )
by Dmitry
15:10
created

ServerResource::getAvailableTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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 ServerResource 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
    /**
42
     * @return array
43
     */
44 View Code Duplication
    public function getAvailableTypes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        return [
47
            static::TYPE_DOMAIN_REGISTRATION => Yii::t('hipanel/finance/tariff', 'Registration'),
48
            static::TYPE_DOMAIN_TRANSFER => Yii::t('hipanel/finance/tariff', 'Transfer'),
49
            static::TYPE_DOMAIN_RENEWAL => Yii::t('hipanel/finance/tariff', 'Renewal'),
50
            static::TYPE_DOMAIN_DELETE_AGP => Yii::t('hipanel/finance/tariff', 'Delete in AGP'),
51
            static::TYPE_DOMAIN_RESTORE_EXPIRED => Yii::t('hipanel/finance/tariff', 'Restoring expired'),
52
            static::TYPE_DOMAIN_RESTORE_DELETED => Yii::t('hipanel/finance/tariff', 'Restoring deleted'),
53
        ];
54
    }
55
56
    public function getServiceTypes()
57
    {
58
        return [
59
            static::TYPE_PREMIUM_DNS => Yii::t('hipanel/finance/tariff', 'Premium DNS')
60
        ];
61
    }
62
63
    public function isTypeCorrect()
64
    {
65
        return isset($this->getAvailableTypes()[$this->type]);
0 ignored issues
show
Documentation introduced by
The property 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...
66
    }
67
}
68