RbacRuleValidator::validateValue()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 12
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