RbacRuleValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 17
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Validator;
13
14
use Da\User\Traits\ContainerAwareTrait;
15
use Exception;
16
use Yii;
17
use yii\rbac\Rule;
18
use yii\validators\Validator;
19
20
class RbacRuleValidator extends Validator
21
{
22
    use ContainerAwareTrait;
23
24
    protected function validateValue($value)
25
    {
26
        try {
27
            $rule = $this->make($value);
28
29
            if (!($rule instanceof Rule)) {
30
                return [Yii::t('usuario', 'Rule class must extend "yii\\rbac\\Rule".'), []];
31
            }
32
        } catch (Exception $e) {
33
            return [Yii::t('usuario', 'Authentication rule class {0} can not be instantiated', $value), []];
34
        }
35
    }
36
}
37