Completed
Push — master ( c30a0b...37c0e6 )
by Nate
08:20
created

SaveSettings   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 6 1
A performAction() 0 9 1
A newModel() 0 4 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\actions;
10
11
use Craft;
12
use flipbox\craft\ember\actions\models\CreateModel;
13
use flipbox\craft\hubspot\HubSpot;
14
use flipbox\craft\hubspot\models\Settings;
15
use yii\base\Model;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class SaveSettings extends CreateModel
22
{
23
    /**
24
     * @return array
25
     */
26
    public $validBodyParams = [
27
        'defaultConnection',
28
        'defaultCache'
29
    ];
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public $statusCodeSuccess = 200;
35
36
    /**
37
     * @inheritdoc
38
     * @throws \yii\web\UnauthorizedHttpException
39
     */
40
    public function run()
41
    {
42
        return $this->runInternal(
43
            HubSpot::getInstance()->getSettings()
44
        );
45
    }
46
47
    /**
48
     * @inheritdoc
49
     * @param Settings $model
50
     */
51
    protected function performAction(Model $model): bool
52
    {
53
        return Craft::$app->getPlugins()->savePluginSettings(
54
            HubSpot::getInstance(),
55
            $model->toArray(
56
                $this->validBodyParams()
57
            )
58
        );
59
    }
60
61
    /**
62
     * @inheritdoc
63
     * @return Settings
64
     */
65
    protected function newModel(array $config = []): Model
66
    {
67
        return clone HubSpot::getInstance()->getSettings();
68
    }
69
}
70