original_string: private function validateAndDenormalize(string $currentClass, string $attribute, $data, ?string $format, array $context)
      {
          if (null === $types = $this->getTypes($currentClass, $attribute)) {
              return $data;
          }
  
          $expectedTypes = [];
          foreach ($types as $type) {
              if (null === $data && $type->isNullable()) {
                  return;
              }
  
              if ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueType()) && Type::BUILTIN_TYPE_OBJECT === $collectionValueType->getBuiltinType()) {
                  $builtinType = Type::BUILTIN_TYPE_OBJECT;
                  $class = $collectionValueType->getClassName().'[]';
  
                  // Fix a collection that contains the only one element
                  // This is special to xml format only
                  if ('xml' === $format && !\is_int(key($data))) {
                      $data = [$data];
                  }
  
                  if (null !== $collectionKeyType = $type->getCollectionKeyType()) {
                      $context['key_type'] = $collectionKeyType;
                  }
              } else {
                  $builtinType = $type->getBuiltinType();
                  $class = $type->getClassName();
              }
  
              $expectedTypes[Type::BUILTIN_TYPE_OBJECT === $builtinType && $class ? $class : $builtinType] = true;
  
              if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {
                  if (!$this->serializer instanceof DenormalizerInterface) {
                      throw new LogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer', $attribute, $class));
                  }
  
                  $childContext = $this->createChildContext($context, $attribute, $format);
                  if ($this->serializer->supportsDenormalization($data, $class, $format, $childContext)) {
                      return $this->serializer->denormalize($data, $class, $format, $childContext);
                  }
              }
  
              // JSON only has a Number type corresponding to both int and float PHP types.
              // PHP's json_encode, JavaScript's JSON.stringify, Go's json.Marshal as well as most other JSON encoders convert
              // floating-point numbers like 12.0 to 12 (the decimal part is dropped when possible).
              // PHP's json_decode automatically converts Numbers without a decimal part to integers.
              // To circumvent this behavior, integers are converted to floats when denormalizing JSON based formats and when
              // a float is expected.
              if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && false !== strpos($format, JsonEncoder::FORMAT)) {
                  return (float) $data;
              }
  
              if (('is_'.$builtinType)($data)) {
                  return $data;
              }
          }
  
          if ($context[self::DISABLE_TYPE_ENFORCEMENT] ?? $this->defaultContext[self::DISABLE_TYPE_ENFORCEMENT] ?? false) {
              return $data;
          }
  
          throw new NotNormalizableValueException(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute, $currentClass, implode('", "', array_keys($expectedTypes)), \gettype($data)));
      }
code: private function validateAndDenormalize(string $currentClass, string $attribute, $data, ?string $format, array $context)
      {
          if (null === $types = $this->getTypes($currentClass, $attribute)) {
              return $data;
          }
  
          $expectedTypes = [];
          foreach ($types as $type) {
              if (null === $data && $type->isNullable()) {
                  return;
              }
  
              if ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueType()) && Type::BUILTIN_TYPE_OBJECT === $collectionValueType->getBuiltinType()) {
                  $builtinType = Type::BUILTIN_TYPE_OBJECT;
                  $class = $collectionValueType->getClassName().'[]';
  
                  // Fix a collection that contains the only one element
                  // This is special to xml format only
                  if ('xml' === $format && !\is_int(key($data))) {
                      $data = [$data];
                  }
  
                  if (null !== $collectionKeyType = $type->getCollectionKeyType()) {
                      $context['key_type'] = $collectionKeyType;
                  }
              } else {
                  $builtinType = $type->getBuiltinType();
                  $class = $type->getClassName();
              }
  
              $expectedTypes[Type::BUILTIN_TYPE_OBJECT === $builtinType && $class ? $class : $builtinType] = true;
  
              if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {
                  if (!$this->serializer instanceof DenormalizerInterface) {
                      throw new LogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer', $attribute, $class));
                  }
  
                  $childContext = $this->createChildContext($context, $attribute, $format);
                  if ($this->serializer->supportsDenormalization($data, $class, $format, $childContext)) {
                      return $this->serializer->denormalize($data, $class, $format, $childContext);
                  }
              }
  
              // JSON only has a Number type corresponding to both int and float PHP types.
              // PHP's json_encode, JavaScript's JSON.stringify, Go's json.Marshal as well as most other JSON encoders convert
              // floating-point numbers like 12.0 to 12 (the decimal part is dropped when possible).
              // PHP's json_decode automatically converts Numbers without a decimal part to integers.
              // To circumvent this behavior, integers are converted to floats when denormalizing JSON based formats and when
              // a float is expected.
              if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && false !== strpos($format, JsonEncoder::FORMAT)) {
                  return (float) $data;
              }
  
              if (('is_'.$builtinType)($data)) {
                  return $data;
              }
          }
  
          if ($context[self::DISABLE_TYPE_ENFORCEMENT] ?? $this->defaultContext[self::DISABLE_TYPE_ENFORCEMENT] ?? false) {
              return $data;
          }
  
          throw new NotNormalizableValueException(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute, $currentClass, implode('", "', array_keys($expectedTypes)), \gettype($data)));
      }
