Completed
Push — master ( dfce01...4497f6 )
by Andrii
11:42 queued 08:42
created

ConfigController::actions()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 68
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 68
ccs 0
cts 60
cp 0
rs 8.8452
c 0
b 0
f 0
cc 5
nc 1
nop 0
crap 30

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
namespace hipanel\modules\server\controllers;
4
5
use hipanel\actions\IndexAction;
6
use hipanel\actions\SmartCreateAction;
7
use hipanel\actions\SmartDeleteAction;
8
use hipanel\actions\SmartPerformAction;
9
use hipanel\actions\SmartUpdateAction;
10
use hipanel\actions\ValidateFormAction;
11
use hipanel\actions\ViewAction;
12
use hipanel\base\CrudController;
13
use Yii;
14
15
class ConfigController extends CrudController
16
{
17
    public function actions()
18
    {
19
        return array_merge(parent::actions(), [
20
            'index' => [
21
                'class' => IndexAction::class,
22
            ],
23
            'view' => [
24
                'class' => ViewAction::class,
25
            ],
26
            'create' => [
27
                'class' => SmartCreateAction::class,
28
                'scenario' => 'create',
29
                'success' => Yii::t(
30
                    'hipanel:server:config',
31
                    'The configuration has been successfully created'
32
                ),
33
            ],
34
            'update' => [
35
                'class' => SmartUpdateAction::class,
36
                'scenario' => 'update',
37
                'success' => Yii::t(
38
                    'hipanel:server:config',
39
                    'The configuration has been successfully updated'
40
                ),
41
            ],
42
            'delete' => [
43
                'class' => SmartDeleteAction::class,
44
                'success' => Yii::t(
45
                    'hipanel:server:config',
46
                    'The configuration has been deleted'
47
                ),
48
                'error' => Yii::t(
49
                    'hipanel:server:config',
50
                    'Failed to delete the configuration'
51
                ),
52
            ],
53
            'enable' => [
54
                'class' => SmartPerformAction::class,
55
                'success' => Yii::t(
56
                    'hipanel:server:config',
57
                    'The configuration has been enabled'
58
                ),
59
                'on beforeSave' => function ($event) {
60
                    $action = $event->sender;
61
                    foreach ($action->collection->models as $model) {
62
                        if ($id = Yii::$app->request->get('id')) {
63
                            $model->id = $id;
64
                        }
65
                    }
66
                },
67
            ],
68
            'disable' => [
69
                'class' => SmartPerformAction::class,
70
                'success' => Yii::t(
71
                    'hipanel:server:config',
72
                    'The configuration has been disabled'
73
                ),
74
                'on beforeSave' => function ($event) {
75
                    $action = $event->sender;
76
                    foreach ($action->collection->models as $model) {
77
                        if ($id = Yii::$app->request->get('id')) {
78
                            $model->id = $id;
79
                        }
80
                    }
81
                },
82
            ],
83
            'validate-form' => [
84
                'class' => ValidateFormAction::class,
85
            ],
86
        ]);
87
    }
88
}
89