Code Duplication    Length = 25-27 lines in 2 locations

models/Assignment.php 2 locations

@@ 41-67 (lines=27) @@
38
     * @param array $items
39
     * @return integer number of successful grand
40
     */
41
    public function assign($items)
42
    {
43
        $manager = Configs::authManager();
44
        $success = 0;
45
46
        $current_user_id = Yii::$app->getUser()->getId();
47
48
        foreach ($items as $name) {
49
            try {
50
                $verify_result = $manager->checkAccess($current_user_id, $name);
51
52
                Yii::debug("verify role|permission: $name, result: "
53
                    . ($verify_result ? "Y" : "N"));
54
55
                if ($verify_result) {
56
                    $item = $manager->getRole($name);
57
                    $item = $item ?: $manager->getPermission($name);
58
                    $manager->assign($item, $this->id);
59
                    $success++;
60
                }
61
            } catch (\Exception $exc) {
62
                Yii::error($exc->getMessage(), __METHOD__);
63
            }
64
        }
65
        Helper::invalidate();
66
        return $success;
67
    }
68
69
    /**
70
     * Revokes a roles from a user.
@@ 74-98 (lines=25) @@
71
     * @param array $items
72
     * @return integer number of successful revoke
73
     */
74
    public function revoke($items)
75
    {
76
        $current_user_id = Yii::$app->getUser()->getId();
77
        $manager = Configs::authManager();
78
        $success = 0;
79
        foreach ($items as $name) {
80
            try {
81
                $verify_result = $manager->checkAccess($current_user_id, $name);
82
83
                Yii::debug("verify role|permission: $name, result: "
84
                    . ($verify_result ? "Y" : "N"));
85
86
                if ($verify_result) {
87
                    $item = $manager->getRole($name);
88
                    $item = $item ?: $manager->getPermission($name);
89
                    $manager->revoke($item, $this->id);
90
                    $success++;
91
                }
92
            } catch (\Exception $exc) {
93
                Yii::error($exc->getMessage(), __METHOD__);
94
            }
95
        }
96
        Helper::invalidate();
97
        return $success;
98
    }
99
100
    /**
101
     * Get all available and assigned roles/permission