UpdateSettings   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 44
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newModel() 0 4 1
A performAction() 0 15 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\cp\actions\settings;
10
11
use Craft;
12
use flipbox\craft\ember\actions\models\CreateModel;
13
use flipbox\patron\models\Settings;
14
use flipbox\patron\Patron;
15
use yii\base\Model;
16
use yii\web\NotFoundHttpException;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 *
22
 * @method array parentNormalizeSiteConfig($config = [])
23
 */
24
class UpdateSettings extends CreateModel
25
{
26
    public $validBodyParams = [
27
        'callbackUrlPath',
28
        'encryptStorageData',
29
        'autoPopulateTokenEnvironments',
30
        'applyProviderEnvironmentsToToken'
31
    ];
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public $statusCodeSuccess = 200;
37
38
    /**
39
     * @param Model $model
40
     * @return bool
41
     * @throws \Throwable
42
     */
43
    protected function performAction(Model $model): bool
44
    {
45
        if (!$model instanceof Settings) {
46
            throw new NotFoundHttpException(sprintf(
47
                "Settings must be an instance of '%s', '%s' given.",
48
                Settings::class,
49
                get_class($model)
50
            ));
51
        }
52
53
        return Craft::$app->getPlugins()->savePluginSettings(
54
            Patron::getInstance(),
55
            $model->toArray()
56
        );
57
    }
58
59
    /**
60
     * @inheritdoc
61
     * @return Settings
62
     */
63
    protected function newModel(array $config = []): Model
64
    {
65
        return clone Patron::getInstance()->getSettings();
66
    }
67
}
68