UpdateSettings::performAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 7
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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