UserTypesController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 0
loc 120
ccs 0
cts 84
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 35 1
A verbs() 0 8 1
A actionCreate() 0 14 1
A actionUpdate() 0 18 2
A actionDelete() 0 18 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\cp\controllers\settings;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\organizations\actions\users\CreateUserType;
14
use flipbox\organizations\actions\users\DeleteUserType;
15
use flipbox\organizations\actions\users\UpdateUserType;
16
use flipbox\organizations\cp\controllers\AbstractController;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
class UserTypesController extends AbstractController
23
{
24
    /**
25
     * @return array
26
     */
27
    public function behaviors()
28
    {
29
        return ArrayHelper::merge(
30
            parent::behaviors(),
31
            [
32
                'error' => [
33
                    'default' => 'userType'
34
                ],
35
                'redirect' => [
36
                    'only' => ['create', 'update', 'delete'],
37
                    'actions' => [
38
                        'create' => [201],
39
                        'update' => [200],
40
                        'delete' => [204],
41
                    ]
42
                ],
43
                'flash' => [
44
                    'actions' => [
45
                        'create' => [
46
                            201 => Craft::t('organizations', "User Type successfully created."),
47
                            401 => Craft::t('organizations', "Failed to create User Type.")
48
                        ],
49
                        'update' => [
50
                            200 => Craft::t('organizations', "User Type successfully updated."),
51
                            401 => Craft::t('organizations', "Failed to update User Type.")
52
                        ],
53
                        'delete' => [
54
                            204 => Craft::t('organizations', "User Type successfully deleted."),
55
                            401 => Craft::t('organizations', "Failed to delete User Type.")
56
                        ]
57
                    ]
58
                ]
59
            ]
60
        );
61
    }
62
63
    /**
64
     * @return array
65
     */
66
    protected function verbs(): array
67
    {
68
        return [
69
            'create' => ['post'],
70
            'update' => ['post', 'put'],
71
            'delete' => ['post', 'delete']
72
        ];
73
    }
74
75
    /**
76
     * @return mixed
77
     * @throws \yii\base\InvalidConfigException
78
     */
79
    public function actionCreate()
80
    {
81
        /** @var CreateUserType $action */
82
        $action = Craft::createObject([
83
            'class' => CreateUserType::class
84
        ], [
85
            'create',
86
            $this
87
        ]);
88
89
        $response = $action->runWithParams([]);
90
91
        return $response;
92
    }
93
94
    /**
95
     * @param string|int|null $type
96
     * @return mixed
97
     * @throws \yii\base\InvalidConfigException
98
     */
99
    public function actionUpdate($type = null)
100
    {
101
        if (null === $type) {
102
            $type = Craft::$app->getRequest()->getBodyParam('type');
103
        }
104
105
        /** @var UpdateUserType $action */
106
        $action = Craft::createObject([
107
            'class' => UpdateUserType::class
108
        ], [
109
            'update',
110
            $this
111
        ]);
112
113
        return $action->runWithParams([
114
            'type' => $type
115
        ]);
116
    }
117
118
    /**
119
     * @param string|int|null $type
120
     * @return mixed
121
     * @throws \yii\base\InvalidConfigException
122
     */
123
    public function actionDelete($type = null)
124
    {
125
        if (null === $type) {
126
            $type = Craft::$app->getRequest()->getBodyParam('type');
127
        }
128
129
        /** @var DeleteUserType $action */
130
        $action = Craft::createObject([
131
            'class' => DeleteUserType::class
132
        ], [
133
            'delete',
134
            $this
135
        ]);
136
137
        return $action->runWithParams([
138
            'type' => $type
139
        ]);
140
    }
141
}
142