Completed
Push — master ( 444139...b6b37e )
by Damien
09:32
created

AbstractSettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 73
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 25 1
A verbs() 0 6 1
A actionSave() 0 16 1
A checkUpdateAccess() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dsmrt
5
 * Date: 3/9/18
6
 * Time: 2:48 PM
7
 */
8
9
namespace flipbox\saml\core\controllers;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\saml\core\AbstractPlugin;
14
use flipbox\saml\core\traits\EnsureSamlPlugin;
15
use yii\base\Action;
16
17
/**
18
 * Class AbstractGeneralController
19
 * @package flipbox\saml\core\controllers\cp\view
20
 */
21
abstract class AbstractSettingsController extends AbstractController
22
{
23
    use EnsureSamlPlugin;
24
25
    /**
26
     * @return array
27
     */
28
    public function behaviors()
29
    {
30
        return ArrayHelper::merge(
31
            parent::behaviors(),
32
            [
33
                'error'    => [
34
                    'default' => 'save'
35
                ],
36
                'redirect' => [
37
                    'only'    => ['save'],
38
                    'actions' => [
39
                        'save' => [200]
40
                    ]
41
                ],
42
                'flash'    => [
43
                    'actions' => [
44
                        'save' => [
45
                            200 => \Craft::t('saml-sp', "Settings successfully updated."),
46
                            401 => \Craft::t('saml-sp', "Failed to update settings.")
47
                        ]
48
                    ]
49
                ]
50
            ]
51
        );
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    protected function verbs(): array
58
    {
59
        return [
60
            'save' => ['post', 'put']
61
        ];
62
    }
63
64
    /**
65
     * @return mixed
66
     * @throws \yii\base\InvalidConfigException
67
     */
68
    public function actionSave()
69
    {
70
        $entityId = Craft::$app->request->getRequiredParam('entityId');
71
        /** @var AbstractPlugin $plugin */
72
        $plugin = $this->getSamlPlugin();
0 ignored issues
show
Unused Code introduced by
$plugin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
74
        $settings = [
75
            'entityId' => $entityId
76
        ];
77
78
        Craft::$app->plugins->savePluginSettings(
79
            $this->getSamlPlugin(),
80
            $settings
81
        );
82
        return $this->redirectToPostedUrl();
83
    }
84
85
    /**
86
     * @return bool
87
     * @throws \yii\web\ForbiddenHttpException
88
     */
89
    public function checkUpdateAccess(): bool
90
    {
91
        return $this->checkAdminAccess();
92
    }
93
}
94