From 8ee83879ebec38c8a2eb19f9948c2cb89518c11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 11 Feb 2018 19:19:04 +0100 Subject: [PATCH] [Serializer] optims and cleanup --- .../Serializer/Annotation/Groups.php | 10 +++---- .../Serializer/Encoder/JsonEncoder.php | 2 +- .../Serializer/Encoder/XmlEncoder.php | 28 +++++++++---------- .../Serializer/Mapping/AttributeMetadata.php | 2 +- .../Mapping/Factory/ClassMetadataFactory.php | 6 ++-- .../Serializer/Mapping/Loader/LoaderChain.php | 2 +- .../Mapping/Loader/YamlFileLoader.php | 10 +++---- .../CamelCaseToSnakeCaseNameConverter.php | 6 ++-- .../Normalizer/AbstractNormalizer.php | 20 ++++++------- .../Normalizer/GetSetMethodNormalizer.php | 16 +++++------ .../Normalizer/ObjectNormalizer.php | 10 +++---- .../Normalizer/PropertyNormalizer.php | 12 ++++---- .../Component/Serializer/Serializer.php | 6 ++-- 13 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/Symfony/Component/Serializer/Annotation/Groups.php b/src/Symfony/Component/Serializer/Annotation/Groups.php index d0339552a7..be29135ae8 100644 --- a/src/Symfony/Component/Serializer/Annotation/Groups.php +++ b/src/Symfony/Component/Serializer/Annotation/Groups.php @@ -34,16 +34,16 @@ class Groups public function __construct(array $data) { if (!isset($data['value']) || !$data['value']) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this))); + throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', \get_class($this))); } - if (!is_array($data['value'])) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this))); + if (!\is_array($data['value'])) { + throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', \get_class($this))); } foreach ($data['value'] as $group) { - if (!is_string($group)) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this))); + if (!\is_string($group)) { + throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', \get_class($this))); } } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index 66d94f85af..2a084f1426 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php @@ -96,7 +96,7 @@ class JsonEncoder implements EncoderInterface, DecoderInterface */ public static function getLastErrorMessage() { - if (function_exists('json_last_error_msg')) { + if (\function_exists('json_last_error_msg')) { return json_last_error_msg(); } diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 005b565d12..5ce58fb07b 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -179,7 +179,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec */ final protected function appendXMLString(\DOMNode $node, $val) { - if (strlen($val) > 0) { + if (\strlen($val) > 0) { $frag = $this->dom->createDocumentFragment(); $frag->appendXML($val); $node->appendChild($frag); @@ -260,17 +260,17 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec $value = $this->parseXmlValue($node); - if (!count($data)) { + if (!\count($data)) { return $value; } - if (!is_array($value)) { + if (!\is_array($value)) { $data['#'] = $value; return $data; } - if (1 === count($value) && key($value)) { + if (1 === \count($value) && key($value)) { $data[key($value)] = current($value); return $data; @@ -326,7 +326,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec return $node->nodeValue; } - if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) { + if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) { return $node->firstChild->nodeValue; } @@ -351,7 +351,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec } foreach ($value as $key => $val) { - if (is_array($val) && 1 === count($val)) { + if (\is_array($val) && 1 === \count($val)) { $value[$key] = current($val); } } @@ -374,7 +374,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec { $append = true; - if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) { + if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) { foreach ($data as $key => $data) { //Ah this is the magic @ attribute types. if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) { @@ -384,7 +384,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec $parentNode->setAttribute($attributeName, $data); } elseif ('#' === $key) { $append = $this->selectNodeType($parentNode, $data); - } elseif (is_array($data) && false === is_numeric($key)) { + } elseif (\is_array($data) && false === is_numeric($key)) { // Is this array fully numeric keys? if (ctype_digit(implode('', array_keys($data)))) { /* @@ -408,7 +408,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec return $append; } - if (is_object($data)) { + if (\is_object($data)) { $data = $this->serializer->normalize($data, $this->format, $this->context); if (null !== $data && !is_scalar($data)) { return $this->buildXml($parentNode, $data, $xmlRootNodeName); @@ -477,22 +477,22 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec */ private function selectNodeType(\DOMNode $node, $val) { - if (is_array($val)) { + if (\is_array($val)) { return $this->buildXml($node, $val); } elseif ($val instanceof \SimpleXMLElement) { $child = $this->dom->importNode(dom_import_simplexml($val), true); $node->appendChild($child); } elseif ($val instanceof \Traversable) { $this->buildXml($node, $val); - } elseif (is_object($val)) { + } elseif (\is_object($val)) { return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context)); } elseif (is_numeric($val)) { return $this->appendText($node, (string) $val); - } elseif (is_string($val) && $this->needsCdataWrapping($val)) { + } elseif (\is_string($val) && $this->needsCdataWrapping($val)) { return $this->appendCData($node, $val); - } elseif (is_string($val)) { + } elseif (\is_string($val)) { return $this->appendText($node, $val); - } elseif (is_bool($val)) { + } elseif (\is_bool($val)) { return $this->appendText($node, (int) $val); } elseif ($val instanceof \DOMNode) { $child = $this->dom->importNode($val, true); diff --git a/src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php b/src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php index 600e17be4f..1d8496179a 100644 --- a/src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php +++ b/src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php @@ -55,7 +55,7 @@ class AttributeMetadata implements AttributeMetadataInterface */ public function addGroup($group) { - if (!in_array($group, $this->groups)) { + if (!\in_array($group, $this->groups)) { $this->groups[] = $group; } } diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php index 2babf7e27d..c058e021df 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php @@ -40,7 +40,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface { $class = $this->getClass($value); if (!$class) { - throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($value))); + throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value))); } if (isset($this->loadedClasses[$class])) { @@ -96,10 +96,10 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface */ private function getClass($value) { - if (!is_object($value) && !is_string($value)) { + if (!\is_object($value) && !\is_string($value)) { return false; } - return ltrim(is_object($value) ? get_class($value) : $value, '\\'); + return ltrim(\is_object($value) ? \get_class($value) : $value, '\\'); } } diff --git a/src/Symfony/Component/Serializer/Mapping/Loader/LoaderChain.php b/src/Symfony/Component/Serializer/Mapping/Loader/LoaderChain.php index 3b0192b7e4..461001fe57 100644 --- a/src/Symfony/Component/Serializer/Mapping/Loader/LoaderChain.php +++ b/src/Symfony/Component/Serializer/Mapping/Loader/LoaderChain.php @@ -40,7 +40,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_class($loader))); + throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', \get_class($loader))); } } diff --git a/src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php b/src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php index be2de7b6f1..ac48d81614 100644 --- a/src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php @@ -30,7 +30,7 @@ class YamlFileLoader extends FileLoader * * @var array */ - private $classes = null; + private $classes; /** * {@inheritdoc} @@ -53,7 +53,7 @@ class YamlFileLoader extends FileLoader } // not an array - if (!is_array($classes)) { + if (!\is_array($classes)) { throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file)); } @@ -66,7 +66,7 @@ class YamlFileLoader extends FileLoader $yaml = $this->classes[$classMetadata->getName()]; - if (isset($yaml['attributes']) && is_array($yaml['attributes'])) { + if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) { $attributesMetadata = $classMetadata->getAttributesMetadata(); foreach ($yaml['attributes'] as $attribute => $data) { @@ -78,12 +78,12 @@ class YamlFileLoader extends FileLoader } if (isset($data['groups'])) { - if (!is_array($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())); } foreach ($data['groups'] as $group) { - if (!is_string($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())); } diff --git a/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php b/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php index ca2705cf2a..9241d40357 100644 --- a/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php +++ b/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php @@ -36,11 +36,11 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface */ public function normalize($propertyName) { - if (null === $this->attributes || in_array($propertyName, $this->attributes)) { + if (null === $this->attributes || \in_array($propertyName, $this->attributes)) { $lcPropertyName = lcfirst($propertyName); $snakeCasedName = ''; - $len = strlen($lcPropertyName); + $len = \strlen($lcPropertyName); for ($i = 0; $i < $len; ++$i) { if (ctype_upper($lcPropertyName[$i])) { $snakeCasedName .= '_'.strtolower($lcPropertyName[$i]); @@ -68,7 +68,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface $camelCasedName = lcfirst($camelCasedName); } - if (null === $this->attributes || in_array($camelCasedName, $this->attributes)) { + if (null === $this->attributes || \in_array($camelCasedName, $this->attributes)) { return $camelCasedName; } diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index 031bcf7d08..88f5f9273d 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -100,7 +100,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N */ public function setCircularReferenceHandler($circularReferenceHandler) { - if (!is_callable($circularReferenceHandler)) { + if (!\is_callable($circularReferenceHandler)) { throw new InvalidArgumentException('The given circular reference handler is not callable.'); } @@ -121,7 +121,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N public function setCallbacks(array $callbacks) { foreach ($callbacks as $attribute => $callback) { - if (!is_callable($callback)) { + if (!\is_callable($callback)) { throw new InvalidArgumentException(sprintf( 'The given callback for attribute "%s" is not callable.', $attribute @@ -220,10 +220,10 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N protected function handleCircularReference($object) { if ($this->circularReferenceHandler) { - return call_user_func($this->circularReferenceHandler, $object); + return \call_user_func($this->circularReferenceHandler, $object); } - throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', get_class($object), $this->circularReferenceLimit)); + throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', \get_class($object), $this->circularReferenceLimit)); } /** @@ -253,13 +253,13 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N */ protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false) { - if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !is_array($context[static::GROUPS])) { + if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) { return false; } $allowedAttributes = array(); foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) { - if (count(array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS]))) { + if (array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS])) { $allowedAttributes[] = $attributesAsString ? $attributeMetadata->getName() : $attributeMetadata; } } @@ -302,7 +302,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N { if ( isset($context[static::OBJECT_TO_POPULATE]) && - is_object($context[static::OBJECT_TO_POPULATE]) && + \is_object($context[static::OBJECT_TO_POPULATE]) && $context[static::OBJECT_TO_POPULATE] instanceof $class ) { $object = $context[static::OBJECT_TO_POPULATE]; @@ -320,11 +320,11 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N $paramName = $constructorParameter->name; $key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName; - $allowed = false === $allowedAttributes || in_array($paramName, $allowedAttributes); - $ignored = in_array($paramName, $this->ignoredAttributes); + $allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes); + $ignored = \in_array($paramName, $this->ignoredAttributes); if (method_exists($constructorParameter, 'isVariadic') && $constructorParameter->isVariadic()) { if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) { - if (!is_array($data[$paramName])) { + 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)); } diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 6eec32160d..d8cfc1d201 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -58,17 +58,17 @@ class GetSetMethodNormalizer extends AbstractNormalizer foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3)); - if (in_array($attributeName, $this->ignoredAttributes)) { + if (\in_array($attributeName, $this->ignoredAttributes)) { continue; } - if (false !== $allowedAttributes && !in_array($attributeName, $allowedAttributes)) { + if (false !== $allowedAttributes && !\in_array($attributeName, $allowedAttributes)) { continue; } $attributeValue = $method->invoke($object); if (isset($this->callbacks[$attributeName])) { - $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); + $attributeValue = \call_user_func($this->callbacks[$attributeName], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { if (!$this->serializer instanceof NormalizerInterface) { @@ -108,13 +108,13 @@ class GetSetMethodNormalizer extends AbstractNormalizer $attribute = $this->nameConverter->denormalize($attribute); } - $allowed = false === $allowedAttributes || in_array($attribute, $allowedAttributes); - $ignored = in_array($attribute, $this->ignoredAttributes); + $allowed = false === $allowedAttributes || \in_array($attribute, $allowedAttributes); + $ignored = \in_array($attribute, $this->ignoredAttributes); if ($allowed && !$ignored) { $setter = 'set'.ucfirst($attribute); - if (in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) { + if (\in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) { $object->$setter($value); } } @@ -128,7 +128,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer */ public function supportsNormalization($data, $format = null) { - return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data)); + return \is_object($data) && !$data instanceof \Traversable && $this->supports(\get_class($data)); } /** @@ -166,7 +166,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer */ private function isGetMethod(\ReflectionMethod $method) { - $methodLength = strlen($method->name); + $methodLength = \strlen($method->name); return !$method->isStatic() && diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index 5c64e156c3..dc3a49ff7e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -45,7 +45,7 @@ class ObjectNormalizer extends AbstractNormalizer */ public function supportsNormalization($data, $format = null) { - return is_object($data) && !$data instanceof \Traversable; + return \is_object($data) && !$data instanceof \Traversable; } /** @@ -98,14 +98,14 @@ class ObjectNormalizer extends AbstractNormalizer } foreach ($attributes as $attribute) { - if (in_array($attribute, $this->ignoredAttributes)) { + if (\in_array($attribute, $this->ignoredAttributes)) { continue; } $attributeValue = $this->propertyAccessor->getValue($object, $attribute); if (isset($this->callbacks[$attribute])) { - $attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue); + $attributeValue = \call_user_func($this->callbacks[$attribute], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { @@ -150,8 +150,8 @@ class ObjectNormalizer extends AbstractNormalizer $attribute = $this->nameConverter->denormalize($attribute); } - $allowed = false === $allowedAttributes || in_array($attribute, $allowedAttributes); - $ignored = in_array($attribute, $this->ignoredAttributes); + $allowed = false === $allowedAttributes || \in_array($attribute, $allowedAttributes); + $ignored = \in_array($attribute, $this->ignoredAttributes); if ($allowed && !$ignored) { try { diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index a5764244fe..89e1057277 100644 --- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php @@ -50,11 +50,11 @@ class PropertyNormalizer extends AbstractNormalizer $allowedAttributes = $this->getAllowedAttributes($object, $context, true); foreach ($reflectionObject->getProperties() as $property) { - if (in_array($property->name, $this->ignoredAttributes) || $property->isStatic()) { + if (\in_array($property->name, $this->ignoredAttributes) || $property->isStatic()) { continue; } - if (false !== $allowedAttributes && !in_array($property->name, $allowedAttributes)) { + if (false !== $allowedAttributes && !\in_array($property->name, $allowedAttributes)) { continue; } @@ -66,7 +66,7 @@ class PropertyNormalizer extends AbstractNormalizer $attributeValue = $property->getValue($object); if (isset($this->callbacks[$property->name])) { - $attributeValue = call_user_func($this->callbacks[$property->name], $attributeValue); + $attributeValue = \call_user_func($this->callbacks[$property->name], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { if (!$this->serializer instanceof NormalizerInterface) { @@ -105,8 +105,8 @@ class PropertyNormalizer extends AbstractNormalizer $propertyName = $this->nameConverter->denormalize($propertyName); } - $allowed = false === $allowedAttributes || in_array($propertyName, $allowedAttributes); - $ignored = in_array($propertyName, $this->ignoredAttributes); + $allowed = false === $allowedAttributes || \in_array($propertyName, $allowedAttributes); + $ignored = \in_array($propertyName, $this->ignoredAttributes); if ($allowed && !$ignored && $reflectionClass->hasProperty($propertyName)) { $property = $reflectionClass->getProperty($propertyName); @@ -131,7 +131,7 @@ class PropertyNormalizer extends AbstractNormalizer */ public function supportsNormalization($data, $format = null) { - return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data)); + return \is_object($data) && !$data instanceof \Traversable && $this->supports(\get_class($data)); } /** diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 37b49f3493..34e4193c6a 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -132,7 +132,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz return $data; } - if (is_array($data) || $data instanceof \Traversable) { + if (\is_array($data) || $data instanceof \Traversable) { $normalized = array(); foreach ($data as $key => $val) { $normalized[$key] = $this->normalize($val, $format, $context); @@ -141,12 +141,12 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz return $normalized; } - if (is_object($data)) { + if (\is_object($data)) { if (!$this->normalizers) { throw new LogicException('You must register at least one normalizer to be able to normalize objects.'); } - throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($data))); + throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', \get_class($data))); } throw new UnexpectedValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true)));