Skip to content

Commit

Permalink
fix: simplify result variable generation by skipping string-to-typed …
Browse files Browse the repository at this point in the history
…object conversion
  • Loading branch information
wazelin committed Feb 15, 2024
1 parent 507bafa commit da0eca0
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/qtism/runtime/common/Variable.php
Original file line number Diff line number Diff line change
@@ -25,13 +25,12 @@

use InvalidArgumentException;
use qtism\common\datatypes\QtiDatatype;
use qtism\common\datatypes\QtiFile;
use qtism\common\datatypes\QtiScalar;
use qtism\common\enums\BaseType;
use qtism\common\enums\Cardinality;
use qtism\data\state\Value;
use qtism\data\state\ValueCollection;
use qtism\data\state\VariableDeclaration;
use qtism\data\storage\Utils as StorageUtils;
use qtism\runtime\common\Utils as RuntimeUtils;
use UnexpectedValueException;

@@ -577,19 +576,11 @@ public function getDataModelValues(): ValueCollection

/**
* @param QtiDatatype $value
* @param int|null $baseType
* @return Value
*/
private function createValue(QtiDatatype $value, int $baseType = null): Value
private function createValue(QtiDatatype $value): Value
{
if (!$value instanceof QtiFile || !$this->isFile()) {
$value = StorageUtils::stringToDatatype(
(string)$value,
$baseType ?? $this->getBaseType()
);
}

return new Value($value);
return new Value($value instanceof QtiScalar ? $value->getValue() : $value);
}

/**
@@ -598,7 +589,7 @@ private function createValue(QtiDatatype $value, int $baseType = null): Value
*/
private function createRecordValue(QtiDatatype $value): Value
{
$value = $this->createValue($value, $value->getBaseType());
$value = $this->createValue($value);
$value->setPartOfRecord(true);
return $value;
}

0 comments on commit da0eca0

Please sign in to comment.