[Serializer] Fix denormalizing nested arrays as object values

by @mcfedr

Some issues have been detected in this pull request

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/symfony/symfony/30258/952527d7b6df151043ec5df333735436f6ae8936/cs.diff | patch -p0
diff -ru src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
--- src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php	2021-01-23 18:30:10.230925418 +0000
+++ src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php	2021-01-23 18:30:11.619878809 +0000
@@ -299,7 +299,7 @@
      */
     public function setMaxDepthHandler(?callable $handler): void
     {
-        @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the "max_depth_handler" key of the context instead.', __METHOD__), E_USER_DEPRECATED);
+        @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the "max_depth_handler" key of the context instead.', __METHOD__), \E_USER_DEPRECATED);
 
         $this->maxDepthHandler = $handler;
     }
@@ -571,7 +571,7 @@
         if (\func_num_args() >= 3) {
             $format = func_get_arg(2);
         } else {
-            @trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED);
+            @trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', static::class, __FUNCTION__), \E_USER_DEPRECATED);
             $format = null;
         }
 

0
Common Typos

0
License Headers

0
Pull Request Contributor Headers

0
File Permissions

0
Merge Commits

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/symfony/symfony/30258/952527d7b6df151043ec5df333735436f6ae8936/exception_messages.diff | patch -p0
diff -ru src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
--- src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php	2021-01-23 18:30:10.230925418 +0000
+++ src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php	2021-01-23 18:30:12.532848172 +0000
@@ -200,7 +200,7 @@
 
         foreach ($stack as $attribute => $attributeValue) {
             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));
             }
 
             $data = $this->updateData($data, $attribute, $this->serializer->normalize($attributeValue, $format, $this->createChildContext($context, $attribute, $format)), $class, $format, $context);
@@ -216,12 +216,12 @@
     {
         if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForClass($class)) {
             if (!isset($data[$mapping->getTypeProperty()])) {
-                throw new RuntimeException(sprintf('Type property "%s" not found for the abstract object "%s"', $mapping->getTypeProperty(), $class));
+                throw new RuntimeException(sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class));
             }
 
             $type = $data[$mapping->getTypeProperty()];
             if (null === ($mappedClass = $mapping->getClassForType($type))) {
-                throw new RuntimeException(sprintf('The type "%s" has no mapped class for the abstract object "%s"', $type, $class));
+                throw new RuntimeException(sprintf('The type "%s" has no mapped class for the abstract object "%s".', $type, $class));
             }
 
             $class = $mappedClass;
@@ -353,7 +353,7 @@
             try {
                 $this->setAttributeValue($object, $attribute, $value, $format, $context);
             } catch (InvalidArgumentException $e) {
-                throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": %s.', $attribute, $type, $e->getMessage()), $e->getCode(), $e);
+                throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": "%s".', $attribute, $type, $e->getMessage()), $e->getCode(), $e);
             }
         }
 
@@ -402,7 +402,7 @@
 
             if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {
                 if (!$this->serializer instanceof DenormalizerInterface) {
-                    throw new LogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer', $attribute, $class));
+                    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);

0
Usage of void in test files

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/symfony/symfony/30258/952527d7b6df151043ec5df333735436f6ae8936/class_keyword.diff | patch -p0
diff -ru src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
--- src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php	2021-01-23 18:30:10.677910419 +0000
+++ src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php	2021-01-23 18:30:12.542847837 +0000
@@ -61,7 +61,7 @@
 
     public function testDenormalizeWithExtraAttributes()
     {
-        $this->expectException('Symfony\Component\Serializer\Exception\ExtraAttributesException');
+        $this->expectException(\Symfony\Component\Serializer\Exception\ExtraAttributesException::class);
         $this->expectExceptionMessage('Extra attributes are not allowed ("fooFoo", "fooBar" are unknown).');
         $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
         $normalizer = new AbstractObjectNormalizerDummy($factory);
@@ -75,7 +75,7 @@
 
     public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory()
     {
-        $this->expectException('Symfony\Component\Serializer\Exception\ExtraAttributesException');
+        $this->expectException(\Symfony\Component\Serializer\Exception\ExtraAttributesException::class);
         $this->expectExceptionMessage('Extra attributes are not allowed ("fooFoo", "fooBar" are unknown).');
         $normalizer = new AbstractObjectNormalizerWithMetadata();
         $normalizer->denormalize(
@@ -254,7 +254,7 @@
      */
     public function testExtraAttributesException()
     {
-        $this->expectException('Symfony\Component\Serializer\Exception\LogicException');
+        $this->expectException(\Symfony\Component\Serializer\Exception\LogicException::class);
         $this->expectExceptionMessage('A class metadata factory must be provided in the constructor when setting "allow_extra_attributes" to false.');
         $normalizer = new ObjectNormalizer();
 
diff -ru src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php
--- src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php	2021-01-23 18:30:10.900902936 +0000
+++ src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php	2021-01-23 18:30:12.542847837 +0000
@@ -33,7 +33,7 @@
 
     protected function setUp(): void
     {
-        $this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')->getMock();
+        $this->serializer = $this->getMockBuilder(Serializer::class)->getMock();
         $this->denormalizer = new ArrayDenormalizer();
         $this->denormalizer->setSerializer($this->serializer);
     }