Completed
Push — develop ( eb3b7f...ef26fd )
by Damien
17:04 queued 06:46
created

AbstractCp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
createNewMigration() 0 1 ?
A saveSettings() 0 15 2
A alterEnvironmentsColumn() 0 10 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 flipbox\saml\core\traits\EnsureSamlPlugin;
14
use yii\base\Model;
15
16
abstract class AbstractCp extends Component
17
{
18
19
    use EnsureSamlPlugin;
20
21
    /**
22
     * @return AbstractAlterEnvironments
23
     */
24
    abstract protected function createNewMigration(): AbstractAlterEnvironments;
25
26
    /**
27
     * @param SettingsInterface $settingsModel
28
     * @return bool
29
     * @throws \Throwable
30
     */
31
    public function saveSettings(SettingsInterface $settingsModel)
32
    {
33
        /** @var Model $settingsModel */
34
35
        // Save plugin settings
36
        if (Craft::$app->getPlugins()->savePluginSettings(
37
            $this->getSamlPlugin(),
38
            $settingsModel->toArray()
0 ignored issues
show
Bug introduced by
The method toArray() does not seem to exist on object<flipbox\saml\core...dels\SettingsInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        )) {
40
            // Alter table
41
            return $this->alterEnvironmentsColumn();
42
        }
43
44
        return false;
45
    }
46
47
    /**
48
     * @return bool
49
     * @throws \Throwable
50
     */
51
    private function alterEnvironmentsColumn(): bool
52
    {
53
        $migration = $this->createNewMigration();
54
55
        ob_start();
56
        $migration->up();
57
        ob_end_clean();
58
59
        return true;
60
    }
61
}
62