URIFilter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 14
Bugs 12 Features 0
Metric Value
wmc 8
eloc 11
c 14
b 12
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isAllowed() 0 7 5
A init() 0 7 3
1
<?php
2
3
namespace dominus77\maintenance\filters;
4
5
use Yii;
6
use yii\helpers\ArrayHelper;
7
use yii\web\Application;
8
use yii\web\NotFoundHttpException;
9
use yii\web\Request;
10
use dominus77\maintenance\Filter;
11
12
/**
13
 * Class URIFilter
14
 * @package dominus77\maintenance\filters
15
 */
16
class URIFilter extends Filter
17
{
18
    /**
19
     * @var array|string
20
     */
21
    public $uri;
22
    /**
23
     * @var Request|null
24
     */
25
    protected $request;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function init()
31
    {
32
        if (Yii::$app instanceof Application) {
33
            $this->request = Yii::$app->request;
34
        }
35
        if (is_string($this->uri)) {
36
            $this->uri = [$this->uri];
37
        }
38
    }
39
40
    /**
41
     * @return bool
42
     * @throws NotFoundHttpException
43
     */
44
    public function isAllowed()
45
    {
46
        if ($this->request && is_array($this->uri) && !empty($this->uri) && $resolve = $this->request->resolve()) {
47
            $this->uri = ArrayHelper::merge($this->uri, ['maintenance/subscribe']);
48
            return (bool)in_array($resolve[0], $this->uri, true);
49
        }
50
        return false;
51
    }
52
}
53