public function process()
    {
        $rule = $this->getRule();
        $state = $this->getState();
        $variableIdentifier = $rule->getIdentifier();
        
        $var = $state->getVariable($variableIdentifier);
        
        if (is_null($var) === true) {
            $msg = "No variable with identifier '${variableIdentifier}' to be set in the current state.";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE);
        } elseif (!$var instanceof ResponseVariable) {
            $msg = "The variable to set '${variableIdentifier}' is not an instance of 'ResponseVariable'.";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE);
        }
        
        try {
            $expressionEngine = new ExpressionEngine($rule->getExpression(), $state);
            $val = $expressionEngine->process();
            $var->setCorrectResponse($val);
        } catch (InvalidArgumentException $e) {
            $varBaseType = (BaseType::getNameByConstant($var->getBaseType())  === false) ? 'noBaseType' : BaseType::getNameByConstant($var->getBaseType());
            $varCardinality = (Cardinality::getNameByConstant($var->getCardinality()));
            // The affected value does not match the baseType of the variable $var.
            $msg = "Unable to set value ${val} to variable '${variableIdentifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_BASETYPE, $e);
        } catch (ExpressionProcessingException $e) {
            $msg = "An error occured while processing the expression bound with the 'SetCorrectResponse' rule.";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e);
        }
    }
public function process()
    {
        $rule = $this->getRule();
        $state = $this->getState();
        $variableIdentifier = $rule->getIdentifier();
        
        $var = $state->getVariable($variableIdentifier);
        
        if (is_null($var) === true) {
            $msg = "No variable with identifier '${variableIdentifier}' to be set in the current state.";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE);
        } elseif (!$var instanceof ResponseVariable) {
            $msg = "The variable to set '${variableIdentifier}' is not an instance of 'ResponseVariable'.";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE);
        }
        
        try {
            $expressionEngine = new ExpressionEngine($rule->getExpression(), $state);
            $val = $expressionEngine->process();
            $var->setCorrectResponse($val);
        } catch (InvalidArgumentException $e) {
            $varBaseType = (BaseType::getNameByConstant($var->getBaseType())  === false) ? 'noBaseType' : BaseType::getNameByConstant($var->getBaseType());
            $varCardinality = (Cardinality::getNameByConstant($var->getCardinality()));
            // The affected value does not match the baseType of the variable $var.
            $msg = "Unable to set value ${val} to variable '${variableIdentifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_BASETYPE, $e);
        } catch (ExpressionProcessingException $e) {
            $msg = "An error occured while processing the expression bound with the 'SetCorrectResponse' rule.";
            throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e);
        }
    }
public function process ( ) { $ rule = $ this -> getRule ( ) ; $ state = $ this -> getState ( ) ; $ variableIdentifier = $ rule -> getIdentifier ( ) ; $ var = $ state -> getVariable ( $ variableIdentifier ) ; if ( is_null ( $ var ) === true ) { $ msg = "No variable with identifier '${variableIdentifier}' to be set in the current state." ; throw new RuleProcessingException ( $ msg , $ this , RuleProcessingException :: NONEXISTENT_VARIABLE ) ; } elseif ( ! $ var instanceof ResponseVariable ) { $ msg = "The variable to set '${variableIdentifier}' is not an instance of 'ResponseVariable'." ; throw new RuleProcessingException ( $ msg , $ this , RuleProcessingException :: WRONG_VARIABLE_TYPE ) ; } try { $ expressionEngine = new ExpressionEngine ( $ rule -> getExpression ( ) , $ state ) ; $ val = $ expressionEngine -> process ( ) ; $ var -> setCorrectResponse ( $ val ) ; } catch ( InvalidArgumentException $ e ) { $ varBaseType = ( BaseType :: getNameByConstant ( $ var -> getBaseType ( ) ) === false ) ? 'noBaseType' : BaseType :: getNameByConstant ( $ var -> getBaseType ( ) ) ; $ varCardinality = ( Cardinality :: getNameByConstant ( $ var -> getCardinality ( ) ) ) ; // The affected value does not match the baseType of the variable $var. $ msg = "Unable to set value ${val} to variable '${variableIdentifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType})." ; throw new RuleProcessingException ( $ msg , $ this , RuleProcessingException :: WRONG_VARIABLE_BASETYPE , $ e ) ; } catch ( ExpressionProcessingException $ e ) { $ msg = "An error occured while processing the expression bound with the 'SetCorrectResponse' rule." ; throw new RuleProcessingException ( $ msg , $ this , RuleProcessingException :: RUNTIME_ERROR , $ e ) ; } }
Apply the current SetCorrectResponse rule on the current state.

A RuleProcessingException will be thrown if:

* No variable corresponds to the given identifier in the current state.
* The target variable is not a ResponseVariable.
* The baseType and/or cardinality of the value to be set does not correspond to the baseType and/or cardinality of the target variable.
* An error occurs while processing the expression representing the value to be set.

@throws \qtism\runtime\rules\RuleProcessingException
Apply the current SetCorrectResponse rule on the current state .