Completed
Push — master ( ade816...2e2eaf )
by Dmitry
05:09 queued 01:21
created

ReminderController::actions()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 52
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 5
Bugs 0 Features 3
Metric Value
cc 2
eloc 33
c 5
b 0
f 3
nc 1
nop 0
dl 0
loc 52
ccs 0
cts 46
cp 0
crap 6
rs 9.4929

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\controllers;
4
5
use hipanel\actions\IndexAction;
6
use hipanel\actions\OrientationAction;
7
use hipanel\actions\RedirectAction;
8
use hipanel\actions\RenderAjaxAction;
9
use hipanel\actions\RenderJsonAction;
10
use hipanel\actions\SmartCreateAction;
11
use hipanel\actions\SmartDeleteAction;
12
use hipanel\actions\SmartUpdateAction;
13
use hipanel\actions\ValidateFormAction;
14
use yii\web\NotFoundHttpException;
15
16
class ReminderController extends \hipanel\base\CrudController
17
{
18
    public function init()
19
    {
20
        $this->viewPath = '@hipanel/views/reminder';
21
    }
22
23
    public function actions()
24
    {
25
        return [
26
            'set-orientation' => [
27
                'class' => OrientationAction::class,
28
                'allowedRoutes' => [
29
                    'reminder/index'
30
                ]
31
            ],
32
            'validate-form' => [
33
                'class' => ValidateFormAction::class,
34
            ],
35
            'index' => [
36
                'class' => IndexAction::class,
37
                'data' => function ($action, $data) {
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...
Unused Code introduced by
The parameter $data 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...
38
                    return [
39
40
                    ];
41
                },
42
            ],
43
            'create-modal' => [
44
                'class' => SmartCreateAction::class,
45
                'scenario' => 'create',
46
                'view' => 'create-modal',
47
                'data' => function ($action, $data) {
48
                    $object_id = \Yii::$app->request->get('object_id');
49
                    if (empty($object_id)) {
50
                        throw new NotFoundHttpException('Object ID is missing');
51
                    }
52
                    $data['model']->object_id = $object_id;
53
54
                    return $data;
55
                },
56
            ],
57
            'create' => [
58
                'class' => SmartCreateAction::class,
59
                'view' => 'create-modal',
60
            ],
61
            'update' => [
62
                'class' => SmartUpdateAction::class,
63
            ],
64
            'delete' => [
65
                'class' => SmartDeleteAction::class,
66
                'POST html | POST pjax' => [
67
                    'save' => true,
68
                    'success' => [
69
                        'class' => RedirectAction::class,
70
                    ],
71
                ],
72
            ]
73
        ];
74
    }
75
76
    public function getPeriodicityOptions()
77
    {
78
        return $this->getRefs('type,periodicity', 'hipanel/reminder');
79
    }
80
}
81