Code Duplication    Length = 22-22 lines in 2 locations

commands/RoleController.php 2 locations

@@ 44-65 (lines=22) @@
41
     *
42
     * @throws Exception
43
     */
44
    public function actionAssign($roleName, $email)
45
    {
46
        $user = UserModel::findByEmail($email);
47
48
        if (empty($user)) {
49
            throw new Exception(Yii::t('yii2mod.user', 'User is not found.'));
50
        }
51
52
        $role = $this->findRole($roleName);
53
54
        if (in_array($roleName, array_keys($this->_authManager->getRolesByUser($user->id)))) {
55
            $this->stdout(Yii::t('yii2mod.user', 'This role already assigned to this user.') . "\n", Console::FG_RED);
56
57
            return self::EXIT_CODE_NORMAL;
58
        }
59
60
        $this->_authManager->assign($role, $user->id);
61
62
        $this->stdout(Yii::t('yii2mod.user', 'The role has been successfully assigned to the user.') . "\n", Console::FG_GREEN);
63
64
        return self::EXIT_CODE_NORMAL;
65
    }
66
67
    /**
68
     * Revoke role from the user
@@ 77-98 (lines=22) @@
74
     *
75
     * @throws Exception
76
     */
77
    public function actionRevoke($roleName, $email)
78
    {
79
        $user = UserModel::findByEmail($email);
80
81
        if (empty($user)) {
82
            throw new Exception(Yii::t('yii2mod.user', 'User is not found.'));
83
        }
84
85
        $role = $this->findRole($roleName);
86
87
        if (!in_array($roleName, array_keys($this->_authManager->getRolesByUser($user->id)))) {
88
            $this->stdout(Yii::t('yii2mod.user', 'This role is not assigned to this user.') . "\n", Console::FG_RED);
89
90
            return self::EXIT_CODE_NORMAL;
91
        }
92
93
        $this->_authManager->revoke($role, $user->id);
94
95
        $this->stdout(Yii::t('yii2mod.user', 'The role has been successfully revoked from the user.') . "\n", Console::FG_GREEN);
96
97
        return self::EXIT_CODE_NORMAL;
98
    }
99
100
    /**
101
     * Returns the named role.