createForInvalidResolvedQuantifierTypeForOptionalValue() public static method

public static createForInvalidResolvedQuantifierTypeForOptionalValue ( Nelmio\Alice\Definition\ValueInterface $quantifier, null | object | array | float | boolean $resolvedQuantifier ) : UnresolvableValueException
$quantifier Nelmio\Alice\Definition\ValueInterface
$resolvedQuantifier null | object | array | float | boolean
return UnresolvableValueException
Esempio n. 1
0
 /**
  * {@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);
 }