code_tokens: private function validateAndDenormalize ( string $ currentClass , string $ attribute , $ data , ? string $ format , array $ context ) { if ( null === $ types = $ this -> getTypes ( $ currentClass , $ attribute ) ) { return $ data ; } $ expectedTypes = [ ] ; foreach ( $ types as $ type ) { if ( null === $ data && $ type -> isNullable ( ) ) { return ; } if ( $ type -> isCollection ( ) && null !== ( $ collectionValueType = $ type -> getCollectionValueType ( ) ) && Type :: BUILTIN_TYPE_OBJECT === $ collectionValueType -> getBuiltinType ( ) ) { $ builtinType = Type :: BUILTIN_TYPE_OBJECT ; $ class = $ collectionValueType -> getClassName ( ) . '[]' ; // Fix a collection that contains the only one element // This is special to xml format only if ( 'xml' === $ format && ! \ is_int ( key ( $ data ) ) ) { $ data = [ $ data ] ; } if ( null !== $ collectionKeyType = $ type -> getCollectionKeyType ( ) ) { $ context [ 'key_type' ] = $ collectionKeyType ; } } else { $ builtinType = $ type -> getBuiltinType ( ) ; $ class = $ type -> getClassName ( ) ; } $ expectedTypes [ Type :: BUILTIN_TYPE_OBJECT === $ builtinType && $ class ? $ class : $ builtinType ] = true ; if ( Type :: BUILTIN_TYPE_OBJECT === $ builtinType ) { if ( ! $ this -> serializer instanceof DenormalizerInterface ) { throw new LogicException ( sprintf ( 'Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer' , $ attribute , $ class ) ) ; } $ childContext = $ this -> createChildContext ( $ context , $ attribute , $ format ) ; if ( $ this -> serializer -> supportsDenormalization ( $ data , $ class , $ format , $ childContext ) ) { return $ this -> serializer -> denormalize ( $ data , $ class , $ format , $ childContext ) ; } } // JSON only has a Number type corresponding to both int and float PHP types. // PHP's json_encode, JavaScript's JSON.stringify, Go's json.Marshal as well as most other JSON encoders convert // floating-point numbers like 12.0 to 12 (the decimal part is dropped when possible). // PHP's json_decode automatically converts Numbers without a decimal part to integers. // To circumvent this behavior, integers are converted to floats when denormalizing JSON based formats and when // a float is expected. if ( Type :: BUILTIN_TYPE_FLOAT === $ builtinType && \ is_int ( $ data ) && false !== strpos ( $ format , JsonEncoder :: FORMAT ) ) { return ( float ) $ data ; } if ( ( 'is_' . $ builtinType ) ( $ data ) ) { return $ data ; } } if ( $ context [ self :: DISABLE_TYPE_ENFORCEMENT ] ?? $ this -> defaultContext [ self :: DISABLE_TYPE_ENFORCEMENT ] ?? false ) { return $ data ; } throw new NotNormalizableValueException ( sprintf ( 'The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).' , $ attribute , $ currentClass , implode ( '", "' , array_keys ( $ expectedTypes ) ) , \ gettype ( $ data ) ) ) ; }
docstring: Validates the submitted data and denormalizes it.
  
  @param mixed $data
  
  @return mixed
  
  @throws NotNormalizableValueException
  @throws LogicException
docstring_tokens: Validates the submitted data and denormalizes it .