Completed
Push — master ( 4b394d...0ca4f0 )
by Damien
09:55
created

AbstractCp::saveSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 */
6
7
namespace flipbox\saml\core\services;
8
9
use Craft;
10
use craft\base\Component;
11
use flipbox\saml\core\migrations\AbstractAlterEnvironments;
12
use flipbox\saml\core\models\SettingsInterface;
13
use yii\base\Model;
14
use flipbox\saml\core\EnsureSAMLPlugin
15
16
abstract class AbstractCp extends Component implements EnsureSAMLPlugin
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ABSTRACT, expecting ',' or ';'
Loading history...
17
{
18
19
    /**
20
     * @return AbstractAlterEnvironments
21
     */
22
    abstract protected function createNewMigration(): AbstractAlterEnvironments;
23
24
    /**
25
     * @param SettingsInterface $settingsModel
26
     * @return bool
27
     * @throws \Throwable
28
     */
29
    public function saveSettings(SettingsInterface $settingsModel)
30
    {
31
        /** @var Model $settingsModel */
32
33
        // Save plugin settings
34
        if (Craft::$app->getPlugins()->savePluginSettings(
35
            $this->getPlugin(),
36
            $settingsModel->toArray()
37
        )) {
38
            // Alter table
39
            return $this->alterEnvironmentsColumn();
40
        }
41
42
        return false;
43
    }
44
45
    /**
46
     * @return bool
47
     * @throws \Throwable
48
     */
49
    private function alterEnvironmentsColumn(): bool
50
    {
51
        $migration = $this->createNewMigration();
52
53
        ob_start();
54
        $migration->up();
55
        ob_end_clean();
56
57
        return true;
58
    }
59
}
60