RbacItemsValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 12 4
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\validators\Validator;
17
18
class RbacItemsValidator extends Validator
19
{
20
    use AuthManagerAwareTrait;
21
22
    protected function validateValue($value)
23
    {
24
        if (!is_array($value)) {
25
            return [Yii::t('usuario', 'Invalid value'), []];
26
        }
27
28
        foreach ($value as $item) {
29
            if ($this->getAuthManager()->getItem($item) === null) {
30
                return [Yii::t('usuario', 'There is neither role nor permission with name "{0}"', [$item]), []];
31
            }
32
        }
33
    }
34
}
35