Completed
Push — master ( 7354ed...57f1a6 )
by Andrii
05:45
created

src/models/DomainResource.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\models;
12
13
use hipanel\base\ModelTrait;
14
use Yii;
15
16
/**
17
 * Class DomainResource.
18
 * @deprecated Is implemented in plan module
19
 */
20
class DomainResource extends Resource
21
{
22
    use ModelTrait;
23
24
    public static function tableName()
25
    {
26
        return 'resource';
27
    }
28
29
    const TYPE_DOMAIN_REGISTRATION = 'dregistration';
30
    const TYPE_DOMAIN_TRANSFER = 'dtransfer';
31
    const TYPE_DOMAIN_RENEWAL = 'drenewal';
32
    const TYPE_DOMAIN_DELETE_AGP = 'ddelete_agp';
33
    const TYPE_DOMAIN_RESTORE_EXPIRED = 'drestore_expired';
34
    const TYPE_DOMAIN_RESTORE_DELETED = 'drestore_deleted';
35
36
    const TYPE_PREMIUM_DNS = 'premium_dns';
37
38 View Code Duplication
    public function rules()
0 ignored issues
show
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...
39
    {
40
        $rules = parent::rules();
41
        $rules['create-required'] = [
42
            ['object_id'],
43
            'required',
44
            'on' => ['create', 'update'],
45
            'when' => function ($model) {
46
                return $model->isTypeCorrect();
47
            },
48
        ];
49
        $rules['create-required-price'] = [['price'], 'required', 'on' => ['create', 'update']];
50
        $rules[] = [['zone'], 'safe'];
51
52
        return $rules;
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getTypes()
59
    {
60
        return [
61
            static::TYPE_DOMAIN_REGISTRATION => Yii::t('hipanel:finance:tariff', 'Registration'),
62
            static::TYPE_DOMAIN_TRANSFER => Yii::t('hipanel:finance:tariff', 'Transfer'),
63
            static::TYPE_DOMAIN_RENEWAL => Yii::t('hipanel:finance:tariff', 'Renewal'),
64
            static::TYPE_DOMAIN_DELETE_AGP => Yii::t('hipanel:finance:tariff', 'Delete in AGP'),
65
            static::TYPE_DOMAIN_RESTORE_EXPIRED => Yii::t('hipanel:finance:tariff', 'Restoring expired'),
66
            static::TYPE_DOMAIN_RESTORE_DELETED => Yii::t('hipanel:finance:tariff', 'Restoring deleted'),
67
        ];
68
    }
69
70
    public function getServiceTypes()
71
    {
72
        return [
73
            static::TYPE_PREMIUM_DNS => Yii::t('hipanel:finance:tariff', 'Premium DNS'),
74
        ];
75
    }
76
77
    public function isTypeCorrect()
78
    {
79
        return isset($this->getTypes()[$this->type]);
80
    }
81
}
82