/**
  * @param ParserInterface $parser
  * @param string          $value
  *
  * @return mixed|ValueInterface
  */
 private function parseValue(ParserInterface $parser, string $value)
 {
     try {
         return $parser->parse($value);
     } catch (ParseThrowable $throwable) {
         throw DenormalizerExceptionFactory::createForUnparsableValue($value, 0, $throwable);
     }
 }
 /**
  * {@inheritdoc}
  *
  * @throws UnexpectedValueException
  */
 public function denormalize(FixtureInterface $scope, FlagParserInterface $parser, array $unparsedConstructor) : MethodCallInterface
 {
     /** @var int|string|null $firstKey */
     $firstKey = key($unparsedConstructor);
     if (null === $firstKey || is_int($firstKey) || count($unparsedConstructor) > 1 || is_string($firstKey) && preg_match('/\\(.*\\)/', $firstKey)) {
         return new SimpleMethodCall('__construct', $this->argumentDenormalizer->denormalize($scope, $parser, $unparsedConstructor));
     }
     throw DenormalizerExceptionFactory::createForUndenormalizableConstructor();
 }
 /**
  * @inheritdoc
  */
 public function denormalize(FixtureBag $builtFixtures, string $className, string $fixtureId, array $specs, FlagBag $flags) : FixtureBag
 {
     foreach ($this->denormalizers as $denormalizer) {
         if ($denormalizer->canDenormalize($fixtureId)) {
             return $denormalizer->denormalize($builtFixtures, $className, $fixtureId, $specs, $flags);
         }
     }
     throw DenormalizerExceptionFactory::createDenormalizerNotFoundForFixture($fixtureId);
 }
 /**
  * @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);
 }
 /**
  * @inheritdoc
  */
 public function denormalize(FixtureBag $builtFixtures, string $className, string $fixtureId, array $specs, FlagBag $flags) : FixtureBag
 {
     if (null === $this->denormalizer) {
         throw DenormalizerExceptionFactory::createDenormalizerNotFoundUnexpectedCall(__METHOD__);
     }
     if (null === $this->parser) {
         throw FlagParserExceptionFactory::createForExpectedMethodToBeCalledIfHasAParser(__METHOD__);
     }
     $flags = $this->parser->parse($fixtureId)->mergeWith($flags, false);
     $fixtureId = $flags->getKey();
     /**
      * @var FixtureInterface $tempFixture
      * @var FixtureBag       $builtFixtures
      */
     list($tempFixture, $builtFixtures) = $this->denormalizeTemporaryFixture($builtFixtures, $className, $specs, $flags);
     $fixtureIds = $this->buildIds($fixtureId);
     foreach ($fixtureIds as $fixtureId => $valueForCurrent) {
         $builtFixtures = $builtFixtures->with(new TemplatingFixture(new SimpleFixtureWithFlags(new SimpleFixture($fixtureId, $tempFixture->getClassName(), $tempFixture->getSpecs(), (string) $valueForCurrent), $flags->withKey($fixtureId))));
     }
     return $builtFixtures;
 }
 /**
  * @inheritdoc
  */
 public function denormalize(FixtureBag $builtFixtures, string $className, string $fixtureId, array $specs, FlagBag $flags) : FixtureBag
 {
     try {
         return $this->collectionDenormalizer->denormalize($builtFixtures, $className, $fixtureId, $specs, $flags);
     } catch (InvalidScopeException $exception) {
         // Continue to fallback on a more conventional way
     }
     if (null === $this->denormalizer) {
         throw DenormalizerExceptionFactory::createDenormalizerNotFoundUnexpectedCall(__METHOD__);
     }
     if (null === $this->parser) {
         throw FlagParserExceptionFactory::createForExpectedMethodToBeCalledIfHasAParser(__METHOD__);
     }
     $flags = $this->parser->parse($fixtureId)->mergeWith($flags, false);
     $fixtureId = $flags->getKey();
     $fixtureIds = $this->buildIds($fixtureId);
     foreach ($fixtureIds as $fixtureId => $valueForCurrent) {
         $builtFixtures = $this->denormalizeFixture($builtFixtures, $className, $fixtureId, $specs, $flags, (string) $valueForCurrent);
     }
     return $builtFixtures;
 }