/**
* {@inheritdoc}
*
* @param OptionalValue $value
*
* @throws UnresolvableValueException
*/
public function resolve(ValueInterface $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : ResolvedValueWithFixtureSet
{
if (null === $this->resolver) {
throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
}
$quantifier = $value->getQuantifier();
if ($quantifier instanceof ValueInterface) {
$resolvedSet = $this->resolver->resolve($quantifier, $fixture, $fixtureSet, $scope, $context);
list($quantifier, $fixtureSet) = [$resolvedSet->getValue(), $resolvedSet->getSet()];
if (false === is_int($quantifier) && false === is_string($quantifier)) {
throw UnresolvableValueExceptionFactory::createForInvalidResolvedQuantifierTypeForOptionalValue($value, $quantifier);
}
}
$realValue = mt_rand(0, 100) <= $quantifier ? $value->getFirstMember() : $value->getSecondMember();
if ($realValue instanceof ValueInterface) {
return $this->resolver->resolve($realValue, $fixture, $fixtureSet, $scope, $context);
}
return new ResolvedValueWithFixtureSet($realValue, $fixtureSet);
}