From 5be84c4bf05c84bbe6d5091d11fa5d799cd64bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 2 Oct 2014 19:46:25 +0200 Subject: [PATCH] [Serializer] Fix CS. Uniformize PHPDoc. --- .../Serializer/Encoder/ChainDecoder.php | 1 + .../Serializer/Encoder/ChainEncoder.php | 1 + .../Serializer/Encoder/DecoderInterface.php | 8 ++-- .../Serializer/Encoder/EncoderInterface.php | 10 ++--- .../Serializer/Encoder/JsonDecode.php | 4 +- .../Serializer/Encoder/JsonEncode.php | 7 ++-- .../Serializer/Encoder/JsonEncoder.php | 4 +- .../Encoder/NormalizationAwareInterface.php | 2 +- .../Encoder/SerializerAwareEncoder.php | 2 +- .../Serializer/Encoder/XmlEncoder.php | 21 ++++++---- .../Normalizer/DenormalizableInterface.php | 12 +++--- .../Normalizer/DenormalizerInterface.php | 10 ++--- .../Normalizer/GetSetMethodNormalizer.php | 15 +++---- .../Normalizer/NormalizableInterface.php | 12 +++--- .../Normalizer/NormalizerInterface.php | 10 ++--- .../Normalizer/PropertyNormalizer.php | 4 +- .../Normalizer/SerializerAwareNormalizer.php | 2 +- .../Component/Serializer/Serializer.php | 41 +++++++++++++------ .../Serializer/SerializerAwareInterface.php | 4 +- .../Serializer/SerializerInterface.php | 4 +- 20 files changed, 99 insertions(+), 75 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php index 5321a234057ec..f8f17b4f723e6 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php @@ -58,6 +58,7 @@ public function supportsDecoding($format) * @param string $format * * @return DecoderInterface + * * @throws RuntimeException if no decoder is found */ private function getDecoder($format) diff --git a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php index 43dfa00118914..5ee352ab27932 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php @@ -80,6 +80,7 @@ public function needsNormalization($format) * @param string $format * * @return EncoderInterface + * * @throws RuntimeException if no encoder is found */ private function getEncoder($format) diff --git a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php index 34e21bc0e3bee..683da5bec92a7 100644 --- a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php @@ -14,7 +14,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** - * Defines the interface of decoders + * Defines the interface of decoders. * * @author Jordi Boggiano */ @@ -23,9 +23,9 @@ interface DecoderInterface /** * Decodes a string into PHP data. * - * @param scalar $data Data to decode - * @param string $format Format name - * @param array $context options that decoders have access to. + * @param scalar $data Data to decode + * @param string $format Format name + * @param array $context options that decoders have access to. * * The format parameter specifies which format the data is in; valid values * depend on the specific implementation. Authors implementing this interface diff --git a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php index 394df9999fb2d..fe7e777daad32 100644 --- a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php @@ -14,17 +14,17 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** - * Defines the interface of encoders + * Defines the interface of encoders. * * @author Jordi Boggiano */ interface EncoderInterface { /** - * Encodes data into the given format + * Encodes data into the given format. * - * @param mixed $data Data to encode - * @param string $format Format name + * @param mixed $data Data to encode + * @param string $format Format name * @param array $context options that normalizers/encoders have access to. * * @return scalar @@ -34,7 +34,7 @@ interface EncoderInterface public function encode($data, $format, array $context = array()); /** - * Checks whether the serializer can encode to given format + * Checks whether the serializer can encode to given format. * * @param string $format format name * diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index afb4e3ec84332..a1a8e7cab2ffa 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -41,8 +41,8 @@ class JsonDecode implements DecoderInterface /** * Constructs a new JsonDecode instance. * - * @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy - * @param int $depth Specifies the recursion depth + * @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy + * @param int $depth Specifies the recursion depth */ public function __construct($associative = false, $depth = 512) { diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 8b468bd14a874..931a0556c6ccf 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -14,7 +14,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** - * Encodes JSON data + * Encodes JSON data. * * @author Sander Coolen */ @@ -43,7 +43,7 @@ public function getLastError() } /** - * Encodes PHP data to a JSON string + * Encodes PHP data to a JSON string. * * {@inheritdoc} */ @@ -71,7 +71,8 @@ public function supportsEncoding($format) /** * Merge default json encode options with context. * - * @param array $context + * @param array $context + * * @return array */ private function resolveContext(array $context = array()) diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index 9137c926b30d9..df22316ff703d 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php @@ -37,7 +37,7 @@ public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodin } /** - * Returns the last encoding error (if any) + * Returns the last encoding error (if any). * * @return int * @@ -49,7 +49,7 @@ public function getLastEncodingError() } /** - * Returns the last decoding error (if any) + * Returns the last decoding error (if any). * * @return int * diff --git a/src/Symfony/Component/Serializer/Encoder/NormalizationAwareInterface.php b/src/Symfony/Component/Serializer/Encoder/NormalizationAwareInterface.php index 8101332e5ba15..c066bd7cdd1bb 100644 --- a/src/Symfony/Component/Serializer/Encoder/NormalizationAwareInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/NormalizationAwareInterface.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Serializer\Encoder; /** - * Defines the interface of encoders that will normalize data themselves + * Defines the interface of encoders that will normalize data themselves. * * Implementing this interface essentially just tells the Serializer that the * data should not be pre-normalized before being passed to this Encoder. diff --git a/src/Symfony/Component/Serializer/Encoder/SerializerAwareEncoder.php b/src/Symfony/Component/Serializer/Encoder/SerializerAwareEncoder.php index 80bbb23d75ec1..a3d8ff38c347d 100644 --- a/src/Symfony/Component/Serializer/Encoder/SerializerAwareEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/SerializerAwareEncoder.php @@ -15,7 +15,7 @@ use Symfony\Component\Serializer\SerializerAwareInterface; /** - * SerializerAware Encoder implementation + * SerializerAware Encoder implementation. * * @author Jordi Boggiano */ diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index a0222522041a7..709b8b65c3ad9 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -14,7 +14,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** - * Encodes XML data + * Encodes XML data. * * @author Jordi Boggiano * @author John Wards @@ -146,7 +146,7 @@ public function supportsDecoding($format) } /** - * Sets the root node name + * Sets the root node name. * * @param string $name root node name */ @@ -156,7 +156,8 @@ public function setRootNodeName($name) } /** - * Returns the root node name + * Returns the root node name. + * * @return string */ public function getRootNodeName() @@ -229,7 +230,7 @@ final protected function appendDocumentFragment(\DOMNode $node, $fragment) } /** - * Checks the name is a valid xml element name + * Checks the name is a valid xml element name. * * @param string $name * @@ -279,7 +280,7 @@ private function parseXml(\DOMNode $node) } /** - * Parse the input DOMNode attributes into an array + * Parse the input DOMNode attributes into an array. * * @param \DOMNode $node xml to parse * @@ -305,7 +306,7 @@ private function parseXmlAttributes(\DOMNode $node) } /** - * Parse the input DOMNode value (content and children) into an array or a string + * Parse the input DOMNode value (content and children) into an array or a string. * * @param \DOMNode $node xml to parse * @@ -347,7 +348,7 @@ private function parseXmlValue(\DOMNode $node) } /** - * Parse the data and convert it to DOMElements + * Parse the data and convert it to DOMElements. * * @param \DOMNode $parentNode * @param array|object $data @@ -452,7 +453,7 @@ private function needsCdataWrapping($val) } /** - * Tests the value being passed and decide what sort of element to create + * Tests the value being passed and decide what sort of element to create. * * @param \DOMNode $node * @param mixed $val @@ -488,6 +489,10 @@ private function selectNodeType(\DOMNode $node, $val) /** * Get real XML root node name, taking serializer options into account. + * + * @param array $context + * + * @return string */ private function resolveXmlRootName(array $context = array()) { diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php index 5a1b4c196b594..419d793f50950 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Serializer\Normalizer; /** - * Defines the most basic interface a class must implement to be denormalizable + * Defines the most basic interface a class must implement to be denormalizable. * * If a denormalizer is registered for the class and it doesn't implement * the Denormalizable interfaces, the normalizer will be used instead @@ -28,11 +28,11 @@ interface DenormalizableInterface * recursively all child objects of the implementor. * * @param DenormalizerInterface $denormalizer The denormalizer is given so that you - * can use it to denormalize objects contained within this object. - * @param array|scalar $data The data from which to re-create the object. - * @param string|null $format The format is optionally given to be able to denormalize differently - * based on different input formats. - * @param array $context options for denormalizing + * can use it to denormalize objects contained within this object. + * @param array|scalar $data The data from which to re-create the object. + * @param string|null $format The format is optionally given to be able to denormalize differently + * based on different input formats. + * @param array $context options for denormalizing. */ public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = array()); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php index 001dd6863dcf6..8b6c2333958fe 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php @@ -19,11 +19,11 @@ interface DenormalizerInterface { /** - * Denormalizes data back into an object of the given class + * 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 $format format the given data was extracted from + * @param mixed $data data to restore + * @param string $class the expected class to instantiate + * @param string $format format the given data was extracted from * @param array $context options available to the denormalizer * * @return object @@ -31,7 +31,7 @@ interface DenormalizerInterface public function denormalize($data, $class, $format = null, array $context = array()); /** - * Checks whether the given class is supported for denormalization by this normalizer + * Checks whether the given class is supported for denormalization by this normalizer. * * @param mixed $data Data to denormalize from. * @param string $type The class to which the data should be denormalized. diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index f4a1b9094bbdd..aab7db12e2636 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -47,7 +47,7 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer implements Normal * * @throws InvalidArgumentException if a non-callable callback is set * - * @return GetSetMethodNormalizer + * @return self */ public function setCallbacks(array $callbacks) { @@ -62,11 +62,11 @@ public function setCallbacks(array $callbacks) } /** - * Set ignored attributes for normalization + * Set ignored attributes for normalization. * * @param array $ignoredAttributes * - * @return GetSetMethodNormalizer + * @return self */ public function setIgnoredAttributes(array $ignoredAttributes) { @@ -76,11 +76,11 @@ public function setIgnoredAttributes(array $ignoredAttributes) } /** - * Set attributes to be camelized on denormalize + * Set attributes to be camelized on denormalize. * * @param array $camelizedAttributes * - * @return GetSetMethodNormalizer + * @return self */ public function setCamelizedAttributes(array $camelizedAttributes) { @@ -185,9 +185,10 @@ public function denormalize($data, $class, $format = null, array $context = arra /** * Format attribute name to access parameters or methods * As option, if attribute name is found on camelizedAttributes array - * returns attribute name in camelcase format + * returns attribute name in camelcase format. + * + * @param string $attributeName * - * @param string $attributeName * @return string */ protected function formatAttribute($attributeName) diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php index 07c3a4a8dd8e8..e19fe5ce58576 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php @@ -12,10 +12,10 @@ namespace Symfony\Component\Serializer\Normalizer; /** - * Defines the most basic interface a class must implement to be normalizable + * Defines the most basic interface a class must implement to be normalizable. * * If a normalizer is registered for the class and it doesn't implement - * the Normalizable interfaces, the normalizer will be used instead + * the Normalizable interfaces, the normalizer will be used instead. * * @author Jordi Boggiano */ @@ -28,10 +28,10 @@ interface NormalizableInterface * recursively all child objects of the implementor. * * @param NormalizerInterface $normalizer The normalizer is given so that you - * can use it to normalize objects contained within this object. - * @param string|null $format The format is optionally given to be able to normalize differently - * based on different output formats. - * @param array $context Options for normalizing this object + * can use it to normalize objects contained within this object. + * @param string|null $format The format is optionally given to be able to normalize differently + * based on different output formats. + * @param array $context Options for normalizing this object * * @return array|scalar */ diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index 22a95438a098e..f4bd355232b0b 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -19,18 +19,18 @@ interface NormalizerInterface { /** - * Normalizes an object into a set of arrays/scalars + * Normalizes an object into a set of arrays/scalars. * - * @param object $object object to normalize - * @param string $format format the normalization result will be encoded as - * @param array $context Context options for the normalizer + * @param object $object object to normalize + * @param string $format format the normalization result will be encoded as + * @param array $context Context options for the normalizer * * @return array|scalar */ public function normalize($object, $format = null, array $context = array()); /** - * Checks whether the given class is supported for normalization by this normalizer + * Checks whether the given class is supported for normalization by this normalizer. * * @param mixed $data Data to normalize. * @param string $format The format being (de-)serialized from or into. diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index 9eefff3ca81b5..a6bc44384093b 100644 --- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php @@ -57,7 +57,7 @@ public function setCallbacks(array $callbacks) } /** - * Set ignored attributes for normalization + * Set ignored attributes for normalization. * * @param array $ignoredAttributes */ @@ -180,7 +180,7 @@ public function supportsDenormalization($data, $type, $format = null) /** * Format an attribute name, for example to convert a snake_case name to camelCase. * - * @param string $attributeName + * @param string $attributeName * @return string */ protected function formatAttribute($attributeName) diff --git a/src/Symfony/Component/Serializer/Normalizer/SerializerAwareNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/SerializerAwareNormalizer.php index 49916bef4c657..395685707405c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/SerializerAwareNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/SerializerAwareNormalizer.php @@ -15,7 +15,7 @@ use Symfony\Component\Serializer\SerializerAwareInterface; /** - * SerializerAware Normalizer implementation + * SerializerAware Normalizer implementation. * * @author Jordi Boggiano */ diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index c4052bcbcc5ee..358a3f8531f2f 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -21,10 +21,10 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** - * Serializer serializes and deserializes data + * Serializer serializes and deserializes data. * - * objects are turned into arrays by normalizers - * arrays are turned into various output formats by encoders + * objects are turned into arrays by normalizers. + * arrays are turned into various output formats by encoders. * * $serializer->serialize($obj, 'xml') * $serializer->decode($data, 'xml') @@ -36,10 +36,25 @@ */ class Serializer implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface { + /** + * @var Encoder\ChainEncoder + */ protected $encoder; + /** + * @var Encoder\ChainDecoder + */ protected $decoder; + /** + * @var array + */ protected $normalizers = array(); + /** + * @var array + */ protected $normalizerCache = array(); + /** + * @var array + */ protected $denormalizerCache = array(); public function __construct(array $normalizers = array(), array $encoders = array()) @@ -157,7 +172,7 @@ public function supportsDenormalization($data, $type, $format = null) /** * Returns a matching normalizer. * - * @param object $data The object to get the serializer for + * @param object $data The object to get the serializer for * @param string $format format name, present to give the option to normalizers to act differently based on formats * * @return NormalizerInterface|null @@ -219,11 +234,11 @@ final public function decode($data, $format, array $context = array()) } /** - * Normalizes an object into a set of arrays/scalars + * Normalizes an object into a set of arrays/scalars. * - * @param object $object object to normalize - * @param string $format format name, present to give the option to normalizers to act differently based on formats - * @param array $context The context data for this particular normalization + * @param object $object object to normalize + * @param string $format format name, present to give the option to normalizers to act differently based on formats + * @param array $context The context data for this particular normalization * * @return array|scalar * @@ -243,12 +258,12 @@ private function normalizeObject($object, $format, array $context = array()) } /** - * Denormalizes data back into an object of the given class + * 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 $format format name, present to give the option to normalizers to act differently based on formats - * @param array $context The context data for this particular denormalization + * @param mixed $data data to restore + * @param string $class the expected class to instantiate + * @param string $format format name, present to give the option to normalizers to act differently based on formats + * @param array $context The context data for this particular denormalization * * @return object * diff --git a/src/Symfony/Component/Serializer/SerializerAwareInterface.php b/src/Symfony/Component/Serializer/SerializerAwareInterface.php index ad0b768ccc8a2..dd0a62e7fa887 100644 --- a/src/Symfony/Component/Serializer/SerializerAwareInterface.php +++ b/src/Symfony/Component/Serializer/SerializerAwareInterface.php @@ -12,14 +12,14 @@ namespace Symfony\Component\Serializer; /** - * Defines the interface of encoders + * Defines the interface of encoders. * * @author Jordi Boggiano */ interface SerializerAwareInterface { /** - * Sets the owning Serializer object + * Sets the owning Serializer object. * * @param SerializerInterface $serializer */ diff --git a/src/Symfony/Component/Serializer/SerializerInterface.php b/src/Symfony/Component/Serializer/SerializerInterface.php index d196d780a95be..c79db91892075 100644 --- a/src/Symfony/Component/Serializer/SerializerInterface.php +++ b/src/Symfony/Component/Serializer/SerializerInterface.php @@ -12,14 +12,14 @@ namespace Symfony\Component\Serializer; /** - * Defines the interface of the Serializer + * Defines the interface of the Serializer. * * @author Jordi Boggiano */ interface SerializerInterface { /** - * Serializes data in the appropriate format + * Serializes data in the appropriate format. * * @param mixed $data any data * @param string $format format name