functionDefinitionRepository->for($callable); $elements = array_map( fn (ParameterDefinition $parameter) => new ShapedArrayElement( new StringValueType($parameter->name), $parameter->type, $parameter->isOptional, $parameter->attributes, ), $function->parameters->toArray(), ); $type = new ShapedArrayType($elements); try { $node = $this->nodeBuilder->build($source, $type, $function->attributes); } catch (MappingLogicalException $exception) { throw new TypeErrorDuringArgumentsMapping($function, $exception); } if ($node->isValid()) { /** @var array */ return $node->value(); } // Transforms the source value if there is only one object argument, to // ensure the source can contain flattened values. if (count($elements) === 1 && $function->parameters->at(0)->type instanceof ObjectType) { $node = $this->nodeBuilder->build($source, $function->parameters->at(0)->type, $function->attributes); if ($node->isValid()) { /** @var array */ return [$function->parameters->at(0)->name => $node->value()]; } } throw new ArgumentsMapperError($source, $type->toString(), $function->signature, $node->messages()); } }