Completed
Push — master ( 546d98...ab7c28 )
by Dmitry
05:46
created

TariffController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 99
Duplicated Lines 52.53 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 37.74%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
lcom 1
cbo 6
dl 52
loc 99
ccs 20
cts 53
cp 0.3774
rs 10
c 2
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B actions() 0 33 1
A actionCreateDomain() 13 13 3
A actionCreateSvds() 14 14 3
A actionCreateOvds() 13 13 3
A actionUpdate() 12 12 3
A actionView() 0 6 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\controllers;
12
13
use hipanel\actions\ComboSearchAction;
14
use hipanel\actions\IndexAction;
15
use hipanel\actions\OrientationAction;
16
use hipanel\actions\SmartDeleteAction;
17
use hipanel\actions\SmartUpdateAction;
18
use hipanel\actions\ValidateFormAction;
19
use hipanel\models\Ref;
20
use hipanel\modules\finance\logic\DomainTariffManager;
21
use hipanel\modules\finance\logic\TariffManagerFactory;
22
use Yii;
23
24
class TariffController extends \hipanel\base\CrudController
25
{
26 1
    public function actions()
27
    {
28
        return [
29
            'set-orientation' => [
30 1
                'class' => OrientationAction::class,
31
                'allowedRoutes' => [
32 1
                    '@tariff/index',
33 1
                ],
34 1
            ],
35
            'index' => [
36 1
                'class' => IndexAction::class,
37 1
                'data' => function () {
38
                    return [
39
                        'types' => Ref::getList('type,tariff', 'hipanel:finance:tariff:types'),
40
                    ];
41 1
                },
42 1
            ],
43
            'search' => [
44 1
                'class' => ComboSearchAction::class,
45 1
            ],
46
            'validate-form' => [
47 1
                'class' => ValidateFormAction::class,
48 1
            ],
49
            'set-note' => [
50 1
                'class' => SmartUpdateAction::class,
51 1
                'success' => Yii::t('hipanel', 'Note updated'),
52 1
            ],
53
            'delete' => [
54 1
                'class' => SmartDeleteAction::class,
55 1
                'success' => Yii::t('hipanel:finance:tariff', 'Tariff deleted'),
56 1
            ],
57 1
        ];
58
    }
59
60 View Code Duplication
    public function actionCreateDomain()
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...
61
    {
62
        /** @var DomainTariffManager $manager */
63
        $manager = TariffManagerFactory::createByType('domain');
64
        $form = $manager->form;
65
66
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
67
            $manager->insert();
68
            return $this->redirect(['view', 'id' => $form->id]);
69
        }
70
71
        return $this->render('domain/create', ['model' => $form]);
72
    }
73
74 View Code Duplication
    public function actionCreateSvds($parent_id = null)
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...
75
    {
76
        /** @var DomainTariffManager $manager */
77
        $manager = TariffManagerFactory::createByType('svds', $parent_id);
78
79
        $form = $manager->form;
80
81
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
82
            $manager->insert();
83
            return $this->redirect(['view', 'id' => $form->id]);
84
        }
85
86
        return $this->render('vds/create', ['model' => $form]);
87
    }
88
89 View Code Duplication
    public function actionCreateOvds($parent_id = null)
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...
90
    {
91
        /** @var DomainTariffManager $manager */
92
        $manager = TariffManagerFactory::createByType('ovds', $parent_id);
93
        $form = $manager->form;
94
95
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
96
            $manager->insert();
97
            return $this->redirect(['view', 'id' => $form->id]);
98
        }
99
100
        return $this->render('vds/create', ['model' => $form]);
101
    }
102
103 View Code Duplication
    public function actionUpdate($id)
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...
104
    {
105
        $manager = TariffManagerFactory::createById($id, ['scenario' => 'update']);
106
        $form = $manager->form;
107
108
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
109
            $manager->update();
110
            return $this->redirect(['view', 'id' => $form->id]);
111
        }
112
113
        return $this->render($manager->getType() . '/update', ['model' => $form]);
114
    }
115
116
    public function actionView($id)
117
    {
118
        $manager = TariffManagerFactory::createById($id);
119
120
        return $this->render('view', ['manager' => $manager]);
121
    }
122
}
123