Passed
Push — master ( 3e5b55...ab2589 )
by Andrii
03:20
created

RbacController::actionPlantuml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * RBAC implementation for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-rbac
6
 * @package   hipanel-rbac
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\rbac\console;
12
13
use hipanel\rbac\RbacIniterInterface;
14
use hiqdev\yii\compat\yii;
15
use yii\base\Module;
16
17
/**
18
 * Class RbacController.
19
 *
20
 * Usage: `hidev rbac/init`
21
 */
22
class RbacController extends \yii\console\Controller
23
{
24
    /**
25
     * @var RbacIniterInterface
26
     */
27
    protected $initer;
28
29
    public function __construct($id, Module $module, RbacIniterInterface $initer, $config = [])
30
    {
31
        parent::__construct($id, $module, $config);
32
33
        $this->initer = $initer;
34
    }
35
36
    public $defaultAction = 'show';
37
38
    public function actionInit()
39
    {
40
        $auth = yii::getApp()->get('authManager');
41
        $this->initer->init($auth);
0 ignored issues
show
Bug introduced by
It seems like $auth can also be of type mixed and null; however, parameter $auth of hipanel\rbac\RbacIniterInterface::init() does only seem to accept hipanel\rbac\AuthManager, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $this->initer->init(/** @scrutinizer ignore-type */ $auth);
Loading history...
42
    }
43
44
    public function actionReinit()
45
    {
46
        $auth = yii::getApp()->get('authManager');
47
        $this->initer->reinit($auth);
0 ignored issues
show
Bug introduced by
It seems like $auth can also be of type mixed and null; however, parameter $auth of hipanel\rbac\RbacIniterInterface::reinit() does only seem to accept hipanel\rbac\AuthManager, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        $this->initer->reinit(/** @scrutinizer ignore-type */ $auth);
Loading history...
48
    }
49
50
    public function actionShow()
51
    {
52
        $auth = yii::getApp()->get('authManager');
53
54
        echo "Permissions:\n";
55
        $permissions = $auth->getPermissions();
56
        ksort($permissions);
57
        foreach ($permissions as $name => $perm) {
58
            echo "   $perm->name $perm->description\n";
59
        }
60
61
        echo "Roles:\n";
62
        foreach ($auth->getRoles() as $name => $role) {
63
            $children = implode(',', array_keys($auth->getChildren($name)));
64
            printf("   %-12s %s\n", "$role->name:", $children);
65
        }
66
67
        echo "Assignments:\n";
68
        foreach ($auth->getAllAssignments() as $userId => $roles) {
69
            $roles = implode(',', array_keys($roles));
70
            printf("   %-12s %s\n", "$userId:", $roles);
71
        }
72
    }
73
74
    public function actionPlantuml()
75
    {
76
        $path = dirname(__DIR__, 2) . '/docs/test.txt';
77
78
        $auth = yii::getApp()->get('authManager');
79
        $plant = new PlantUML($auth);
80
81
        $uml = $plant->build();
82
83
        file_put_contents($path, $uml);
84
    }
85
}
86