Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueExceptionFactory::createForInvalidResolvedQuantifierTypeForOptionalValue PHP Méthode

createForInvalidResolvedQuantifierTypeForOptionalValue() public static méthode

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
Résultat UnresolvableValueException
    public static function createForInvalidResolvedQuantifierTypeForOptionalValue(ValueInterface $quantifier, $resolvedQuantifier) : UnresolvableValueException
    {
        return new UnresolvableValueException(sprintf('Expected the quantifier "%s" for the optional value to be resolved into a string, got "%s" instead.', get_class($quantifier), is_object($resolvedQuantifier) ? get_class($resolvedQuantifier) : gettype($resolvedQuantifier)));
    }

Usage Example

 /**
  * {@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);
 }