Completed
Push — master ( 80f949...488989 )
by Xu
63:17 queued 57:43
created

RbacValidator::validateValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 9
rs 9.2
1
<?php
2
/**
3
 * @link http://www.tintsoft.com/
4
 * @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd.
5
 * @license http://www.tintsoft.com/license/
6
 */
7
8
9
namespace yuncms\validators;
10
11
use Yii;
12
use yii\validators\Validator;
13
14
class RbacValidator extends Validator
15
{
16
    /** @var \yii\rbac\DbManager */
17
    protected $manager;
18
19
    /** @inheritdoc */
20
    public function init()
21
    {
22
        parent::init();
23
        $this->manager = Yii::$app->authManager;
0 ignored issues
show
Documentation Bug introduced by
Yii::app->authManager is of type yii\rbac\ManagerInterface, but the property $manager was declared to be of type yii\rbac\DbManager. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
24
    }
25
26
    /** @inheritdoc */
27
    protected function validateValue($value)
28
    {
29
        if (!is_array($value)) {
30
            return [Yii::t('yuncms', 'Invalid value'), []];
31
        }
32
33
        foreach ($value as $val) {
34
            if ($this->manager->getItem($val) == null) {
35
                return [Yii::t('yuncms', 'There is neither role nor permission with name "{0}"', [$val]), []];
36
            }
37
        }
38
    }
39
}