Completed
Push — master ( 834dc7...c72fcf )
by Dmitry
14:24
created

CertificateResource   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 58.54 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 4
dl 24
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A rules() 17 17 1
A getTypes() 7 7 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-2017, 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 CertificateResource
18
 *
19
 * @author Dmytro Naumenko <[email protected]>
20
 */
21
class CertificateResource extends Resource
22
{
23
    use ModelTrait;
24
25
    public static function tableName()
26
    {
27
        return 'resource';
28
    }
29
30
    const TYPE_CERT_REGISTRATION = 'certificate_purchase';
31
    const TYPE_CERT_RENEW = 'certificate_renew';
32
33 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...
34
    {
35
        $rules = parent::rules();
36
        $rules['create-required'] = [
37
            ['object_id'],
38
            'required',
39
            'on' => ['create', 'update'],
40
            'when' => function ($model) {
41
                /** @var self $model */
42
                return $model->isTypeCorrect();
43
            },
44
        ];
45
        $rules['create-required-price'] = [['price'], 'required', 'on' => ['create', 'update']];
46
        $rules[] = [['certificateType'], 'safe'];
47
48
        return $rules;
49
    }
50
51
    /**
52
     * @return array
53
     */
54 View Code Duplication
    public function getTypes()
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...
55
    {
56
        return [
57
            static::TYPE_CERT_REGISTRATION => Yii::t('hipanel:finance:tariff', 'Registration'),
58
            static::TYPE_CERT_RENEW => Yii::t('hipanel:finance:tariff', 'Renewal'),
59
        ];
60
    }
61
}
62