BaseValidateComponent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 3
A getAuthManager() 0 3 1
A setAuthManager() 0 3 1
1
<?php
2
3
namespace Itstructure\RbacModule\components;
4
5
use Yii;
6
use yii\base\{Component, InvalidConfigException};
7
use yii\rbac\ManagerInterface;
8
9
/**
10
 * Class BaseValidateComponent
11
 *
12
 * @property ManagerInterface $authManager
13
 *
14
 * @package Itstructure\RbacModule\components
15
 */
16
class BaseValidateComponent extends Component
17
{
18
    /**
19
     * Auth manager.
20
     *
21
     * @var ManagerInterface
22
     */
23
    private $authManager;
24
25
    /**
26
     * Initialize.
27
     */
28
    public function init()
29
    {
30
        if (null === $this->authManager) {
31
            $this->setAuthManager(Yii::$app->authManager);
32
        }
33
34
        if (null === $this->authManager) {
35
            throw new InvalidConfigException('The authManager is not defined.');
36
        }
37
    }
38
39
    /**
40
     * Returns the authManager (RBAC).
41
     *
42
     * @return ManagerInterface
43
     */
44
    public function getAuthManager(): ManagerInterface
45
    {
46
        return $this->authManager;
47
    }
48
49
    /**
50
     * Set authManager (RBAC).
51
     *
52
     * @param ManagerInterface $authManager
53
     */
54
    public function setAuthManager(ManagerInterface $authManager): void
55
    {
56
        $this->authManager = $authManager;
57
    }
58
}
59