/**
* @param FixtureInterface $scope
* @param FlagBag $flags
* @param mixed|ValueInterface $value
*
* @throws InvalidScopeException
*
* @return ValueInterface
*/
private function generateValue(FixtureInterface $scope, FlagBag $flags, $value) : ValueInterface
{
$uniqueId = sprintf('%s#%s', $scope->getClassName(), $flags->getKey());
if ('temporary_id' === substr($scope->getId(), 0, 12)) {
throw DenormalizerExceptionFactory::createForInvalidScopeForUniqueValue();
}
if ($value instanceof DynamicArrayValue) {
$uniqueId = uniqid($uniqueId . '::', true);
return new DynamicArrayValue($value->getQuantifier(), new UniqueValue($uniqueId, $value->getElement()));
}
if ($value instanceof ArrayValue) {
$uniqueId = uniqid($uniqueId . '::', true);
$elements = $value->getValue();
foreach ($elements as $key => $element) {
// The key must be the same for each argument: the unique ID is bound to the array, not the argument
// number.
$elements[$key] = new UniqueValue($uniqueId, $element);
}
return new ArrayValue($elements);
}
return new UniqueValue($uniqueId, $value);
}