mirror of
https://github.com/symfony/serializer.git
synced 2026-03-24 01:12:14 +01:00
CS fixes
This commit is contained in:
@@ -39,14 +39,14 @@ class Context
|
||||
string|array $groups = [],
|
||||
) {
|
||||
if (!$context && !$normalizationContext && !$denormalizationContext) {
|
||||
throw new InvalidArgumentException(sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options must be provided as a non-empty array to "%s".', static::class));
|
||||
throw new InvalidArgumentException(\sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options must be provided as a non-empty array to "%s".', static::class));
|
||||
}
|
||||
|
||||
$this->groups = (array) $groups;
|
||||
|
||||
foreach ($this->groups as $group) {
|
||||
if (!\is_string($group)) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "%s" given.', static::class, get_debug_type($group)));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "%s" given.', static::class, get_debug_type($group)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ class DiscriminatorMap
|
||||
private readonly array $mapping,
|
||||
) {
|
||||
if (empty($typeProperty)) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" given to "%s" cannot be empty.', static::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter "typeProperty" given to "%s" cannot be empty.', static::class));
|
||||
}
|
||||
|
||||
if (empty($mapping)) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "mapping" given to "%s" cannot be empty.', static::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter "mapping" given to "%s" cannot be empty.', static::class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,12 @@ class Groups
|
||||
$this->groups = (array) $groups;
|
||||
|
||||
if (!$this->groups) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter given to "%s" cannot be empty.', static::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" cannot be empty.', static::class));
|
||||
}
|
||||
|
||||
foreach ($this->groups as $group) {
|
||||
if (!\is_string($group) || '' === $group) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a string or an array of non-empty strings.', static::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a string or an array of non-empty strings.', static::class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class MaxDepth
|
||||
public function __construct(private readonly int $maxDepth)
|
||||
{
|
||||
if ($maxDepth <= 0) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a positive integer.', static::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a positive integer.', static::class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class SerializedName
|
||||
public function __construct(private readonly string $serializedName)
|
||||
{
|
||||
if ('' === $serializedName) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a non-empty string.', self::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a non-empty string.', self::class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class SerializedPath
|
||||
try {
|
||||
$this->serializedPath = new PropertyPath($serializedPath);
|
||||
} catch (InvalidPropertyPathException $pathException) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a valid property path.', self::class));
|
||||
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a valid property path.', self::class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class DebugCommand extends Command
|
||||
|
||||
if (!class_exists($class)) {
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->error(sprintf('Class "%s" was not found.', $class));
|
||||
$io->error(\sprintf('Class "%s" was not found.', $class));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class DebugCommand extends Command
|
||||
private function dumpSerializerDataForClass(InputInterface $input, OutputInterface $output, string $class): void
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$title = sprintf('<info>%s</info>', $class);
|
||||
$title = \sprintf('<info>%s</info>', $class);
|
||||
$rows = [];
|
||||
$dump = new Dumper($output);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ final class CsvEncoderContextBuilder implements ContextBuilderInterface
|
||||
public function withDelimiter(?string $delimiter): static
|
||||
{
|
||||
if (null !== $delimiter && 1 !== \strlen($delimiter)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" delimiter must be a single character.', $delimiter));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" delimiter must be a single character.', $delimiter));
|
||||
}
|
||||
|
||||
return $this->with(CsvEncoder::DELIMITER_KEY, $delimiter);
|
||||
@@ -51,7 +51,7 @@ final class CsvEncoderContextBuilder implements ContextBuilderInterface
|
||||
public function withEnclosure(?string $enclosure): static
|
||||
{
|
||||
if (null !== $enclosure && 1 !== \strlen($enclosure)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" enclosure must be a single character.', $enclosure));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" enclosure must be a single character.', $enclosure));
|
||||
}
|
||||
|
||||
return $this->with(CsvEncoder::ENCLOSURE_KEY, $enclosure);
|
||||
@@ -67,7 +67,7 @@ final class CsvEncoderContextBuilder implements ContextBuilderInterface
|
||||
public function withEscapeChar(?string $escapeChar): static
|
||||
{
|
||||
if (null !== $escapeChar && \strlen($escapeChar) > 1) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" escape character must be empty or a single character.', $escapeChar));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" escape character must be empty or a single character.', $escapeChar));
|
||||
}
|
||||
|
||||
return $this->with(CsvEncoder::ESCAPE_CHAR_KEY, $escapeChar);
|
||||
|
||||
@@ -87,7 +87,7 @@ abstract class AbstractNormalizerContextBuilder implements ContextBuilderInterfa
|
||||
|
||||
foreach ($it as $attribute) {
|
||||
if (!\is_string($attribute)) {
|
||||
throw new InvalidArgumentException(sprintf('Each attribute must be a string, "%s" given.', get_debug_type($attribute)));
|
||||
throw new InvalidArgumentException(\sprintf('Each attribute must be a string, "%s" given.', get_debug_type($attribute)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ abstract class AbstractObjectNormalizerContextBuilder extends AbstractNormalizer
|
||||
preg_match_all('/(?<!%)(?:%{2})*%(?<specifier>[a-z])/', $depthKeyPattern, $matches);
|
||||
|
||||
if (2 !== \count($matches['specifier']) || 's' !== $matches['specifier'][0] || 's' !== $matches['specifier'][1]) {
|
||||
throw new InvalidArgumentException(sprintf('The depth key pattern "%s" is not valid. You must set exactly two string placeholders.', $depthKeyPattern));
|
||||
throw new InvalidArgumentException(\sprintf('The depth key pattern "%s" is not valid. You must set exactly two string placeholders.', $depthKeyPattern));
|
||||
}
|
||||
|
||||
return $this->with(AbstractObjectNormalizer::DEPTH_KEY_PATTERN, $depthKeyPattern);
|
||||
|
||||
@@ -55,7 +55,7 @@ final class DateTimeNormalizerContextBuilder implements ContextBuilderInterface
|
||||
try {
|
||||
$timezone = new \DateTimeZone($timezone);
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" timezone is invalid.', $timezone), previous: $e);
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" timezone is invalid.', $timezone), previous: $e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ final class UidNormalizerContextBuilder implements ContextBuilderInterface
|
||||
public function withNormalizationFormat(?string $normalizationFormat): static
|
||||
{
|
||||
if (null !== $normalizationFormat && !\in_array($normalizationFormat, UidNormalizer::NORMALIZATION_FORMATS, true)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" normalization format is not valid.', $normalizationFormat));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" normalization format is not valid.', $normalizationFormat));
|
||||
}
|
||||
|
||||
return $this->with(UidNormalizer::NORMALIZATION_FORMAT_KEY, $normalizationFormat);
|
||||
|
||||
@@ -45,7 +45,7 @@ final class UnwrappingDenormalizerContextBuilder implements ContextBuilderInterf
|
||||
try {
|
||||
new PropertyPath($unwrapPath);
|
||||
} catch (InvalidPropertyPathException $e) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" property path is not valid.', $unwrapPath), previous: $e);
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" property path is not valid.', $unwrapPath), previous: $e);
|
||||
}
|
||||
|
||||
return $this->with(UnwrappingDenormalizer::UNWRAP_PATH, $unwrapPath);
|
||||
|
||||
@@ -36,7 +36,7 @@ class TraceableEncoder implements EncoderInterface, DecoderInterface, Serializer
|
||||
public function encode(mixed $data, string $format, array $context = []): string
|
||||
{
|
||||
if (!$this->encoder instanceof EncoderInterface) {
|
||||
throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested encoder doesn\'t implements "%s".', __METHOD__, EncoderInterface::class));
|
||||
throw new \BadMethodCallException(\sprintf('The "%s()" method cannot be called as nested encoder doesn\'t implements "%s".', __METHOD__, EncoderInterface::class));
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
@@ -62,7 +62,7 @@ class TraceableEncoder implements EncoderInterface, DecoderInterface, Serializer
|
||||
public function decode(string $data, string $format, array $context = []): mixed
|
||||
{
|
||||
if (!$this->encoder instanceof DecoderInterface) {
|
||||
throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested encoder doesn\'t implements "%s".', __METHOD__, DecoderInterface::class));
|
||||
throw new \BadMethodCallException(\sprintf('The "%s()" method cannot be called as nested encoder doesn\'t implements "%s".', __METHOD__, DecoderInterface::class));
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
@@ -51,7 +51,7 @@ class TraceableNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
|
||||
{
|
||||
if (!$this->normalizer instanceof NormalizerInterface) {
|
||||
throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class));
|
||||
throw new \BadMethodCallException(\sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class));
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
@@ -77,7 +77,7 @@ class TraceableNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
|
||||
{
|
||||
if (!$this->normalizer instanceof DenormalizerInterface) {
|
||||
throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, DenormalizerInterface::class));
|
||||
throw new \BadMethodCallException(\sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, DenormalizerInterface::class));
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
@@ -33,7 +33,7 @@ class ChainDecoder implements ContextAwareDecoderInterface
|
||||
* @param array<DecoderInterface> $decoders
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $decoders = []
|
||||
private readonly array $decoders = [],
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -78,6 +78,6 @@ class ChainDecoder implements ContextAwareDecoderInterface
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException(sprintf('No decoder found for format "%s".', $format));
|
||||
throw new RuntimeException(\sprintf('No decoder found for format "%s".', $format));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class ChainEncoder implements ContextAwareEncoderInterface
|
||||
* @param array<EncoderInterface> $encoders
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $encoders = []
|
||||
private readonly array $encoders = [],
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -101,6 +101,6 @@ class ChainEncoder implements ContextAwareEncoderInterface
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException(sprintf('No encoder found for format "%s".', $format));
|
||||
throw new RuntimeException(\sprintf('No encoder found for format "%s".', $format));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
||||
$asCollection = $context[self::AS_COLLECTION_KEY] ?? $this->defaultContext[self::AS_COLLECTION_KEY];
|
||||
|
||||
if (!\is_array($headers)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, get_debug_type($headers)));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, get_debug_type($headers)));
|
||||
}
|
||||
|
||||
return [$delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas, $outputBom, $asCollection];
|
||||
|
||||
@@ -111,7 +111,7 @@ class JsonDecode implements DecoderInterface
|
||||
}
|
||||
|
||||
if (!class_exists(JsonParser::class)) {
|
||||
throw new UnsupportedException(sprintf('Enabling "%s" serializer option requires seld/jsonlint. Try running "composer require seld/jsonlint".', self::DETAILED_ERROR_MESSAGES));
|
||||
throw new UnsupportedException(\sprintf('Enabling "%s" serializer option requires seld/jsonlint. Try running "composer require seld/jsonlint".', self::DETAILED_ERROR_MESSAGES));
|
||||
}
|
||||
|
||||
throw new NotEncodableValueException((new JsonParser())->lint($data)?->getMessage() ?: $errorMessage);
|
||||
|
||||
@@ -391,7 +391,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
||||
|
||||
if (\is_object($data)) {
|
||||
if (null === $this->serializer) {
|
||||
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
|
||||
throw new BadMethodCallException(\sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
|
||||
}
|
||||
|
||||
$data = $this->serializer->normalize($data, $format, $context);
|
||||
@@ -410,7 +410,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
||||
return $this->appendNode($parentNode, $data, $format, $context, 'data');
|
||||
}
|
||||
|
||||
throw new NotEncodableValueException('An unexpected value could not be serialized: '.(!\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
|
||||
throw new NotEncodableValueException('An unexpected value could not be serialized: '.(!\is_resource($data) ? var_export($data, true) : \sprintf('%s resource', get_resource_type($data))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,7 +459,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
||||
$node->appendChild($child);
|
||||
} elseif (\is_object($val)) {
|
||||
if (null === $this->serializer) {
|
||||
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
|
||||
throw new BadMethodCallException(\sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
|
||||
}
|
||||
|
||||
return $this->selectNodeType($node, $this->serializer->normalize($val, $format, $context), $format, $context);
|
||||
|
||||
@@ -22,7 +22,7 @@ class ExtraAttributesException extends RuntimeException
|
||||
private readonly array $extraAttributes,
|
||||
?\Throwable $previous = null,
|
||||
) {
|
||||
$msg = sprintf('Extra attributes are not allowed ("%s" %s unknown).', implode('", "', $extraAttributes), \count($extraAttributes) > 1 ? 'are' : 'is');
|
||||
$msg = \sprintf('Extra attributes are not allowed ("%s" %s unknown).', implode('", "', $extraAttributes), \count($extraAttributes) > 1 ? 'are' : 'is');
|
||||
|
||||
parent::__construct($msg, 0, $previous);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ EOF;
|
||||
$classMetadata->getClassDiscriminatorMapping()->getTypesMapping(),
|
||||
] : null;
|
||||
|
||||
$compiled .= sprintf("\n'%s' => %s,", $classMetadata->getName(), VarExporter::export([
|
||||
$compiled .= \sprintf("\n'%s' => %s,", $classMetadata->getName(), VarExporter::export([
|
||||
$attributesMetadata,
|
||||
$classDiscriminatorMapping,
|
||||
]));
|
||||
|
||||
@@ -31,7 +31,7 @@ trait ClassResolverTrait
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
if (!class_exists($value) && !interface_exists($value, false)) {
|
||||
throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value));
|
||||
throw new InvalidArgumentException(\sprintf('The class or interface "%s" does not exist.', $value));
|
||||
}
|
||||
|
||||
return ltrim($value, '\\');
|
||||
|
||||
@@ -35,7 +35,7 @@ final class CompiledClassMetadataFactory implements ClassMetadataFactoryInterfac
|
||||
|
||||
$compiledClassMetadata = require $compiledClassMetadataFile;
|
||||
if (!\is_array($compiledClassMetadata)) {
|
||||
throw new \RuntimeException(sprintf('Compiled metadata must be of the type array, %s given.', \gettype($compiledClassMetadata)));
|
||||
throw new \RuntimeException(\sprintf('Compiled metadata must be of the type array, %s given.', \gettype($compiledClassMetadata)));
|
||||
}
|
||||
|
||||
$this->compiledClassMetadata = $compiledClassMetadata;
|
||||
|
||||
@@ -143,7 +143,7 @@ class AttributeLoader implements LoaderInterface
|
||||
foreach ($this->loadAttributes($method) as $annotation) {
|
||||
if ($annotation instanceof Groups) {
|
||||
if (!$accessorOrMutator) {
|
||||
throw new MappingException(sprintf('Groups on "%s::%s()" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
throw new MappingException(\sprintf('Groups on "%s::%s()" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
}
|
||||
|
||||
foreach ($annotation->getGroups() as $group) {
|
||||
@@ -151,19 +151,19 @@ class AttributeLoader implements LoaderInterface
|
||||
}
|
||||
} elseif ($annotation instanceof MaxDepth) {
|
||||
if (!$accessorOrMutator) {
|
||||
throw new MappingException(sprintf('MaxDepth on "%s::%s()" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
throw new MappingException(\sprintf('MaxDepth on "%s::%s()" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
}
|
||||
|
||||
$attributeMetadata->setMaxDepth($annotation->getMaxDepth());
|
||||
} elseif ($annotation instanceof SerializedName) {
|
||||
if (!$accessorOrMutator) {
|
||||
throw new MappingException(sprintf('SerializedName on "%s::%s()" cannot be added. SerializedName can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
throw new MappingException(\sprintf('SerializedName on "%s::%s()" cannot be added. SerializedName can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
}
|
||||
|
||||
$attributeMetadata->setSerializedName($annotation->getSerializedName());
|
||||
} elseif ($annotation instanceof SerializedPath) {
|
||||
if (!$accessorOrMutator) {
|
||||
throw new MappingException(sprintf('SerializedPath on "%s::%s()" cannot be added. SerializedPath can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
throw new MappingException(\sprintf('SerializedPath on "%s::%s()" cannot be added. SerializedPath can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
}
|
||||
|
||||
$attributeMetadata->setSerializedPath($annotation->getSerializedPath());
|
||||
@@ -173,7 +173,7 @@ class AttributeLoader implements LoaderInterface
|
||||
}
|
||||
} elseif ($annotation instanceof Context) {
|
||||
if (!$accessorOrMutator) {
|
||||
throw new MappingException(sprintf('Context on "%s::%s()" cannot be added. Context can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
throw new MappingException(\sprintf('Context on "%s::%s()" cannot be added. Context can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
|
||||
}
|
||||
|
||||
$this->setAttributeContextsForGroups($annotation, $attributeMetadata);
|
||||
@@ -198,12 +198,12 @@ class AttributeLoader implements LoaderInterface
|
||||
}
|
||||
$on = match (true) {
|
||||
$reflector instanceof \ReflectionClass => ' on class '.$reflector->name,
|
||||
$reflector instanceof \ReflectionMethod => sprintf(' on "%s::%s()"', $reflector->getDeclaringClass()->name, $reflector->name),
|
||||
$reflector instanceof \ReflectionProperty => sprintf(' on "%s::$%s"', $reflector->getDeclaringClass()->name, $reflector->name),
|
||||
$reflector instanceof \ReflectionMethod => \sprintf(' on "%s::%s()"', $reflector->getDeclaringClass()->name, $reflector->name),
|
||||
$reflector instanceof \ReflectionProperty => \sprintf(' on "%s::$%s"', $reflector->getDeclaringClass()->name, $reflector->name),
|
||||
default => '',
|
||||
};
|
||||
|
||||
throw new MappingException(sprintf('Could not instantiate attribute "%s"%s.', $attribute->getName(), $on), 0, $e);
|
||||
throw new MappingException(\sprintf('Could not instantiate attribute "%s"%s.', $attribute->getName(), $on), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ abstract class FileLoader implements LoaderInterface
|
||||
public function __construct(string $file)
|
||||
{
|
||||
if (!is_file($file)) {
|
||||
throw new MappingException(sprintf('The mapping file "%s" does not exist.', $file));
|
||||
throw new MappingException(\sprintf('The mapping file "%s" does not exist.', $file));
|
||||
}
|
||||
|
||||
if (!is_readable($file)) {
|
||||
throw new MappingException(sprintf('The mapping file "%s" is not readable.', $file));
|
||||
throw new MappingException(\sprintf('The mapping file "%s" is not readable.', $file));
|
||||
}
|
||||
|
||||
$this->file = $file;
|
||||
|
||||
@@ -38,7 +38,7 @@ class LoaderChain implements LoaderInterface
|
||||
{
|
||||
foreach ($loaders as $loader) {
|
||||
if (!$loader instanceof LoaderInterface) {
|
||||
throw new MappingException(sprintf('Class "%s" is expected to implement LoaderInterface.', get_debug_type($loader)));
|
||||
throw new MappingException(\sprintf('Class "%s" is expected to implement LoaderInterface.', get_debug_type($loader)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class XmlFileLoader extends FileLoader
|
||||
try {
|
||||
$attributeMetadata->setSerializedPath(new PropertyPath((string) $attribute['serialized-path']));
|
||||
} catch (InvalidPropertyPathException) {
|
||||
throw new MappingException(sprintf('The "serialized-path" value must be a valid property path for the attribute "%s" of the class "%s".', $attributeName, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('The "serialized-path" value must be a valid property path for the attribute "%s" of the class "%s".', $attributeName, $classMetadata->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
if (isset($data['groups'])) {
|
||||
if (!\is_array($data['groups'])) {
|
||||
throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
}
|
||||
|
||||
foreach ($data['groups'] as $group) {
|
||||
if (!\is_string($group)) {
|
||||
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
}
|
||||
|
||||
$attributeMetadata->addGroup($group);
|
||||
@@ -73,7 +73,7 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
if (isset($data['max_depth'])) {
|
||||
if (!\is_int($data['max_depth'])) {
|
||||
throw new MappingException(sprintf('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
}
|
||||
|
||||
$attributeMetadata->setMaxDepth($data['max_depth']);
|
||||
@@ -81,7 +81,7 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
if (isset($data['serialized_name'])) {
|
||||
if (!\is_string($data['serialized_name']) || '' === $data['serialized_name']) {
|
||||
throw new MappingException(sprintf('The "serialized_name" value must be a non-empty string in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('The "serialized_name" value must be a non-empty string in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
}
|
||||
|
||||
$attributeMetadata->setSerializedName($data['serialized_name']);
|
||||
@@ -91,13 +91,13 @@ class YamlFileLoader extends FileLoader
|
||||
try {
|
||||
$attributeMetadata->setSerializedPath(new PropertyPath((string) $data['serialized_path']));
|
||||
} catch (InvalidPropertyPathException) {
|
||||
throw new MappingException(sprintf('The "serialized_path" value must be a valid property path in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('The "serialized_path" value must be a valid property path in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['ignore'])) {
|
||||
if (!\is_bool($data['ignore'])) {
|
||||
throw new MappingException(sprintf('The "ignore" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
throw new MappingException(\sprintf('The "ignore" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||
}
|
||||
|
||||
$attributeMetadata->setIgnore($data['ignore']);
|
||||
@@ -124,11 +124,11 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
if (isset($yaml['discriminator_map'])) {
|
||||
if (!isset($yaml['discriminator_map']['type_property'])) {
|
||||
throw new MappingException(sprintf('The "type_property" key must be set for the discriminator map of the class "%s" in "%s".', $classMetadata->getName(), $this->file));
|
||||
throw new MappingException(\sprintf('The "type_property" key must be set for the discriminator map of the class "%s" in "%s".', $classMetadata->getName(), $this->file));
|
||||
}
|
||||
|
||||
if (!isset($yaml['discriminator_map']['mapping'])) {
|
||||
throw new MappingException(sprintf('The "mapping" key must be set for the discriminator map of the class "%s" in "%s".', $classMetadata->getName(), $this->file));
|
||||
throw new MappingException(\sprintf('The "mapping" key must be set for the discriminator map of the class "%s" in "%s".', $classMetadata->getName(), $this->file));
|
||||
}
|
||||
|
||||
$classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping(
|
||||
@@ -153,7 +153,7 @@ class YamlFileLoader extends FileLoader
|
||||
private function getClassesFromYaml(): array
|
||||
{
|
||||
if (!stream_is_local($this->file)) {
|
||||
throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
|
||||
throw new MappingException(\sprintf('This is not a local file "%s".', $this->file));
|
||||
}
|
||||
|
||||
$this->yamlParser ??= new Parser();
|
||||
@@ -165,7 +165,7 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
if (!\is_array($classes)) {
|
||||
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
|
||||
throw new MappingException(\sprintf('The file "%s" must contain a YAML array.', $this->file));
|
||||
}
|
||||
|
||||
return $classes;
|
||||
|
||||
@@ -80,7 +80,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
||||
}
|
||||
|
||||
if (null !== $attributesMetadata[$propertyName]->getSerializedName() && null !== $attributesMetadata[$propertyName]->getSerializedPath()) {
|
||||
throw new LogicException(sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $propertyName, $class));
|
||||
throw new LogicException(\sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $propertyName, $class));
|
||||
}
|
||||
|
||||
return $attributesMetadata[$propertyName]->getSerializedName() ?? null;
|
||||
@@ -124,7 +124,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
||||
}
|
||||
|
||||
if (null !== $metadata->getSerializedName() && null !== $metadata->getSerializedPath()) {
|
||||
throw new LogicException(sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $name, $class));
|
||||
throw new LogicException(\sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $name, $class));
|
||||
}
|
||||
|
||||
$metadataGroups = $metadata->getGroups();
|
||||
|
||||
@@ -152,7 +152,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
$this->validateCallbackContext($this->defaultContext, 'default');
|
||||
|
||||
if (isset($this->defaultContext[self::CIRCULAR_REFERENCE_HANDLER]) && !\is_callable($this->defaultContext[self::CIRCULAR_REFERENCE_HANDLER])) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid callback found in the "%s" default context option.', self::CIRCULAR_REFERENCE_HANDLER));
|
||||
throw new InvalidArgumentException(\sprintf('Invalid callback found in the "%s" default context option.', self::CIRCULAR_REFERENCE_HANDLER));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
return $circularReferenceHandler($object, $format, $context);
|
||||
}
|
||||
|
||||
throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d).', get_debug_type($object), $context[self::CIRCULAR_REFERENCE_LIMIT] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_LIMIT]));
|
||||
throw new CircularReferenceException(\sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d).', get_debug_type($object), $context[self::CIRCULAR_REFERENCE_LIMIT] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_LIMIT]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,7 +225,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
$allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
|
||||
if (!$this->classMetadataFactory) {
|
||||
if (!$allowExtraAttributes) {
|
||||
throw new LogicException(sprintf('A class metadata factory must be provided in the constructor when setting "%s" to false.', self::ALLOW_EXTRA_ATTRIBUTES));
|
||||
throw new LogicException(\sprintf('A class metadata factory must be provided in the constructor when setting "%s" to false.', self::ALLOW_EXTRA_ATTRIBUTES));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -353,7 +353,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
if ($constructorParameter->isVariadic()) {
|
||||
if ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {
|
||||
if (!\is_array($data[$key])) {
|
||||
throw new RuntimeException(sprintf('Cannot create an instance of "%s" from serialized data because the variadic parameter "%s" can only accept an array.', $class, $constructorParameter->name));
|
||||
throw new RuntimeException(\sprintf('Cannot create an instance of "%s" from serialized data because the variadic parameter "%s" can only accept an array.', $class, $constructorParameter->name));
|
||||
}
|
||||
|
||||
$variadicParameters = [];
|
||||
@@ -415,7 +415,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
}
|
||||
|
||||
$exception = NotNormalizableValueException::createForUnexpectedDataType(
|
||||
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
|
||||
\sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
|
||||
null,
|
||||
[$constructorParameterType],
|
||||
$attributeContext['deserialization_path'] ?? null,
|
||||
@@ -426,7 +426,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
}
|
||||
|
||||
if ($missingConstructorArguments) {
|
||||
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments, $class);
|
||||
throw new MissingConstructorArgumentsException(\sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments, $class);
|
||||
}
|
||||
|
||||
if (!$constructor->isConstructor()) {
|
||||
@@ -461,12 +461,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
unset($context['has_constructor']);
|
||||
|
||||
if (!$reflectionClass->isInstantiable()) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(
|
||||
sprintf('Failed to create object because the class "%s" is not instantiable.', $class),
|
||||
$data,
|
||||
['unknown'],
|
||||
$context['deserialization_path'] ?? null
|
||||
);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Failed to create object because the class "%s" is not instantiable.', $class), $data, ['unknown'], $context['deserialization_path'] ?? null);
|
||||
}
|
||||
|
||||
return new $class();
|
||||
@@ -483,13 +478,13 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
|
||||
|
||||
if (!$this->serializer instanceof DenormalizerInterface) {
|
||||
throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameterClass, static::class));
|
||||
throw new LogicException(\sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameterClass, static::class));
|
||||
}
|
||||
|
||||
$parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e);
|
||||
throw new RuntimeException(\sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e);
|
||||
} catch (MissingConstructorArgumentsException $e) {
|
||||
if (!$parameter->getType()->allowsNull()) {
|
||||
throw $e;
|
||||
@@ -529,12 +524,12 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
}
|
||||
|
||||
if (!\is_array($context[self::CALLBACKS])) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s"%s context option must be an array of callables.', self::CALLBACKS, '' !== $contextType ? " $contextType" : ''));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s"%s context option must be an array of callables.', self::CALLBACKS, '' !== $contextType ? " $contextType" : ''));
|
||||
}
|
||||
|
||||
foreach ($context[self::CALLBACKS] as $attribute => $callback) {
|
||||
if (!\is_callable($callback)) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid callback found for attribute "%s" in the "%s"%s context option.', $attribute, self::CALLBACKS, '' !== $contextType ? " $contextType" : ''));
|
||||
throw new InvalidArgumentException(\sprintf('Invalid callback found for attribute "%s" in the "%s"%s context option.', $attribute, self::CALLBACKS, '' !== $contextType ? " $contextType" : ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
parent::__construct($classMetadataFactory, $nameConverter, $defaultContext);
|
||||
|
||||
if (isset($this->defaultContext[self::MAX_DEPTH_HANDLER]) && !\is_callable($this->defaultContext[self::MAX_DEPTH_HANDLER])) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" given in the default context is not callable.', self::MAX_DEPTH_HANDLER));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" given in the default context is not callable.', self::MAX_DEPTH_HANDLER));
|
||||
}
|
||||
|
||||
$this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] = array_merge($this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] ?? [], [self::CIRCULAR_REFERENCE_LIMIT_COUNTERS]);
|
||||
@@ -175,7 +175,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
if (isset($context[self::MAX_DEPTH_HANDLER])) {
|
||||
$maxDepthHandler = $context[self::MAX_DEPTH_HANDLER];
|
||||
if (!\is_callable($maxDepthHandler)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" given in the context is not callable.', self::MAX_DEPTH_HANDLER));
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" given in the context is not callable.', self::MAX_DEPTH_HANDLER));
|
||||
}
|
||||
} else {
|
||||
$maxDepthHandler = null;
|
||||
@@ -216,7 +216,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
}
|
||||
|
||||
if (!$this->serializer instanceof NormalizerInterface) {
|
||||
throw new LogicException(sprintf('Cannot normalize attribute "%s" because the injected serializer is not a normalizer.', $attribute));
|
||||
throw new LogicException(\sprintf('Cannot normalize attribute "%s" because the injected serializer is not a normalizer.', $attribute));
|
||||
}
|
||||
|
||||
$childContext = $this->createChildContext($attributeContext, $attribute, $format);
|
||||
@@ -355,7 +355,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
$notConverted = $attribute;
|
||||
$attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $context);
|
||||
if (isset($nestedData[$notConverted]) && !isset($originalNestedData[$attribute])) {
|
||||
throw new LogicException(sprintf('Duplicate values for key "%s" found. One value is set via the SerializedPath attribute: "%s", the other one is set via the SerializedName attribute: "%s".', $notConverted, implode('->', $nestedAttributes[$notConverted]->getElements()), $attribute));
|
||||
throw new LogicException(\sprintf('Duplicate values for key "%s" found. One value is set via the SerializedPath attribute: "%s", the other one is set via the SerializedName attribute: "%s".', $notConverted, implode('->', $nestedAttributes[$notConverted]->getElements()), $attribute));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
$this->setAttributeValue($object, $attribute, $value, $format, $attributeContext);
|
||||
} catch (PropertyAccessInvalidArgumentException $e) {
|
||||
$exception = NotNormalizableValueException::createForUnexpectedDataType(
|
||||
sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type),
|
||||
\sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type),
|
||||
$data,
|
||||
['unknown'],
|
||||
$attributeContext['deserialization_path'] ?? null,
|
||||
@@ -495,14 +495,14 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
} elseif ('true' === $data || '1' === $data) {
|
||||
$data = true;
|
||||
} else {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be bool ("%s" given).', $attribute, $currentClass, $data), $data, [Type::BUILTIN_TYPE_BOOL], $context['deserialization_path'] ?? null);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be bool ("%s" given).', $attribute, $currentClass, $data), $data, [Type::BUILTIN_TYPE_BOOL], $context['deserialization_path'] ?? null);
|
||||
}
|
||||
break;
|
||||
case Type::BUILTIN_TYPE_INT:
|
||||
if (ctype_digit(isset($data[0]) && '-' === $data[0] ? substr($data, 1) : $data)) {
|
||||
$data = (int) $data;
|
||||
} else {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be int ("%s" given).', $attribute, $currentClass, $data), $data, [Type::BUILTIN_TYPE_INT], $context['deserialization_path'] ?? null);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be int ("%s" given).', $attribute, $currentClass, $data), $data, [Type::BUILTIN_TYPE_INT], $context['deserialization_path'] ?? null);
|
||||
}
|
||||
break;
|
||||
case Type::BUILTIN_TYPE_FLOAT:
|
||||
@@ -514,7 +514,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
'NaN' => \NAN,
|
||||
'INF' => \INF,
|
||||
'-INF' => -\INF,
|
||||
default => throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be float ("%s" given).', $attribute, $currentClass, $data), $data, [Type::BUILTIN_TYPE_FLOAT], $context['deserialization_path'] ?? null),
|
||||
default => throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be float ("%s" given).', $attribute, $currentClass, $data), $data, [Type::BUILTIN_TYPE_FLOAT], $context['deserialization_path'] ?? null),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -557,7 +557,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
|
||||
if (Type::BUILTIN_TYPE_OBJECT === $builtinType && null !== $class) {
|
||||
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));
|
||||
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);
|
||||
@@ -636,7 +636,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
return $data;
|
||||
}
|
||||
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute, $currentClass, implode('", "', array_keys($expectedTypes)), get_debug_type($data)), $data, array_keys($expectedTypes), $context['deserialization_path'] ?? $attribute);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute, $currentClass, implode('", "', array_keys($expectedTypes)), get_debug_type($data)), $data, array_keys($expectedTypes), $context['deserialization_path'] ?? $attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -702,7 +702,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
if (null !== $classMetadata && null !== $serializedPath = ($attributesMetadata[$attribute] ?? null)?->getSerializedPath()) {
|
||||
$propertyAccessor = PropertyAccess::createPropertyAccessor();
|
||||
if ($propertyAccessor->isReadable($data, $serializedPath) && null !== $propertyAccessor->getValue($data, $serializedPath)) {
|
||||
throw new LogicException(sprintf('The element you are trying to set is already populated: "%s".', (string) $serializedPath));
|
||||
throw new LogicException(\sprintf('The element you are trying to set is already populated: "%s".', (string) $serializedPath));
|
||||
}
|
||||
$propertyAccessor->setValue($data, $serializedPath, $attributeValue);
|
||||
|
||||
@@ -731,7 +731,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = sprintf(self::DEPTH_KEY_PATTERN, $class, $attribute);
|
||||
$key = \sprintf(self::DEPTH_KEY_PATTERN, $class, $attribute);
|
||||
if (!isset($context[$key])) {
|
||||
$context[$key] = 1;
|
||||
|
||||
@@ -844,7 +844,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
}
|
||||
$pathIdentifier = implode(',', $serializedPath->getElements());
|
||||
if (isset($serializedPaths[$pathIdentifier])) {
|
||||
throw new LogicException(sprintf('Duplicate serialized path: "%s" used for properties "%s" and "%s".', $pathIdentifier, $serializedPaths[$pathIdentifier], $name));
|
||||
throw new LogicException(\sprintf('Duplicate serialized path: "%s" used for properties "%s" and "%s".', $pathIdentifier, $serializedPaths[$pathIdentifier], $name));
|
||||
}
|
||||
$serializedPaths[$pathIdentifier] = $name;
|
||||
$properties[$name] = $serializedPath;
|
||||
@@ -877,11 +877,11 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
}
|
||||
|
||||
if (null === $type = $data[$mapping->getTypeProperty()] ?? null) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class), null, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), false);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class), null, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), false);
|
||||
}
|
||||
|
||||
if (null === $mappedClass = $mapping->getClassForType($type)) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type "%s" is not a valid value.', $type), $type, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type "%s" is not a valid value.', $type), $type, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
|
||||
}
|
||||
|
||||
return $mappedClass;
|
||||
|
||||
@@ -50,7 +50,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz
|
||||
throw new BadMethodCallException('Please set a denormalizer before calling denormalize()!');
|
||||
}
|
||||
if (!\is_array($data)) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Data expected to be "%s", "%s" given.', $type, get_debug_type($data)), $data, [Type::BUILTIN_TYPE_ARRAY], $context['deserialization_path'] ?? null);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Data expected to be "%s", "%s" given.', $type, get_debug_type($data)), $data, [Type::BUILTIN_TYPE_ARRAY], $context['deserialization_path'] ?? null);
|
||||
}
|
||||
if (!str_ends_with($type, '[]')) {
|
||||
throw new InvalidArgumentException('Unsupported class: '.$type);
|
||||
@@ -64,7 +64,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$subContext = $context;
|
||||
$subContext['deserialization_path'] = ($context['deserialization_path'] ?? false) ? sprintf('%s[%s]', $context['deserialization_path'], $key) : "[$key]";
|
||||
$subContext['deserialization_path'] = ($context['deserialization_path'] ?? false) ? \sprintf('%s[%s]', $context['deserialization_path'], $key) : "[$key]";
|
||||
|
||||
$this->validateKeyType($builtinTypes, $key, $subContext['deserialization_path']);
|
||||
|
||||
@@ -77,7 +77,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz
|
||||
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
|
||||
{
|
||||
if (null === $this->denormalizer) {
|
||||
throw new BadMethodCallException(sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.', __METHOD__));
|
||||
throw new BadMethodCallException(\sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.', __METHOD__));
|
||||
}
|
||||
|
||||
return str_ends_with($type, '[]')
|
||||
@@ -109,6 +109,6 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz
|
||||
}
|
||||
}
|
||||
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, implode('", "', $builtinTypes), get_debug_type($key)), $key, $builtinTypes, $path, true);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, implode('", "', $builtinTypes), get_debug_type($key)), $key, $builtinTypes, $path, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ final class BackedEnumNormalizer implements NormalizerInterface, DenormalizerInt
|
||||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
return [
|
||||
\BackedEnum::class => true,
|
||||
\BackedEnum::class => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl
|
||||
'parameters' => $violation->getParameters(),
|
||||
];
|
||||
if (null !== $code = $violation->getCode()) {
|
||||
$violationEntry['type'] = sprintf('urn:uuid:%s', $code);
|
||||
$violationEntry['type'] = \sprintf('urn:uuid:%s', $code);
|
||||
}
|
||||
|
||||
$constraint = $violation->getConstraint();
|
||||
@@ -87,7 +87,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl
|
||||
|
||||
$violations[] = $violationEntry;
|
||||
|
||||
$prefix = $propertyPath ? sprintf('%s: ', $propertyPath) : '';
|
||||
$prefix = $propertyPath ? \sprintf('%s: ', $propertyPath) : '';
|
||||
$messages[] = $prefix.$violation->getMessage();
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +72,10 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
||||
}
|
||||
|
||||
if ('text' === explode('/', $mimeType, 2)[0]) {
|
||||
return sprintf('data:%s,%s', $mimeType, rawurlencode($data));
|
||||
return \sprintf('data:%s,%s', $mimeType, rawurlencode($data));
|
||||
}
|
||||
|
||||
return sprintf('data:%s;base64,%s', $mimeType, base64_encode($data));
|
||||
return \sprintf('data:%s;base64,%s', $mimeType, base64_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
||||
switch ($type) {
|
||||
case File::class:
|
||||
if (!class_exists(File::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Cannot denormalize to a "%s" without the HttpFoundation component installed. Try running "composer require symfony/http-foundation".', File::class));
|
||||
throw new InvalidArgumentException(\sprintf('Cannot denormalize to a "%s" without the HttpFoundation component installed. Try running "composer require symfony/http-foundation".', File::class));
|
||||
}
|
||||
|
||||
return new File($data, false);
|
||||
@@ -117,7 +117,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType($exception->getMessage(), $data, ['string'], $context['deserialization_path'] ?? null, false, $exception->getCode(), $exception);
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $type));
|
||||
throw new InvalidArgumentException(\sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $type));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,7 +100,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
||||
}
|
||||
$valuePattern = '/^'.$signPattern.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?:(?P<$1>\d+)$2)?', preg_replace('/(T.*)$/', '($1)?', $dateIntervalFormat)).'$/';
|
||||
if (!preg_match($valuePattern, $data)) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat), $data, ['string'], $context['deserialization_path'] ?? null, false);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat), $data, ['string'], $context['deserialization_path'] ?? null, false);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -95,8 +95,8 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
{
|
||||
if (\is_int($data) || \is_float($data)) {
|
||||
switch ($context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY] ?? null) {
|
||||
case 'U': $data = sprintf('%d', $data); break;
|
||||
case 'U.u': $data = sprintf('%.6F', $data); break;
|
||||
case 'U': $data = \sprintf('%d', $data); break;
|
||||
case 'U.u': $data = \sprintf('%.6F', $data); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
|
||||
$dateTimeErrors = $type::getLastErrors();
|
||||
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors: ', $data, $dateTimeFormat, $dateTimeErrors['error_count'])."\n".implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors'])), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors: ', $data, $dateTimeFormat, $dateTimeErrors['error_count'])."\n".implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors'])), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
|
||||
}
|
||||
|
||||
$defaultDateTimeFormat = $this->defaultContext[self::FORMAT_KEY] ?? null;
|
||||
@@ -166,7 +166,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
$formattedErrors = [];
|
||||
|
||||
foreach ($errors as $pos => $message) {
|
||||
$formattedErrors[] = sprintf('at position %d: %s', $pos, $message);
|
||||
$formattedErrors[] = \sprintf('at position %d: %s', $pos, $message);
|
||||
}
|
||||
|
||||
return $formattedErrors;
|
||||
|
||||
@@ -121,7 +121,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
||||
&& 3 < \strlen($method->name)
|
||||
&& str_starts_with($method->name, 'set')
|
||||
&& !ctype_lower($method->name[3])
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
|
||||
@@ -188,7 +188,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
||||
return false;
|
||||
}
|
||||
|
||||
$class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;
|
||||
$class = \is_object($classOrObject) ? $classOrObject::class : $classOrObject;
|
||||
|
||||
if (!isset(self::$reflectionCache[$class])) {
|
||||
self::$reflectionCache[$class] = new \ReflectionClass($class);
|
||||
|
||||
@@ -30,7 +30,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
||||
}
|
||||
|
||||
if (!$object instanceof \JsonSerializable) {
|
||||
throw new InvalidArgumentException(sprintf('The object must implement "%s".', \JsonSerializable::class));
|
||||
throw new InvalidArgumentException(\sprintf('The object must implement "%s".', \JsonSerializable::class));
|
||||
}
|
||||
|
||||
if (!$this->serializer instanceof NormalizerInterface) {
|
||||
@@ -65,7 +65,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
||||
|
||||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
|
||||
{
|
||||
throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
|
||||
throw new LogicException(\sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,7 +58,7 @@ final class MimeMessageNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
public function setSerializer(SerializerInterface $serializer): void
|
||||
{
|
||||
if (!$serializer instanceof NormalizerInterface || !$serializer instanceof DenormalizerInterface) {
|
||||
throw new LogicException(sprintf('The passed serializer should implement both NormalizerInterface and DenormalizerInterface, "%s" given.', get_debug_type($serializer)));
|
||||
throw new LogicException(\sprintf('The passed serializer should implement both NormalizerInterface and DenormalizerInterface, "%s" given.', get_debug_type($serializer)));
|
||||
}
|
||||
$this->serializer = $serializer;
|
||||
$this->normalizer->setSerializer($serializer);
|
||||
|
||||
@@ -20,7 +20,6 @@ use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyWriteInfo;
|
||||
use Symfony\Component\Serializer\Annotation\Ignore;
|
||||
use Symfony\Component\Serializer\Exception\LogicException;
|
||||
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
|
||||
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
||||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
||||
@@ -170,7 +169,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
||||
return false;
|
||||
}
|
||||
|
||||
$class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;
|
||||
$class = \is_object($classOrObject) ? $classOrObject::class : $classOrObject;
|
||||
|
||||
if ($context['_read_attributes'] ?? true) {
|
||||
if (!isset(self::$isReadableCache[$class.$attribute])) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class ProblemNormalizer implements NormalizerInterface, SerializerAwareInterface
|
||||
public function normalize(mixed $object, ?string $format = null, array $context = []): array
|
||||
{
|
||||
if (!$object instanceof FlattenException) {
|
||||
throw new InvalidArgumentException(sprintf('The object must implement "%s".', FlattenException::class));
|
||||
throw new InvalidArgumentException(\sprintf('The object must implement "%s".', FlattenException::class));
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
@@ -181,7 +181,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
||||
|| ($reflectionProperty->isProtected() && !\array_key_exists("\0*\0{$reflectionProperty->name}", $propertyValues))
|
||||
|| ($reflectionProperty->isPrivate() && !\array_key_exists("\0{$reflectionProperty->class}\0{$reflectionProperty->name}", $propertyValues))
|
||||
) {
|
||||
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $object::class, $reflectionProperty->name));
|
||||
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not initialized.', $object::class, $reflectionProperty->name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ final class TranslatableNormalizer implements NormalizerInterface
|
||||
public function normalize(mixed $object, ?string $format = null, array $context = []): string
|
||||
{
|
||||
if (!$object instanceof TranslatableInterface) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The object must implement the "%s".', TranslatableInterface::class), $object, [TranslatableInterface::class]);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The object must implement the "%s".', TranslatableInterface::class), $object, [TranslatableInterface::class]);
|
||||
}
|
||||
|
||||
return $object->trans($this->translator, $context[self::NORMALIZATION_LOCALE_KEY] ?? $this->defaultContext[self::NORMALIZATION_LOCALE_KEY]);
|
||||
|
||||
@@ -58,7 +58,7 @@ final class UidNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
self::NORMALIZATION_FORMAT_BASE58 => $object->toBase58(),
|
||||
self::NORMALIZATION_FORMAT_BASE32 => $object->toBase32(),
|
||||
self::NORMALIZATION_FORMAT_RFC4122 => $object->toRfc4122(),
|
||||
default => throw new LogicException(sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY])),
|
||||
default => throw new LogicException(\sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY])),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ final class UidNormalizer implements NormalizerInterface, DenormalizerInterface,
|
||||
|
||||
return $type::fromString($data);
|
||||
} catch (\InvalidArgumentException|\TypeError) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The data is not a valid "%s" string representation.', $type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The data is not a valid "%s" string representation.', $type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
|
||||
} catch (\Error $e) { // @deprecated remove this catch block in 7.0
|
||||
if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) {
|
||||
return $this->denormalize($data, AbstractUid::class, $format, $context);
|
||||
|
||||
@@ -105,7 +105,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
}
|
||||
|
||||
if (!($normalizer instanceof NormalizerInterface || $normalizer instanceof DenormalizerInterface)) {
|
||||
throw new InvalidArgumentException(sprintf('The class "%s" neither implements "%s" nor "%s".', get_debug_type($normalizer), NormalizerInterface::class, DenormalizerInterface::class));
|
||||
throw new InvalidArgumentException(\sprintf('The class "%s" neither implements "%s" nor "%s".', get_debug_type($normalizer), NormalizerInterface::class, DenormalizerInterface::class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
}
|
||||
|
||||
if (!($encoder instanceof EncoderInterface || $encoder instanceof DecoderInterface)) {
|
||||
throw new InvalidArgumentException(sprintf('The class "%s" neither implements "%s" nor "%s".', get_debug_type($encoder), EncoderInterface::class, DecoderInterface::class));
|
||||
throw new InvalidArgumentException(\sprintf('The class "%s" neither implements "%s" nor "%s".', get_debug_type($encoder), EncoderInterface::class, DecoderInterface::class));
|
||||
}
|
||||
}
|
||||
$this->encoder = new ChainEncoder($realEncoders);
|
||||
@@ -133,7 +133,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
final public function serialize(mixed $data, string $format, array $context = []): string
|
||||
{
|
||||
if (!$this->supportsEncoding($format, $context)) {
|
||||
throw new UnsupportedFormatException(sprintf('Serialization for the format "%s" is not supported.', $format));
|
||||
throw new UnsupportedFormatException(\sprintf('Serialization for the format "%s" is not supported.', $format));
|
||||
}
|
||||
|
||||
if ($this->encoder->needsNormalization($format, $context)) {
|
||||
@@ -146,7 +146,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
final public function deserialize(mixed $data, string $type, string $format, array $context = []): mixed
|
||||
{
|
||||
if (!$this->supportsDecoding($format, $context)) {
|
||||
throw new UnsupportedFormatException(sprintf('Deserialization for the format "%s" is not supported.', $format));
|
||||
throw new UnsupportedFormatException(\sprintf('Deserialization for the format "%s" is not supported.', $format));
|
||||
}
|
||||
|
||||
$data = $this->decode($data, $format, $context);
|
||||
@@ -187,10 +187,10 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
throw new LogicException('You must register at least one normalizer to be able to normalize objects.');
|
||||
}
|
||||
|
||||
throw new NotNormalizableValueException(sprintf('Could not normalize object of type "%s", no supporting normalizer found.', get_debug_type($data)));
|
||||
throw new NotNormalizableValueException(\sprintf('Could not normalize object of type "%s", no supporting normalizer found.', get_debug_type($data)));
|
||||
}
|
||||
|
||||
throw new NotNormalizableValueException('An unexpected value could not be normalized: '.(!\is_resource($data) ? var_export($data, true) : sprintf('"%s" resource', get_resource_type($data))));
|
||||
throw new NotNormalizableValueException('An unexpected value could not be normalized: '.(!\is_resource($data) ? var_export($data, true) : \sprintf('"%s" resource', get_resource_type($data))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +208,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
// Check for a denormalizer first, e.g. the data is wrapped
|
||||
if (!$normalizer && isset(self::SCALAR_TYPES[$type])) {
|
||||
if (!('is_'.$type)($data)) {
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Data expected to be of type "%s" ("%s" given).', $type, get_debug_type($data)), $data, [$type], $context['deserialization_path'] ?? null, true);
|
||||
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Data expected to be of type "%s" ("%s" given).', $type, get_debug_type($data)), $data, [$type], $context['deserialization_path'] ?? null, true);
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -219,7 +219,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
}
|
||||
|
||||
if (!$normalizer) {
|
||||
throw new NotNormalizableValueException(sprintf('Could not denormalize object of type "%s", no supporting normalizer found.', $type));
|
||||
throw new NotNormalizableValueException(\sprintf('Could not denormalize object of type "%s", no supporting normalizer found.', $type));
|
||||
}
|
||||
|
||||
if ((isset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS]) || isset($this->defaultContext[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS])) && !isset($context['not_normalizable_value_exceptions'])) {
|
||||
|
||||
@@ -32,9 +32,9 @@ interface SerializerInterface
|
||||
* @param TType $type
|
||||
* @param array<string, mixed> $context
|
||||
*
|
||||
* @psalm-return (TType is class-string<TObject> ? TObject : mixed)
|
||||
*
|
||||
* @phpstan-return ($type is class-string<TObject> ? TObject : mixed)
|
||||
*
|
||||
* @psalm-return (TType is class-string<TObject> ? TObject : mixed)
|
||||
*/
|
||||
public function deserialize(mixed $data, string $type, string $format, array $context = []): mixed;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ContextTest extends TestCase
|
||||
public function testInvalidGroupOption()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "stdClass" given', Context::class));
|
||||
$this->expectExceptionMessage(\sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "stdClass" given', Context::class));
|
||||
|
||||
new Context(context: ['foo' => 'bar'], groups: ['fine', new \stdClass()]);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ Symfony\Component\Serializer\Attribute\Context {
|
||||
-normalizationContext: []
|
||||
-denormalizationContext: []
|
||||
}
|
||||
DUMP
|
||||
DUMP,
|
||||
];
|
||||
|
||||
yield 'named arguments: with normalization context option' => [
|
||||
@@ -100,7 +100,7 @@ Symfony\Component\Serializer\Attribute\Context {
|
||||
]
|
||||
-denormalizationContext: []
|
||||
}
|
||||
DUMP
|
||||
DUMP,
|
||||
];
|
||||
|
||||
yield 'named arguments: with denormalization context option' => [
|
||||
@@ -114,7 +114,7 @@ Symfony\Component\Serializer\Attribute\Context {
|
||||
"foo" => "bar",
|
||||
]
|
||||
}
|
||||
DUMP
|
||||
DUMP,
|
||||
];
|
||||
|
||||
yield 'named arguments: with groups option as string' => [
|
||||
@@ -130,7 +130,7 @@ Symfony\Component\Serializer\Attribute\Context {
|
||||
-normalizationContext: []
|
||||
-denormalizationContext: []
|
||||
}
|
||||
DUMP
|
||||
DUMP,
|
||||
];
|
||||
|
||||
yield 'named arguments: with groups option as array' => [
|
||||
@@ -147,7 +147,7 @@ Symfony\Component\Serializer\Attribute\Context {
|
||||
-normalizationContext: []
|
||||
-denormalizationContext: []
|
||||
}
|
||||
DUMP
|
||||
DUMP,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class ContextBuilderTraitTest extends TestCase
|
||||
{
|
||||
public function testWithContext()
|
||||
{
|
||||
$contextBuilder = new class() implements ContextBuilderInterface {
|
||||
$contextBuilder = new class implements ContextBuilderInterface {
|
||||
use ContextBuilderTrait;
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ class ContextBuilderTraitTest extends TestCase
|
||||
|
||||
public function testWith()
|
||||
{
|
||||
$contextBuilder = new class() {
|
||||
$contextBuilder = new class {
|
||||
use ContextBuilderTrait;
|
||||
|
||||
public function withFoo(string $value): static
|
||||
|
||||
@@ -25,7 +25,7 @@ class AbstractNormalizerContextBuilderTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->contextBuilder = new class() extends AbstractNormalizerContextBuilder {};
|
||||
$this->contextBuilder = new class extends AbstractNormalizerContextBuilder {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ class AbstractObjectNormalizerContextBuilderTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->contextBuilder = new class() extends AbstractObjectNormalizerContextBuilder {};
|
||||
$this->contextBuilder = new class extends AbstractObjectNormalizerContextBuilder {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -625,8 +625,8 @@ XML;
|
||||
XML;
|
||||
|
||||
$expected = ['person' => [
|
||||
['firstname' => 'Benjamin', 'lastname' => 'Alexandre'],
|
||||
['firstname' => 'Damien', 'lastname' => 'Clay'],
|
||||
['firstname' => 'Benjamin', 'lastname' => 'Alexandre'],
|
||||
['firstname' => 'Damien', 'lastname' => 'Clay'],
|
||||
]];
|
||||
|
||||
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
|
||||
@@ -649,8 +649,8 @@ XML;
|
||||
</people>
|
||||
XML;
|
||||
$expected = ['person' => [
|
||||
['firstname' => 'Benjamin', 'lastname' => 'Alexandre'],
|
||||
['firstname' => 'Damien', 'lastname' => 'Clay'],
|
||||
['firstname' => 'Benjamin', 'lastname' => 'Alexandre'],
|
||||
['firstname' => 'Damien', 'lastname' => 'Clay'],
|
||||
]];
|
||||
$this->assertEquals($expected, $this->encoder->decode(
|
||||
$source,
|
||||
@@ -684,8 +684,8 @@ XML;
|
||||
$this->encoder->setSerializer($serializer);
|
||||
|
||||
$expected = ['person' => [
|
||||
['firstname' => 'Benjamin', 'lastname' => 'Alexandre', '#comment' => ' This comment should be decoded. '],
|
||||
['firstname' => 'Damien', 'lastname' => 'Clay'],
|
||||
['firstname' => 'Benjamin', 'lastname' => 'Alexandre', '#comment' => ' This comment should be decoded. '],
|
||||
['firstname' => 'Damien', 'lastname' => 'Clay'],
|
||||
]];
|
||||
|
||||
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
|
||||
@@ -1004,14 +1004,14 @@ XML;
|
||||
|
||||
private function createXmlWithDateTime(): string
|
||||
{
|
||||
return sprintf('<?xml version="1.0"?>
|
||||
return \sprintf('<?xml version="1.0"?>
|
||||
<response><dateTime>%s</dateTime></response>
|
||||
', $this->exampleDateTimeString);
|
||||
}
|
||||
|
||||
private function createXmlWithDateTimeField(): string
|
||||
{
|
||||
return sprintf('<?xml version="1.0"?>
|
||||
return \sprintf('<?xml version="1.0"?>
|
||||
<response><foo dateTime="%s"/></response>
|
||||
', $this->exampleDateTimeString);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class CacheMetadataFactoryTest extends TestCase
|
||||
|
||||
public function testAnonymousClass()
|
||||
{
|
||||
$anonymousObject = new class() {
|
||||
$anonymousObject = new class {
|
||||
};
|
||||
|
||||
$metadata = new ClassMetadata($anonymousObject::class);
|
||||
|
||||
@@ -154,7 +154,7 @@ abstract class AttributeLoaderTestCase extends TestCase
|
||||
$class = $this->getNamespace().'\BadMethodContextDummy';
|
||||
|
||||
$this->expectException(MappingException::class);
|
||||
$this->expectExceptionMessage(sprintf('Context on "%s::badMethod()" cannot be added', $class));
|
||||
$this->expectExceptionMessage(\sprintf('Context on "%s::badMethod()" cannot be added', $class));
|
||||
|
||||
$loader = $this->getLoaderForContextMapping();
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ class AbstractNormalizerTest extends TestCase
|
||||
public static function getNormalizerWithCustomNameConverter()
|
||||
{
|
||||
$extractor = new PhpDocExtractor();
|
||||
$nameConverter = new class() implements NameConverterInterface {
|
||||
$nameConverter = new class implements NameConverterInterface {
|
||||
public function normalize(string $propertyName): string
|
||||
{
|
||||
return ucfirst($propertyName);
|
||||
|
||||
@@ -496,7 +496,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
{
|
||||
$factory = new ClassMetadataFactory(new AttributeLoader());
|
||||
|
||||
$loaderMock = new class() implements ClassMetadataFactoryInterface {
|
||||
$loaderMock = new class implements ClassMetadataFactoryInterface {
|
||||
public function getMetadataFor($value): ClassMetadataInterface
|
||||
{
|
||||
if (AbstractDummy::class === $value) {
|
||||
@@ -531,7 +531,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
{
|
||||
$factory = new ClassMetadataFactory(new AttributeLoader());
|
||||
|
||||
$loaderMock = new class() implements ClassMetadataFactoryInterface {
|
||||
$loaderMock = new class implements ClassMetadataFactoryInterface {
|
||||
public function getMetadataFor($value): ClassMetadataInterface
|
||||
{
|
||||
if (AbstractDummy::class === $value) {
|
||||
@@ -584,7 +584,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
|
||||
public function testDenormalizeWithNestedDiscriminatorMap()
|
||||
{
|
||||
$classDiscriminatorResolver = new class() implements ClassDiscriminatorResolverInterface {
|
||||
$classDiscriminatorResolver = new class implements ClassDiscriminatorResolverInterface {
|
||||
public function getMappingForClass(string $class): ?ClassDiscriminatorMapping
|
||||
{
|
||||
return match ($class) {
|
||||
@@ -817,7 +817,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
'99' => 'baz',
|
||||
];
|
||||
|
||||
$obj = new class() {
|
||||
$obj = new class {
|
||||
#[SerializedName('1')]
|
||||
public $foo;
|
||||
|
||||
@@ -841,7 +841,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
],
|
||||
];
|
||||
|
||||
$obj = new class() {
|
||||
$obj = new class {
|
||||
#[SerializedPath('[data][id]')]
|
||||
public $id;
|
||||
};
|
||||
@@ -852,7 +852,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
|
||||
public function testNormalizeBasedOnAllowedAttributes()
|
||||
{
|
||||
$normalizer = new class() extends AbstractObjectNormalizer {
|
||||
$normalizer = new class extends AbstractObjectNormalizer {
|
||||
protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false): array
|
||||
{
|
||||
return ['foo'];
|
||||
@@ -927,7 +927,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
$foobar->bar = 'bar';
|
||||
$foobar->baz = 'baz';
|
||||
|
||||
$normalizer = new class() extends AbstractObjectNormalizerDummy {
|
||||
$normalizer = new class extends AbstractObjectNormalizerDummy {
|
||||
public $childContextCacheKey;
|
||||
|
||||
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
|
||||
@@ -967,7 +967,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
$foobar->bar = 'bar';
|
||||
$foobar->baz = 'baz';
|
||||
|
||||
$normalizer = new class() extends AbstractObjectNormalizerDummy {
|
||||
$normalizer = new class extends AbstractObjectNormalizerDummy {
|
||||
public $childContextCacheKey;
|
||||
|
||||
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
|
||||
@@ -1002,7 +1002,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
$foobar->bar = 'bar';
|
||||
$foobar->baz = 'baz';
|
||||
|
||||
$normalizer = new class() extends AbstractObjectNormalizerDummy {
|
||||
$normalizer = new class extends AbstractObjectNormalizerDummy {
|
||||
public $childContextCacheKey;
|
||||
|
||||
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
|
||||
@@ -1032,7 +1032,7 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
|
||||
public function testDenormalizeXmlScalar()
|
||||
{
|
||||
$normalizer = new class() extends AbstractObjectNormalizer {
|
||||
$normalizer = new class extends AbstractObjectNormalizer {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(null, new MetadataAwareNameConverter(new ClassMetadataFactory(new AttributeLoader())));
|
||||
|
||||
@@ -50,23 +50,23 @@ class ConstraintViolationListNormalizerTest extends TestCase
|
||||
'detail' => 'd: a
|
||||
4: 1',
|
||||
'violations' => [
|
||||
[
|
||||
'propertyPath' => 'd',
|
||||
'title' => 'a',
|
||||
'template' => 'b',
|
||||
'type' => 'urn:uuid:f',
|
||||
'parameters' => [
|
||||
'value' => 'foo',
|
||||
],
|
||||
],
|
||||
[
|
||||
'propertyPath' => '4',
|
||||
'title' => '1',
|
||||
'template' => '2',
|
||||
'type' => 'urn:uuid:6',
|
||||
'parameters' => [],
|
||||
[
|
||||
'propertyPath' => 'd',
|
||||
'title' => 'a',
|
||||
'template' => 'b',
|
||||
'type' => 'urn:uuid:f',
|
||||
'parameters' => [
|
||||
'value' => 'foo',
|
||||
],
|
||||
],
|
||||
[
|
||||
'propertyPath' => '4',
|
||||
'title' => '1',
|
||||
'template' => '2',
|
||||
'type' => 'urn:uuid:6',
|
||||
'parameters' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->normalizer->normalize($list));
|
||||
|
||||
@@ -59,7 +59,7 @@ trait CallbacksTestTrait
|
||||
{
|
||||
$normalizer = $this->getNormalizerForCallbacksWithPropertyTypeExtractor();
|
||||
|
||||
$obj = new class() extends CallbacksObject {
|
||||
$obj = new class extends CallbacksObject {
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
@@ -101,7 +101,7 @@ trait CallbacksTestTrait
|
||||
{
|
||||
$normalizer = $this->getNormalizerForCallbacksWithPropertyTypeExtractor();
|
||||
|
||||
$objWithNoConstructorArgument = new class() extends CallbacksObject {
|
||||
$objWithNoConstructorArgument = new class extends CallbacksObject {
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ trait CircularReferenceTestTrait
|
||||
$obj = $this->getSelfReferencingModel();
|
||||
|
||||
$this->expectException(CircularReferenceException::class);
|
||||
$this->expectExceptionMessage(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d).', $obj::class, $expectedLimit));
|
||||
$this->expectExceptionMessage(\sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d).', $obj::class, $expectedLimit));
|
||||
$normalizer->normalize($obj, null, $context);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ trait ConstructorArgumentsTestTrait
|
||||
$normalizer = $this->getDenormalizerForConstructArguments();
|
||||
try {
|
||||
$normalizer->denormalize($data, ConstructorArgumentsObject::class);
|
||||
self::fail(sprintf('Failed asserting that exception of type "%s" is thrown.', MissingConstructorArgumentsException::class));
|
||||
self::fail(\sprintf('Failed asserting that exception of type "%s" is thrown.', MissingConstructorArgumentsException::class));
|
||||
} catch (MissingConstructorArgumentsException $e) {
|
||||
self::assertSame(ConstructorArgumentsObject::class, $e->getClass());
|
||||
self::assertSame(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$foo", "$baz".', ConstructorArgumentsObject::class), $e->getMessage());
|
||||
self::assertSame(\sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$foo", "$baz".', ConstructorArgumentsObject::class), $e->getMessage());
|
||||
self::assertSame(['foo', 'baz'], $e->getMissingConstructorArguments());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class MapDenormalizationTest extends TestCase
|
||||
|
||||
private function getSerializer()
|
||||
{
|
||||
$loaderMock = new class() implements ClassMetadataFactoryInterface {
|
||||
$loaderMock = new class implements ClassMetadataFactoryInterface {
|
||||
public function getMetadataFor($value): ClassMetadataInterface
|
||||
{
|
||||
if (AbstractDummyValue::class === $value) {
|
||||
|
||||
@@ -737,7 +737,7 @@ class ObjectNormalizerTest extends TestCase
|
||||
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
|
||||
$serializer = new Serializer([new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer]);
|
||||
|
||||
$this->assertSame('bar', $serializer->denormalize(['foo' => 'bar'], (new class() {
|
||||
$this->assertSame('bar', $serializer->denormalize(['foo' => 'bar'], (new class {
|
||||
/** @var self::*|null */
|
||||
public $foo;
|
||||
})::class)->foo);
|
||||
@@ -786,15 +786,15 @@ class ObjectNormalizerTest extends TestCase
|
||||
|
||||
public function testAdvancedNameConverter()
|
||||
{
|
||||
$nameConverter = new class() implements AdvancedNameConverterInterface {
|
||||
$nameConverter = new class implements AdvancedNameConverterInterface {
|
||||
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
return sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
||||
return \sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
||||
}
|
||||
|
||||
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
return sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
||||
return \sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -952,7 +952,7 @@ class ObjectNormalizerTest extends TestCase
|
||||
'tell' => true,
|
||||
'class' => true,
|
||||
'responsibility' => true,
|
||||
123 => 321
|
||||
123 => 321,
|
||||
], $normalized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,19 +465,19 @@ class PropertyNormalizerTest extends TestCase
|
||||
{
|
||||
$normalizer = $this->getDenormalizerForTypeEnforcement();
|
||||
$root = $normalizer->denormalize([
|
||||
'children' => [[
|
||||
['foo' => 'one', 'bar' => 'two'],
|
||||
['foo' => 'three', 'bar' => 'four'],
|
||||
]],
|
||||
'grandChildren' => [[[
|
||||
['foo' => 'five', 'bar' => 'six'],
|
||||
['foo' => 'seven', 'bar' => 'eight'],
|
||||
]]],
|
||||
'intMatrix' => [
|
||||
[0, 1, 2],
|
||||
[3, 4, 5],
|
||||
],
|
||||
'children' => [[
|
||||
['foo' => 'one', 'bar' => 'two'],
|
||||
['foo' => 'three', 'bar' => 'four'],
|
||||
]],
|
||||
'grandChildren' => [[[
|
||||
['foo' => 'five', 'bar' => 'six'],
|
||||
['foo' => 'seven', 'bar' => 'eight'],
|
||||
]]],
|
||||
'intMatrix' => [
|
||||
[0, 1, 2],
|
||||
[3, 4, 5],
|
||||
],
|
||||
],
|
||||
RootDummy::class,
|
||||
'any'
|
||||
);
|
||||
|
||||
@@ -50,8 +50,8 @@ class UidNormalizerTest extends TestCase
|
||||
{
|
||||
$uidFormats = [null, 'canonical', 'base58', 'base32', 'rfc4122'];
|
||||
$data = [
|
||||
[
|
||||
UuidV1::fromString('9b7541de-6f87-11ea-ab3c-9da9a81562fc'),
|
||||
[
|
||||
UuidV1::fromString('9b7541de-6f87-11ea-ab3c-9da9a81562fc'),
|
||||
'9b7541de-6f87-11ea-ab3c-9da9a81562fc',
|
||||
'9b7541de-6f87-11ea-ab3c-9da9a81562fc',
|
||||
'LCQS8f2p5SDSiAt9V7ZYnF',
|
||||
|
||||
@@ -408,7 +408,7 @@ class SerializerTest extends TestCase
|
||||
$example = new AbstractDummyFirstChild('foo-value', 'bar-value');
|
||||
$example->setQuux(new DummyFirstChildQuux('quux'));
|
||||
|
||||
$loaderMock = new class() implements ClassMetadataFactoryInterface {
|
||||
$loaderMock = new class implements ClassMetadataFactoryInterface {
|
||||
public function getMetadataFor($value): ClassMetadataInterface
|
||||
{
|
||||
if (AbstractDummy::class === $value) {
|
||||
@@ -589,10 +589,10 @@ class SerializerTest extends TestCase
|
||||
$data['c2'] = new \ArrayObject(['nested' => new \ArrayObject(['k' => 'v'])]);
|
||||
$data['d1'] = new \ArrayObject(['nested' => []]);
|
||||
$data['d2'] = new \ArrayObject(['nested' => ['k' => 'v']]);
|
||||
$data['e1'] = new class() {
|
||||
$data['e1'] = new class {
|
||||
public $map = [];
|
||||
};
|
||||
$data['e2'] = new class() {
|
||||
$data['e2'] = new class {
|
||||
public $map = ['k' => 'v'];
|
||||
};
|
||||
$data['f1'] = new class(new \ArrayObject()) {
|
||||
@@ -1192,7 +1192,7 @@ class SerializerTest extends TestCase
|
||||
'useMessageForUser' => false,
|
||||
'message' => 'The type of the "string" attribute for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full" must be one of "string" ("null" given).',
|
||||
],
|
||||
];
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $exceptionsAsArray);
|
||||
}
|
||||
@@ -1442,8 +1442,8 @@ class SerializerTest extends TestCase
|
||||
|
||||
try {
|
||||
$serializer->deserialize('{"get": "POST"}', DummyObjectWithEnumProperty::class, 'json', [
|
||||
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
|
||||
]);
|
||||
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->assertInstanceOf(PartialDenormalizationException::class, $e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user