RouteRule::execute()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
c 0
b 0
f 0
rs 9.6111
cc 5
nc 6
nop 3
1
<?php
2
3
namespace toir427\admin\components;
4
5
use Yii;
6
use yii\rbac\Rule;
7
8
/**
9
 * RouteRule Rule for check route with extra params.
10
 *
11
 * @author Misbahul D Munir <[email protected]>
12
 * @since 1.0
13
 */
14
class RouteRule extends Rule
15
{
16
    const RULE_NAME = 'route_rule';
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public $name = self::RULE_NAME;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function execute($user, $item, $params)
27
    {
28
        $routeParams = isset($item->data['params']) ? $item->data['params'] : [];
29
        foreach ($routeParams as $key => $value) {
30
            if (!array_key_exists($key, $params) || $params[$key] != $value) {
31
                return false;
32
            }
33
        }
34
        return true;
35
    }
36
}
37