Completed
Push — develop ( 2d4f17...d5975b )
by Nate
05:25
created

GeneralController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 58
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 25 1
A verbs() 0 6 1
A actionSave() 0 12 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp\controllers\settings;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\craft\hubspot\cp\actions\SaveSettings;
14
use flipbox\craft\hubspot\cp\controllers\AbstractController;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class GeneralController extends AbstractController
21
{
22
    /**
23
     * @return array
24
     */
25
    public function behaviors()
26
    {
27
        return ArrayHelper::merge(
28
            parent::behaviors(),
29
            [
30
                'error' => [
31
                    'default' => 'settings'
32
                ],
33
                'redirect' => [
34
                    'only' => ['save'],
35
                    'actions' => [
36
                        'save' => [200]
37
                    ]
38
                ],
39
                'flash' => [
40
                    'actions' => [
41
                        'save' => [
42
                            200 => Craft::t('hubspot', "Settings successfully saved."),
43
                            400 => Craft::t('hubspot', "Failed to save settings.")
44
                        ]
45
                    ]
46
                ]
47
            ]
48
        );
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    protected function verbs(): array
55
    {
56
        return [
57
            'save' => ['post']
58
        ];
59
    }
60
61
    /**
62
     * @return mixed
63
     * @throws \yii\base\InvalidConfigException
64
     */
65
    public function actionSave()
66
    {
67
        /** @var SaveSettings $action */
68
        $action = Craft::createObject([
69
            'class' => SaveSettings::class
70
        ], [
71
            'save',
72
            $this
73
        ]);
74
75
        return $action->runWithParams([]);
76
    }
77
}
78