Completed
Push — master ( ea6653...57a239 )
by Dmitry
30:07 queued 15:12
created

PreOrderController::actions()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 42
Code Lines 27

Duplication

Lines 11
Ratio 26.19 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 11
loc 42
rs 8.8571
cc 3
eloc 27
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\server\controllers;
4
5
use hipanel\actions\Action;
6
use hipanel\actions\IndexAction;
7
use hipanel\actions\PrepareBulkAction;
8
use hipanel\actions\RedirectAction;
9
use hipanel\actions\SmartUpdateAction;
10
use hipanel\base\CrudController;
11
use hipanel\modules\server\models\Change;
12
use Yii;
13
use yii\base\Event;
14
15
class PreOrderController extends CrudController
16
{
17
    public static function modelClassName()
18
    {
19
        return Change::class;
20
    }
21
22
    public function actions()
23
    {
24
        return [
25
            'index' => [
26
                'class' => IndexAction::class,
27
                'findOptions' => ['state' => 'new', 'class' => 'serverBuy'],
28
                'data' => function ($action) {
29
                    return [
30
                        'states' => $action->controller->getStates(),
31
                    ];
32
                },
33
            ],
34
            'bulk-approve' => [
35
                'class' => SmartUpdateAction::class,
36
                'scenario' => 'approve',
37
                'success' => Yii::t('hipanel/server', 'Hosting accounts were blocked successfully'),
38
                'error' => Yii::t('hipanel/server', 'Error during the hosting accounts blocking'),
39
                'POST html' => [
40
                    'save'    => true,
41
                    'success' => [
42
                        'class' => RedirectAction::class,
43
                    ],
44
                ],
45 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...
46
                    /** @var \hipanel\actions\Action $action */
47
                    $action = $event->sender;
48
                    $comment = Yii::$app->request->post('comment');
49
                    if (!empty($type)) {
0 ignored issues
show
Bug introduced by
The variable $type seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
50
                        foreach ($action->collection->models as $model) {
51
                            $model->setAttribute('comment', $comment);
52
53
                        }
54
                    }
55
                },
56
            ],
57
            'bulk-approve-modal' => [
58
                'class' => PrepareBulkAction::class,
59
                'scenario' => 'approve',
60
                'view' => '_bulkApprove',
61
            ],
62
        ];
63
    }
64
65
    public function getStates()
66
    {
67
        return $this->getRefs('state,change', [], 'hipanel/server');
0 ignored issues
show
Unused Code introduced by
The call to PreOrderController::getRefs() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
    }
69
70
}
71