Completed
Push — master ( 099852...844c41 )
by Dmitry
08:44
created

TariffController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 35.48 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 54.55%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 8
c 7
b 2
f 2
lcom 1
cbo 3
dl 22
loc 62
ccs 18
cts 33
cp 0.5455
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B actions() 0 28 1
A actionCreateDomain() 11 11 3
A actionUpdate() 11 11 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
/*
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\controllers;
13
14
use hipanel\actions\IndexAction;
15
use hipanel\actions\OrientationAction;
16
use hipanel\actions\SearchAction;
17
use hipanel\actions\SmartPerformAction;
18
use hipanel\actions\SmartUpdateAction;
19
use hipanel\actions\ValidateFormAction;
20
use hipanel\actions\ViewAction;
21
use hipanel\modules\finance\logic\TariffManagerFactory;
22
use Yii;
23
24
class TariffController extends \hipanel\base\CrudController
25 1
{
26
    public function actions()
27
    {
28
        return [
29 1
            'set-orientation' => [
30
                'class' => OrientationAction::class,
31 1
                'allowedRoutes' => [
32 1
                    '@tariff/index'
33 1
                ]
34
            ],
35 1
            'index' => [
36 1
                'class' => IndexAction::class,
37
            ],
38 1
            'search' => [
39 1
                'class' => SearchAction::class,
40
            ],
41 1
            'validate-form' => [
42 1
                'class' => ValidateFormAction::class,
43
            ],
44 1
            'set-note' => [
45 1
                'class' => SmartUpdateAction::class,
46 1
                'success' => Yii::t('hipanel', 'Note updated'),
47
            ],
48 1
            'delete' => [
49 1
                'class' => SmartPerformAction::class,
50 1
                'success' => Yii::t('hipanel/finance/tariff', 'Tariff deleted'),
51 1
            ],
52
        ];
53
    }
54
55 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...
56
    {
57
        $manager = TariffManagerFactory::createByType('domain');
58
59
        if (Yii::$app->request->isPost && $manager->model->load(Yii::$app->request->post())) {
60
            $manager->insert();
61
            return $this->redirect(['view', 'id' => $manager->model->id]);
62
        }
63
64
        return $this->render('domain/create', ['model' => $manager->model]);
65
    }
66
67 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...
68
    {
69
        $manager = TariffManagerFactory::createById($id);
70
71
        if (Yii::$app->request->isPost && $manager->model->load(Yii::$app->request->post())) {
72
            $manager->update();
73
            return $this->redirect(['view', 'id' => $manager->model->id]);
74
        }
75
76
        return $this->render($manager->getType() . '/update', ['model' => $manager->model]);
77
    }
78
79
    public function actionView($id)
80
    {
81
        $manager = TariffManagerFactory::createById($id);
82
83
        return $this->render('view', ['manager' => $manager]);
84
    }
85
}
86