Completed
Push — master ( 07dbbd...eb9bbd )
by Dmitry
08:54
created

HeldPaymentsController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 99
Duplicated Lines 16.16 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 5
dl 16
loc 99
ccs 0
cts 90
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A modelClassName() 0 4 1
A behaviors() 0 14 1
B actions() 16 76 3

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\OrientationAction;
15
use Yii;
16
use yii\base\Event;
17
use yii\filters\AccessControl;
18
use hipanel\actions\IndexAction;
19
use hipanel\actions\PrepareBulkAction;
20
use hipanel\actions\RedirectAction;
21
use hipanel\actions\SmartUpdateAction;
22
use hipanel\base\CrudController;
23
use hipanel\modules\server\models\Change;
24
25
class HeldPaymentsController extends CrudController
26
{
27
    public static function modelClassName()
28
    {
29
        return Change::class;
30
    }
31
32
    public function behaviors()
33
    {
34
        return array_merge(parent::behaviors(), [
35
            'access' => [
36
                'class' => AccessControl::class,
37
                'rules' => [
38
                    [
39
                        'allow'   => true,
40
                        'roles'   => ['resell'],
41
                    ],
42
                ],
43
            ],
44
        ]);
45
    }
46
47
    public function actions()
48
    {
49
        return [
50
            'index' => [
51
                'class' => IndexAction::class,
52
                'findOptions' => ['state' => 'new', 'class' => 'merchant'],
53
                'data' => function ($action) {
0 ignored issues
show
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
                    return [
55
                        'states' => Change::getStates(),
56
                    ];
57
                },
58
            ],
59
            'set-orientation' => [
60
                'class' => OrientationAction::class,
61
                'allowedRoutes' => [
62
                    '@finance/held-payments/index',
63
                ],
64
            ],
65
            'bulk-approve' => [
66
                'class' => SmartUpdateAction::class,
67
                'scenario' => 'approve',
68
                'success' => Yii::t('hipanel:finance:change', 'Held payments were approved successfully'),
69
                'error' => Yii::t('hipanel:finance:change', 'Error occurred during held payments approving'),
70
                'POST html' => [
71
                    'save'    => true,
72
                    'success' => [
73
                        'class' => RedirectAction::class,
74
                    ],
75
                ],
76 View Code Duplication
                'on beforeSave' => function (Event $event) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
77
                    /** @var \hipanel\actions\Action $action */
78
                    $action = $event->sender;
79
                    $comment = Yii::$app->request->post('comment');
80
                    foreach ($action->collection->models as $model) {
81
                        $model->setAttribute('comment', $comment);
82
                    }
83
                },
84
            ],
85
            'bulk-approve-modal' => [
86
                'class' => PrepareBulkAction::class,
87
                'scenario' => 'approve',
88
                'view' => '_bulkApprove',
89
                'findOptions' => [
90
                    'state' => Change::STATE_NEW
91
                ]
92
            ],
93
            'bulk-reject' => [
94
                'class' => SmartUpdateAction::class,
95
                'scenario' => 'reject',
96
                'success' => Yii::t('hipanel:finance:change', 'Held payments were rejected successfully'),
97
                'error' => Yii::t('hipanel:finance:change', 'Error occurred during held payments rejecting'),
98
                'POST html' => [
99
                    'save'    => true,
100
                    'success' => [
101
                        'class' => RedirectAction::class,
102
                    ],
103
                ],
104 View Code Duplication
                'on beforeSave' => function (Event $event) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
105
                    /** @var \hipanel\actions\Action $action */
106
                    $action = $event->sender;
107
                    $comment = Yii::$app->request->post('comment');
108
                    foreach ($action->collection->models as $model) {
109
                        $model->setAttribute('comment', $comment);
110
                    }
111
                },
112
            ],
113
            'bulk-reject-modal' => [
114
                'class' => PrepareBulkAction::class,
115
                'scenario' => 'reject',
116
                'view' => '_bulkReject',
117
                'findOptions' => [
118
                    'state' => Change::STATE_NEW
119
                ]
120
            ],
121
        ];
122
    }
123
}
124