DomainResource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 16
loc 62
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A rules() 16 16 1
A getServiceTypes() 0 6 1
A isTypeCorrect() 0 4 1
A getTypes() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
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...
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', 'no'], '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