diff --git a/Encoder/XmlEncoder.php b/Encoder/XmlEncoder.php index 42a070360..1662f3964 100644 --- a/Encoder/XmlEncoder.php +++ b/Encoder/XmlEncoder.php @@ -409,7 +409,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName = 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, $this->format, $this->context); @@ -475,7 +475,7 @@ private function selectNodeType(\DOMNode $node, $val): bool $this->buildXml($node, $val); } 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, $this->format, $this->context)); diff --git a/Mapping/Loader/FileLoader.php b/Mapping/Loader/FileLoader.php index c34d14b4b..f4947ef4c 100644 --- a/Mapping/Loader/FileLoader.php +++ b/Mapping/Loader/FileLoader.php @@ -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; diff --git a/Mapping/Loader/LoaderChain.php b/Mapping/Loader/LoaderChain.php index 7f90c8404..f422f11c7 100644 --- a/Mapping/Loader/LoaderChain.php +++ b/Mapping/Loader/LoaderChain.php @@ -40,7 +40,7 @@ public function __construct(array $loaders) { foreach ($loaders as $loader) { if (!$loader instanceof LoaderInterface) { - throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface.', \get_class($loader))); + throw new MappingException(sprintf('Class "%s" is expected to implement LoaderInterface.', \get_class($loader))); } } diff --git a/Normalizer/AbstractNormalizer.php b/Normalizer/AbstractNormalizer.php index 7ec9e8a34..c5d8b727e 100644 --- a/Normalizer/AbstractNormalizer.php +++ b/Normalizer/AbstractNormalizer.php @@ -354,7 +354,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex if ($constructorParameter->isVariadic()) { if ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) { if (!\is_array($data[$paramName])) { - 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 = []; @@ -384,7 +384,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex } elseif ($constructorParameter->isDefaultValueAvailable()) { $params[] = $constructorParameter->getDefaultValue(); } else { - throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present.', $class, $constructorParameter->name)); + throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires parameter "%s" to be present.', $class, $constructorParameter->name)); } } @@ -406,7 +406,7 @@ protected function denormalizeParameter(\ReflectionClass $class, \ReflectionPara try { if (null !== $parameter->getClass()) { 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.', $parameter->getClass(), self::class)); + throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameter->getClass(), self::class)); } $parameterClass = $parameter->getClass()->getName(); $parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format)); diff --git a/Normalizer/ArrayDenormalizer.php b/Normalizer/ArrayDenormalizer.php index ad5090faa..e1359053d 100644 --- a/Normalizer/ArrayDenormalizer.php +++ b/Normalizer/ArrayDenormalizer.php @@ -69,7 +69,7 @@ public function denormalize($data, string $type, string $format = null, array $c public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool { if (null === $this->serializer) { - throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used.', __METHOD__)); + throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used.', __METHOD__)); } return '[]' === substr($type, -2) diff --git a/Normalizer/DateIntervalNormalizer.php b/Normalizer/DateIntervalNormalizer.php index b166c84a4..2f7d59a7e 100644 --- a/Normalizer/DateIntervalNormalizer.php +++ b/Normalizer/DateIntervalNormalizer.php @@ -72,7 +72,7 @@ public function hasCacheableSupportsMethod(): bool public function denormalize($data, string $type, string $format = null, array $context = []) { if (!\is_string($data)) { - throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data))); + throw new InvalidArgumentException(sprintf('Data expected to be a string, "%s" given.', \gettype($data))); } if (!$this->isISO8601($data)) { diff --git a/Serializer.php b/Serializer.php index 94ec565f5..334f324b8 100644 --- a/Serializer.php +++ b/Serializer.php @@ -112,7 +112,7 @@ public function __construct(array $normalizers = [], array $encoders = []) final public function serialize($data, string $format, array $context = []): string { if (!$this->supportsEncoding($format, $context)) { - throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported.', $format)); + throw new NotEncodableValueException(sprintf('Serialization for the format "%s" is not supported.', $format)); } if ($this->encoder->needsNormalization($format, $context)) { @@ -128,7 +128,7 @@ final public function serialize($data, string $format, array $context = []): str final public function deserialize($data, string $type, string $format, array $context = []) { if (!$this->supportsDecoding($format, $context)) { - throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported.', $format)); + throw new NotEncodableValueException(sprintf('Deserialization for the format "%s" is not supported.', $format)); } $data = $this->decode($data, $format, $context); @@ -164,7 +164,7 @@ public function normalize($data, string $format = null, array $context = []) 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_class($data))); + throw new NotNormalizableValueException(sprintf('Could not normalize object of type "%s", no supporting normalizer found.', \get_class($data))); } throw new NotNormalizableValueException(sprintf('An unexpected value could not be normalized: %s.', !\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data)))); @@ -185,7 +185,7 @@ public function denormalize($data, string $type, string $format = null, array $c return $normalizer->denormalize($data, $type, $format, $context); } - 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)); } /** diff --git a/Tests/Normalizer/Features/ConstructorArgumentsTestTrait.php b/Tests/Normalizer/Features/ConstructorArgumentsTestTrait.php index 40cd02f19..3d4ce2693 100644 --- a/Tests/Normalizer/Features/ConstructorArgumentsTestTrait.php +++ b/Tests/Normalizer/Features/ConstructorArgumentsTestTrait.php @@ -55,7 +55,7 @@ public function testConstructorWithMissingData() $normalizer = $this->getDenormalizerForConstructArguments(); $this->expectException(MissingConstructorArgumentsException::class); - $this->expectExceptionMessage('Cannot create an instance of '.ConstructorArgumentsObject::class.' from serialized data because its constructor requires parameter "bar" to be present.'); + $this->expectExceptionMessage('Cannot create an instance of "'.ConstructorArgumentsObject::class.'" from serialized data because its constructor requires parameter "bar" to be present.'); $normalizer->denormalize($data, ConstructorArgumentsObject::class); } }