Completed
Push — master ( f706eb...84b009 )
by Antonio
01:40
created

RbacRuleNameValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 24
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 11 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\AuthManagerAwareTrait;
15
use Yii;
16
use yii\rbac\Rule;
17
use yii\validators\Validator;
18
19
class RbacRuleNameValidator extends Validator
20
{
21
    use AuthManagerAwareTrait;
22
23
    /**
24
     * @var
25
     */
26
    public $previousName;
27
28
    /**
29
     * @inheritdoc
30
     */
31
    protected function validateValue($value)
32
    {
33
        if ($this->previousName != $value) {
34
            $rule = $this->getAuthManager()->getRule($value);
35
36
            if ($rule instanceof Rule) {
37
                return [Yii::t('usuario', 'Rule name {0} is already in use', $value), []];
38
            }
39
        }
40
        return null;
41
    }
42
}
43