GeneralController::verbs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
use flipbox\craft\hubspot\HubSpot;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class GeneralController extends AbstractController
22
{
23
    /**
24
     * @return array
25
     */
26
    public function behaviors()
27
    {
28
        return ArrayHelper::merge(
29
            parent::behaviors(),
30
            [
31
                'error' => [
32
                    'default' => 'settings'
33
                ],
34
                'redirect' => [
35
                    'only' => ['save'],
36
                    'actions' => [
37
                        'save' => [200]
38
                    ]
39
                ],
40
                'flash' => [
41
                    'actions' => [
42
                        'save' => [
43
                            200 => HubSpot::t("Settings successfully saved."),
44
                            400 => HubSpot::t("Failed to save settings.")
45
                        ]
46
                    ]
47
                ]
48
            ]
49
        );
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    protected function verbs(): array
56
    {
57
        return [
58
            'save' => ['post']
59
        ];
60
    }
61
62
    /**
63
     * @return mixed
64
     * @throws \yii\base\InvalidConfigException
65
     */
66
    public function actionSave()
67
    {
68
        /** @var SaveSettings $action */
69
        $action = Craft::createObject([
70
            'class' => SaveSettings::class
71
        ], [
72
            'save',
73
            $this
74
        ]);
75
76
        return $action->runWithParams([]);
77
    }
78
}
79