original_string: public function actionRole($user, $operation, $role)
      {
          $user = $this->getUser($user);
          $role = Yii::$app->authManager->getRole($role);
          if ($operation == 'assign') {
              try {
                  $assignment = Yii::$app->authManager->assign($role, $user);
              } catch (\yii\db\IntegrityException $ex) {
                  echo "Failed to assign `" . $role->name . "`.\n";
                  echo "Maybe the role has been assigned.\n";
                  return static::EXIT_CODE_ERROR;
              }
              if ($assignment) {
                  echo "`$role->name`" . " assigned to User (" . $user->getID() . ") successfully.\n";
              } else {
                  echo "Failed to assign `" . $role->name . "`.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          if ($operation == 'revoke') {
              $assignment = Yii::$app->authManager->revoke($role, $user);
              if ($assignment) {
                  echo "`$role->name`" . " revoked from User (" . $user->getID() . ").\n";
              } else {
                  echo "Failed to revoke `" . $role->name . "`.\n";
                  echo "Maybe the role has not been assigned yet.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          echo "Unrecognized operation: $operation.\n";
          echo "The accepted operations are `assign` and `revoke`.\n";
          return static::EXIT_CODE_ERROR;
      }
code: public function actionRole($user, $operation, $role)
      {
          $user = $this->getUser($user);
          $role = Yii::$app->authManager->getRole($role);
          if ($operation == 'assign') {
              try {
                  $assignment = Yii::$app->authManager->assign($role, $user);
              } catch (\yii\db\IntegrityException $ex) {
                  echo "Failed to assign `" . $role->name . "`.\n";
                  echo "Maybe the role has been assigned.\n";
                  return static::EXIT_CODE_ERROR;
              }
              if ($assignment) {
                  echo "`$role->name`" . " assigned to User (" . $user->getID() . ") successfully.\n";
              } else {
                  echo "Failed to assign `" . $role->name . "`.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          if ($operation == 'revoke') {
              $assignment = Yii::$app->authManager->revoke($role, $user);
              if ($assignment) {
                  echo "`$role->name`" . " revoked from User (" . $user->getID() . ").\n";
              } else {
                  echo "Failed to revoke `" . $role->name . "`.\n";
                  echo "Maybe the role has not been assigned yet.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          echo "Unrecognized operation: $operation.\n";
          echo "The accepted operations are `assign` and `revoke`.\n";
          return static::EXIT_CODE_ERROR;
      }
code_tokens: public function actionRole ( $ user , $ operation , $ role ) { $ user = $ this -> getUser ( $ user ) ; $ role = Yii :: $ app -> authManager -> getRole ( $ role ) ; if ( $ operation == 'assign' ) { try { $ assignment = Yii :: $ app -> authManager -> assign ( $ role , $ user ) ; } catch ( \ yii \ db \ IntegrityException $ ex ) { echo "Failed to assign `" . $ role -> name . "`.\n" ; echo "Maybe the role has been assigned.\n" ; return static :: EXIT_CODE_ERROR ; } if ( $ assignment ) { echo "`$role->name`" . " assigned to User (" . $ user -> getID ( ) . ") successfully.\n" ; } else { echo "Failed to assign `" . $ role -> name . "`.\n" ; } return static :: EXIT_CODE_NORMAL ; } if ( $ operation == 'revoke' ) { $ assignment = Yii :: $ app -> authManager -> revoke ( $ role , $ user ) ; if ( $ assignment ) { echo "`$role->name`" . " revoked from User (" . $ user -> getID ( ) . ").\n" ; } else { echo "Failed to revoke `" . $ role -> name . "`.\n" ; echo "Maybe the role has not been assigned yet.\n" ; } return static :: EXIT_CODE_NORMAL ; } echo "Unrecognized operation: $operation.\n" ; echo "The accepted operations are `assign` and `revoke`.\n" ; return static :: EXIT_CODE_ERROR ; }
docstring: Assign a role to user or revoke a role.
  @param User|string|integer $user User ID.
  @param string $operation Only `assign` and `revoke` are acceptable.
  @param string $role Role name.
  @return int
docstring_tokens: Assign a role to user or revoke a role .