Skip to content

Commit a66589c

Browse files
committed
[Serializer] Add more parameter types.
1 parent 4828ff4 commit a66589c

35 files changed

+116
-143
lines changed

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function encode($data, string $format, array $context = [])
102102
/**
103103
* {@inheritdoc}
104104
*/
105-
public function supportsEncoding($format)
105+
public function supportsEncoding(string $format)
106106
{
107107
return self::FORMAT === $format;
108108
}
@@ -184,7 +184,7 @@ public function decode(string $data, string $format, array $context = [])
184184
/**
185185
* {@inheritdoc}
186186
*/
187-
public function supportsDecoding($format)
187+
public function supportsDecoding(string $format)
188188
{
189189
return self::FORMAT === $format;
190190
}

src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(PropertyListExtractorInterface $propertyListExtracto
3030
/**
3131
* {@inheritdoc}
3232
*/
33-
public function getProperties($object, array $context = []): ?array
33+
public function getProperties(object $object, array $context = []): ?array
3434
{
3535
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
3636

src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractorInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ interface ObjectPropertyListExtractorInterface
1919
/**
2020
* Gets the list of properties available for the given object.
2121
*
22-
* @param object $object
23-
*
2422
* @return string[]|null
2523
*/
26-
public function getProperties($object, array $context = []): ?array;
24+
public function getProperties(object $object, array $context = []): ?array;
2725
}

src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getName()
6666
/**
6767
* {@inheritdoc}
6868
*/
69-
public function addGroup($group)
69+
public function addGroup(string $group)
7070
{
7171
if (!\in_array($group, $this->groups)) {
7272
$this->groups[] = $group;
@@ -84,7 +84,7 @@ public function getGroups()
8484
/**
8585
* {@inheritdoc}
8686
*/
87-
public function setMaxDepth($maxDepth)
87+
public function setMaxDepth(?int $maxDepth)
8888
{
8989
$this->maxDepth = $maxDepth;
9090
}

src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait ClassResolverTrait
2525
/**
2626
* Gets a class name for a given class or instance.
2727
*
28-
* @throws InvalidArgumentException If the class does not exists
28+
* @param object|string $value
2929
*/
3030
private function getClass($value): string
3131
{

src/Symfony/Component/Serializer/NameConverter/AdvancedNameConverterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ interface AdvancedNameConverterInterface extends NameConverterInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function normalize($propertyName, string $class = null, string $format = null, array $context = []);
24+
public function normalize(string $propertyName, string $class = null, string $format = null, array $context = []);
2525

2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function denormalize($propertyName, string $class = null, string $format = null, array $context = []);
29+
public function denormalize(string $propertyName, string $class = null, string $format = null, array $context = []);
3030
}

src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(ClassMetadataFactoryInterface $metadataFactory, Name
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function normalize($propertyName, string $class = null, string $format = null, array $context = []): string
43+
public function normalize(string $propertyName, string $class = null, string $format = null, array $context = []): string
4444
{
4545
if (null === $class) {
4646
return $this->normalizeFallback($propertyName, $class, $format, $context);
@@ -56,7 +56,7 @@ public function normalize($propertyName, string $class = null, string $format =
5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function denormalize($propertyName, string $class = null, string $format = null, array $context = []): string
59+
public function denormalize(string $propertyName, string $class = null, string $format = null, array $context = []): string
6060
{
6161
if (null === $class) {
6262
return $this->denormalizeFallback($propertyName, $class, $format, $context);

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,11 @@ public function hasCacheableSupportsMethod(): bool
170170
/**
171171
* Detects if the configured circular reference limit is reached.
172172
*
173-
* @param object $object
174-
* @param array $context
175-
*
176173
* @return bool
177174
*
178175
* @throws CircularReferenceException
179176
*/
180-
protected function isCircularReference($object, &$context)
177+
protected function isCircularReference(object $object, array &$context)
181178
{
182179
$objectHash = spl_object_hash($object);
183180

@@ -229,7 +226,7 @@ protected function handleCircularReference(object $object, string $format = null
229226
*
230227
* @return string[]|AttributeMetadataInterface[]|bool
231228
*/
232-
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
229+
protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false)
233230
{
234231
$allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
235232
if (!$this->classMetadataFactory) {
@@ -265,12 +262,10 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
265262
* Is this attribute allowed?
266263
*
267264
* @param object|string $classOrObject
268-
* @param string $attribute
269-
* @param string|null $format
270265
*
271266
* @return bool
272267
*/
273-
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = [])
268+
protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = [])
274269
{
275270
$ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES];
276271
if (\in_array($attribute, $ignoredAttributes)) {
@@ -307,12 +302,11 @@ protected function prepareForDenormalization($data)
307302
* Returns the method to use to construct an object. This method must be either
308303
* the object constructor or static.
309304
*
310-
* @param string $class
311305
* @param array|bool $allowedAttributes
312306
*
313307
* @return \ReflectionMethod|null
314308
*/
315-
protected function getConstructor(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
309+
protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
316310
{
317311
return $reflectionClass->getConstructor();
318312
}
@@ -325,15 +319,14 @@ protected function getConstructor(array &$data, $class, array &$context, \Reflec
325319
* is removed from the context before being returned to avoid side effects
326320
* when recursively normalizing an object graph.
327321
*
328-
* @param string $class
329322
* @param array|bool $allowedAttributes
330323
*
331324
* @return object
332325
*
333326
* @throws RuntimeException
334327
* @throws MissingConstructorArgumentsException
335328
*/
336-
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
329+
protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
337330
{
338331
if (null !== $object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE)) {
339332
unset($context[self::OBJECT_TO_POPULATE]);
@@ -408,7 +401,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
408401
/**
409402
* @internal
410403
*/
411-
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
404+
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
412405
{
413406
try {
414407
if (null !== $parameter->getClass()) {

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function normalize($object, string $format = null, array $context = [])
211211
/**
212212
* {@inheritdoc}
213213
*/
214-
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
214+
protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
215215
{
216216
if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForClass($class)) {
217217
if (!isset($data[$mapping->getTypeProperty()])) {
@@ -272,33 +272,29 @@ protected function getAttributes($object, string $format = null, array $context)
272272
/**
273273
* Extracts attributes to normalize from the class of the given object, format and context.
274274
*
275-
* @param object $object
276-
*
277275
* @return string[]
278276
*/
279-
abstract protected function extractAttributes($object, string $format = null, array $context = []);
277+
abstract protected function extractAttributes(object $object, string $format = null, array $context = []);
280278

281279
/**
282280
* Gets the attribute value.
283281
*
284-
* @param object $object
285-
*
286282
* @return mixed
287283
*/
288-
abstract protected function getAttributeValue($object, string $attribute, string $format = null, array $context = []);
284+
abstract protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []);
289285

290286
/**
291287
* {@inheritdoc}
292288
*/
293-
public function supportsDenormalization($data, $type, string $format = null)
289+
public function supportsDenormalization($data, string $type, string $format = null)
294290
{
295291
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
296292
}
297293

298294
/**
299295
* {@inheritdoc}
300296
*/
301-
public function denormalize($data, $class, string $format = null, array $context = [])
297+
public function denormalize($data, string $class, string $format = null, array $context = [])
302298
{
303299
if (!isset($context['cache_key'])) {
304300
$context['cache_key'] = $this->getCacheKey($format, $context);
@@ -349,13 +345,8 @@ public function denormalize($data, $class, string $format = null, array $context
349345

350346
/**
351347
* Sets attribute value.
352-
*
353-
* @param object $object
354-
* @param string $attribute
355-
* @param mixed $value
356-
* @param string|null $format
357348
*/
358-
abstract protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = []);
349+
abstract protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []);
359350

360351
/**
361352
* Validates the submitted data and denormalizes it.
@@ -435,7 +426,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
435426
/**
436427
* @internal
437428
*/
438-
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
429+
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
439430
{
440431
if (null === $this->propertyTypeExtractor || null === $types = $this->propertyTypeExtractor->getTypes($class->getName(), $parameterName)) {
441432
return parent::denormalizeParameter($class, $parameter, $parameterName, $parameterData, $context, $format);

src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Serializer
3636
*
3737
* @throws NotNormalizableValueException
3838
*/
39-
public function denormalize($data, $class, $format = null, array $context = [])
39+
public function denormalize($data, string $class, string $format = null, array $context = [])
4040
{
4141
if (null === $this->serializer) {
4242
throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
@@ -66,7 +66,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
6666
/**
6767
* {@inheritdoc}
6868
*/
69-
public function supportsDenormalization($data, $type, $format = null, array $context = [])
69+
public function supportsDenormalization($data, string $type, string $format = null, array $context = [])
7070
{
7171
return '[]' === substr($type, -2)
7272
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy