Completed
Push — master ( e45dbf...3a73d5 )
by Nate
05:43 queued 04:08
created

Settings::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 10
cp 0
rs 9.8333
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\services;
10
11
use Craft;
12
use flipbox\patron\migrations\AlterEnvironments;
13
use flipbox\patron\models\Settings as SettingsModel;
14
use flipbox\patron\Patron;
15
use yii\base\Component;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Settings extends Component
22
{
23
    /**
24
     * @param SettingsModel $settingsModel
25
     * @return bool
26
     * @throws \Throwable
27
     */
28
    public function save(SettingsModel $settingsModel)
29
    {
30
        // Save plugin settings
31
        if (Craft::$app->getPlugins()->savePluginSettings(
32
            Patron::getInstance(),
33
            $settingsModel->toArray()
34
        )) {
35
            // Alter table
36
            return $this->alterEnvironmentsColumn();
37
        }
38
39
        return false;
40
    }
41
42
    /**
43
     * @return bool
44
     * @throws \Throwable
45
     */
46
    private function alterEnvironmentsColumn(): bool
47
    {
48
        $migration = new AlterEnvironments();
49
50
        ob_start();
51
        $migration->up();
52
        ob_end_clean();
53
54
        return true;
55
    }
56
}
57