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

HeldPaymentsController::actions()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 76
Code Lines 52

Duplication

Lines 16
Ratio 21.05 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 76
ccs 0
cts 72
cp 0
rs 8.9667
cc 3
eloc 52
nc 1
nop 0
crap 12

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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