AddressController::actions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 9.232
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\hosting\controllers;
4
5
use hipanel\actions\IndexAction;
6
use hipanel\actions\SmartCreateAction;
7
use hipanel\actions\SmartDeleteAction;
8
use hipanel\actions\SmartUpdateAction;
9
use hipanel\actions\ValidateFormAction;
10
use hipanel\actions\ViewAction;
11
use hipanel\base\CrudController;
12
use hipanel\filters\EasyAccessControl;
13
use hipanel\modules\hosting\models\PrefixSearch;
14
use yii\helpers\ArrayHelper;
15
use Yii;
16
17
class AddressController extends CrudController
18
{
19 View Code Duplication
    public function behaviors(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
20
    {
21
        return ArrayHelper::merge(parent::behaviors(), [
22
            [
23
                'class' => EasyAccessControl::class,
24
                'actions' => [
25
                    'create' => 'admin',
26
                    'update' => 'admin',
27
                    'delete' => 'admin',
28
                    '*' => 'ip.read',
29
                ],
30
            ],
31
        ]);
32
    }
33
34
    public function actions()
35
    {
36
        return array_merge(parent::actions(), [
37
            'index' => [
38
                'class' => IndexAction::class,
39
            ],
40
            'view' => [
41
                'class' => ViewAction::class,
42
                'data' => static function ($action) {
43
                    $prefixSearch = new PrefixSearch();
44
                    $dataProvider = $prefixSearch->search([
45
                        $prefixSearch->formName() => [
46
                            'ip_cntd' => $action->getCollection()->first->ip,
47
                        ],
48
                    ]);
49
50
                    return ['parentPrefixesDataProvider' => $dataProvider];
51
                },
52
            ],
53
            'create' => [
54
                'class' => SmartCreateAction::class,
55
                'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was created successfully'),
56
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to add a prefix'),
57
            ],
58
            'update' => [
59
                'class' => SmartUpdateAction::class,
60
                'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was updated successfully'),
61
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to update a prefix'),
62
            ],
63
            'delete' => [
64
                'class' => SmartDeleteAction::class,
65
                'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was deleted successfully'),
66
            ],
67
            'validate-form' => [
68
                'class' => ValidateFormAction::class,
69
            ],
70
            'set-note' => [
71
                'class' => SmartUpdateAction::class,
72
                'success' => Yii::t('hipanel.hosting.ipam', 'Description was changed'),
73
                'error' => Yii::t('hipanel.hosting.ipam', 'Failed to change description'),
74
            ],
75
        ]);
76
    }
77
}
78