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

Settings   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
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 36
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 13 2
A alterEnvironmentsColumn() 0 10 1
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