From 50701fed9f3c7d44c15731d3b1eefd9927fa362c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 15 Aug 2019 13:16:03 +0200 Subject: [PATCH 1/3] [Serializer] Fixed docblocks and parameter names. --- .../Mapping/Factory/ClassResolverTrait.php | 2 +- .../Normalizer/AbstractObjectNormalizer.php | 12 ++++++------ .../Serializer/Normalizer/ArrayDenormalizer.php | 10 +++++----- .../Serializer/Normalizer/CustomNormalizer.php | 4 ++-- .../Serializer/Normalizer/DataUriNormalizer.php | 6 +++--- .../Serializer/Normalizer/DateIntervalNormalizer.php | 2 +- .../Serializer/Normalizer/DateTimeNormalizer.php | 10 +++++----- .../Serializer/Normalizer/DenormalizerInterface.php | 4 ++-- .../Normalizer/JsonSerializableNormalizer.php | 2 +- .../Serializer/Normalizer/ObjectToPopulateTrait.php | 7 +++---- .../Tests/Fixtures/AbstractNormalizerDummy.php | 2 +- .../Normalizer/AbstractObjectNormalizerTest.php | 6 +++--- .../Serializer/Tests/Normalizer/TestDenormalizer.php | 2 +- 13 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php b/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php index 6bb647ebee..73c02a647c 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php @@ -25,7 +25,7 @@ trait ClassResolverTrait /** * Gets a class name for a given class or instance. * - * @param mixed $value + * @param object|string $value * * @return string * diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index 29d90bfbd6..489ac49a05 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -168,25 +168,25 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { if (!isset($context['cache_key'])) { $context['cache_key'] = $this->getCacheKey($format, $context); } - $allowedAttributes = $this->getAllowedAttributes($class, $context, true); + $allowedAttributes = $this->getAllowedAttributes($type, $context, true); $normalizedData = $this->prepareForDenormalization($data); $extraAttributes = []; - $reflectionClass = new \ReflectionClass($class); - $object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes, $format); + $reflectionClass = new \ReflectionClass($type); + $object = $this->instantiateObject($normalizedData, $type, $context, $reflectionClass, $allowedAttributes, $format); foreach ($normalizedData as $attribute => $value) { if ($this->nameConverter) { $attribute = $this->nameConverter->denormalize($attribute); } - if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($class, $attribute, $format, $context)) { + if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($type, $attribute, $format, $context)) { if (isset($context[self::ALLOW_EXTRA_ATTRIBUTES]) && !$context[self::ALLOW_EXTRA_ATTRIBUTES]) { $extraAttributes[] = $attribute; } @@ -194,7 +194,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer continue; } - $value = $this->validateAndDenormalize($class, $attribute, $value, $format, $context); + $value = $this->validateAndDenormalize($type, $attribute, $value, $format, $context); try { $this->setAttributeValue($object, $attribute, $value, $format, $context); } catch (InvalidArgumentException $e) { diff --git a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php index af80d00ba0..93d6fc009b 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php @@ -36,7 +36,7 @@ class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterfa * * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { if (null === $this->serializer) { throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); @@ -44,12 +44,12 @@ class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterfa if (!\is_array($data)) { throw new InvalidArgumentException('Data expected to be an array, '.\gettype($data).' given.'); } - if ('[]' !== substr($class, -2)) { - throw new InvalidArgumentException('Unsupported class: '.$class); + if ('[]' !== substr($type, -2)) { + throw new InvalidArgumentException('Unsupported class: '.$type); } $serializer = $this->serializer; - $class = substr($class, 0, -2); + $type = substr($type, 0, -2); $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null; foreach ($data as $key => $value) { @@ -57,7 +57,7 @@ class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterfa throw new NotNormalizableValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, \gettype($key))); } - $data[$key] = $serializer->denormalize($value, $class, $format, $context); + $data[$key] = $serializer->denormalize($value, $type, $format, $context); } return $data; diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index 969dcf5fc9..a8621cae82 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -35,9 +35,9 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { - $object = $this->extractObjectToPopulate($class, $context) ?: new $class(); + $object = $this->extractObjectToPopulate($type, $context) ?: new $type(); $object->denormalize($this->serializer, $data, $format, $context); return $object; diff --git a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php index 58ce6c2f02..99ca3487ab 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -89,14 +89,14 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface * @throws InvalidArgumentException * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) { throw new NotNormalizableValueException('The provided "data:" URI is not valid.'); } try { - switch ($class) { + switch ($type) { case 'Symfony\Component\HttpFoundation\File\File': return new File($data, false); @@ -108,7 +108,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface throw new NotNormalizableValueException($exception->getMessage(), $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".', $class)); + 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)); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index bd43091bf1..83d9312b01 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -64,7 +64,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa * @throws InvalidArgumentException * @throws UnexpectedValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { if (!\is_string($data)) { throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data))); diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php index 978237510b..39c31f00f1 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -78,7 +78,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface * * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { $dateTimeFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : null; $timezone = $this->getTimezone($context); @@ -90,16 +90,16 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface if (null !== $dateTimeFormat) { if (null === $timezone && \PHP_VERSION_ID < 70000) { // https://bugs.php.net/68669 - $object = \DateTime::class === $class ? \DateTime::createFromFormat($dateTimeFormat, $data) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data); + $object = \DateTime::class === $type ? \DateTime::createFromFormat($dateTimeFormat, $data) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data); } else { - $object = \DateTime::class === $class ? \DateTime::createFromFormat($dateTimeFormat, $data, $timezone) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data, $timezone); + $object = \DateTime::class === $type ? \DateTime::createFromFormat($dateTimeFormat, $data, $timezone) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data, $timezone); } if (false !== $object) { return $object; } - $dateTimeErrors = \DateTime::class === $class ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors(); + $dateTimeErrors = \DateTime::class === $type ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors(); throw new NotNormalizableValueException(sprintf( 'Parsing datetime string "%s" using format "%s" resulted in %d errors:'."\n".'%s', @@ -111,7 +111,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface } try { - return \DateTime::class === $class ? new \DateTime($data, $timezone) : new \DateTimeImmutable($data, $timezone); + return \DateTime::class === $type ? new \DateTime($data, $timezone) : new \DateTimeImmutable($data, $timezone); } catch (\Exception $e) { throw new NotNormalizableValueException($e->getMessage(), $e->getCode(), $e); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php index 7a12d20f11..cdd6685d84 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php @@ -30,7 +30,7 @@ interface DenormalizerInterface * Denormalizes data back into an object of the given class. * * @param mixed $data Data to restore - * @param string $class The expected class to instantiate + * @param string $type The expected class to instantiate * @param string $format Format the given data was extracted from * @param array $context Options available to the denormalizer * @@ -44,7 +44,7 @@ interface DenormalizerInterface * @throws RuntimeException Occurs if the class cannot be instantiated * @throws ExceptionInterface Occurs for all the other cases of errors */ - public function denormalize($data, $class, $format = null, array $context = []); + public function denormalize($data, $type, $format = null, array $context = []); /** * Checks whether the given class is supported for denormalization by this normalizer. diff --git a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php index b4e53e5135..f4080e524c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php @@ -60,7 +60,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class)); } diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectToPopulateTrait.php b/src/Symfony/Component/Serializer/Normalizer/ObjectToPopulateTrait.php index 7150a6e6ee..3560acbfce 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectToPopulateTrait.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectToPopulateTrait.php @@ -17,10 +17,9 @@ trait ObjectToPopulateTrait * Extract the `object_to_populate` field from the context if it exists * and is an instance of the provided $class. * - * @param string $class The class the object should be - * @param $context The denormalization context - * @param string $key They in which to look for the object to populate. - * Keeps backwards compatibility with `AbstractNormalizer`. + * @param string $class The class the object should be + * @param string|null $key They in which to look for the object to populate. + * Keeps backwards compatibility with `AbstractNormalizer`. * * @return object|null an object if things check out, null otherwise */ diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php index f576a241a4..94a5e895c6 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php @@ -46,7 +46,7 @@ class AbstractNormalizerDummy extends AbstractNormalizer /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index 8ce2c10558..a6807c79bf 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -304,13 +304,13 @@ class ArrayDenormalizerDummy implements DenormalizerInterface, SerializerAwareIn * * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { $serializer = $this->serializer; - $class = substr($class, 0, -2); + $type = substr($type, 0, -2); foreach ($data as $key => $value) { - $data[$key] = $serializer->denormalize($value, $class, $format, $context); + $data[$key] = $serializer->denormalize($value, $type, $format, $context); } return $data; diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php b/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php index 036d2bb84c..eefef12d45 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php @@ -23,7 +23,7 @@ class TestDenormalizer implements DenormalizerInterface /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $type, $format = null, array $context = []) { } From 6ecbcf6f22f03aeb75ef73142a2313b8001cbc15 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 16 Aug 2019 01:33:50 +0200 Subject: [PATCH 2/3] [Console] Fix incomplete output mock. --- src/Symfony/Component/Console/Tests/Helper/DumperTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Tests/Helper/DumperTest.php b/src/Symfony/Component/Console/Tests/Helper/DumperTest.php index 7974527d36..8791b08b96 100644 --- a/src/Symfony/Component/Console/Tests/Helper/DumperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/DumperTest.php @@ -37,7 +37,10 @@ class DumperTest extends TestCase */ public function testInvoke($variable) { - $dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock()); + $output = $this->getMockBuilder(OutputInterface::class)->getMock(); + $output->method('isDecorated')->willReturn(false); + + $dumper = new Dumper($output); $this->assertDumpMatchesFormat($dumper($variable), $variable); } From df47058c559003c6867310f6cbff84c542306fd3 Mon Sep 17 00:00:00 2001 From: Smaine Milianni Date: Fri, 16 Aug 2019 02:35:48 +0100 Subject: [PATCH 3/3] [VarDumper] Remove useless variable --- .../Component/VarDumper/Tests/Dumper/FunctionsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/FunctionsTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/FunctionsTest.php index 0bd596c2ad..7444d4bf58 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/FunctionsTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/FunctionsTest.php @@ -26,7 +26,7 @@ class FunctionsTest extends TestCase ob_start(); $return = dump($var1); - $out = ob_get_clean(); + ob_end_clean(); $this->assertEquals($var1, $return); } @@ -41,7 +41,7 @@ class FunctionsTest extends TestCase ob_start(); $return = dump($var1, $var2, $var3); - $out = ob_get_clean(); + ob_end_clean(); $this->assertEquals([$var1, $var2, $var3], $return); }