Completed
Push — develop ( 0ebecd...08b8fb )
by Nate
11:07
created

AbstractController::checkCanMakeAdminChanges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace flipbox\patron\cp\controllers;
4
5
use Craft;
6
use flipbox\craft\ember\filters\FlashMessageFilter;
7
use flipbox\craft\ember\filters\ModelErrorFilter;
8
use flipbox\craft\ember\filters\RedirectFilter;
9
use flipbox\patron\cp\Cp;
10
use yii\helpers\ArrayHelper;
11
12
/**
13
 * @property Cp $module
14
 */
15
abstract class AbstractController extends \flipbox\craft\ember\controllers\AbstractController
16
{
17
    /**
18
     * @return array
19
     */
20
    public function behaviors()
21
    {
22
        return ArrayHelper::merge(
23
            parent::behaviors(),
24
            [
25
                'redirect' => [
26
                    'class' => RedirectFilter::class
27
                ],
28
                'error' => [
29
                    'class' => ModelErrorFilter::class
30
                ],
31
                'flash' => [
32
                    'class' => FlashMessageFilter::class
33
                ]
34
            ]
35
        );
36
    }
37
38
    /**
39
     * @return bool
40
     * @throws \yii\web\ForbiddenHttpException
41
     */
42
    public function checkAdminChanges(): bool
43
    {
44
        $this->checkAdminAccess();
45
        return $this->checkCanMakeAdminChanges();
46
    }
47
48
    /**
49
     * @return bool
50
     * @throws \yii\web\ForbiddenHttpException
51
     */
52
    public function checkAdminAccess(): bool
53
    {
54
        $this->requireAdmin();
55
        return true;
56
    }
57
58
    /**
59
     * @return bool
60
     * @throws \yii\web\ForbiddenHttpException
61
     */
62
    public function checkCanMakeAdminChanges(): bool
63
    {
64
        return !Craft::$app->getProjectConfig()->readOnly;
65
    }
66
}
67