Skip to content

Commit 052f76b

Browse files
committed
style: cs fixes
1 parent 7ff051f commit 052f76b

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

AbstractItemNormalizer.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
226226
} catch (ItemNotFoundException $e) {
227227
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
228228
} catch (InvalidArgumentException $e) {
229-
throw new UnexpectedValueException(sprintf('Invalid IRI "%s".', $data), $e->getCode(), $e);
229+
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $data), $e->getCode(), $e);
230230
}
231231
}
232232

233233
if (!\is_array($data)) {
234-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" resource must be "array" (nested document) or "string" (IRI), "%s" given.', $resourceClass, \gettype($data)), $data, [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null);
234+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" resource must be "array" (nested document) or "string" (IRI), "%s" given.', $resourceClass, \gettype($data)), $data, [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null);
235235
}
236236

237237
$previousObject = $this->clone($objectToPopulate);
@@ -304,7 +304,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
304304
if ($constructorParameter->isVariadic()) {
305305
if ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {
306306
if (!\is_array($data[$paramName])) {
307-
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));
307+
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));
308308
}
309309

310310
$params[] = $data[$paramName];
@@ -332,13 +332,13 @@ protected function instantiateObject(array &$data, string $class, array &$contex
332332
$missingConstructorArguments[] = $constructorParameter->name;
333333
}
334334

335-
$exception = NotNormalizableValueException::createForUnexpectedDataType(sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name), $data, ['unknown'], $context['deserialization_path'] ?? null, true);
335+
$exception = NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name), $data, ['unknown'], $context['deserialization_path'] ?? null, true);
336336
$context['not_normalizable_value_exceptions'][] = $exception;
337337
}
338338
}
339339

340340
if ($missingConstructorArguments) {
341-
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments, $class);
341+
throw new MissingConstructorArgumentsException(\sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments, $class);
342342
}
343343

344344
if (\count($context['not_normalizable_value_exceptions'] ?? []) > 0) {
@@ -362,12 +362,12 @@ protected function getClassDiscriminatorResolvedClass(array $data, string $class
362362
}
363363

364364
if (!isset($data[$mapping->getTypeProperty()])) {
365-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class), null, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty());
365+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class), null, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty());
366366
}
367367

368368
$type = $data[$mapping->getTypeProperty()];
369369
if (null === ($mappedClass = $mapping->getClassForType($type))) {
370-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type "%s" is not a valid value.', $type), $type, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
370+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type "%s" is not a valid value.', $type), $type, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
371371
}
372372

373373
return $mappedClass;
@@ -503,7 +503,7 @@ protected function validateType(string $attribute, Type $type, mixed $value, ?st
503503
}
504504

505505
if (!$isValid) {
506-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, \gettype($value)), $value, [$builtinType], $context['deserialization_path'] ?? null);
506+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, \gettype($value)), $value, [$builtinType], $context['deserialization_path'] ?? null);
507507
}
508508
}
509509

@@ -515,7 +515,7 @@ protected function validateType(string $attribute, Type $type, mixed $value, ?st
515515
protected function denormalizeCollection(string $attribute, ApiProperty $propertyMetadata, Type $type, string $className, mixed $value, ?string $format, array $context): array
516516
{
517517
if (!\is_array($value)) {
518-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value)), $value, [Type::BUILTIN_TYPE_ARRAY], $context['deserialization_path'] ?? null);
518+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value)), $value, [Type::BUILTIN_TYPE_ARRAY], $context['deserialization_path'] ?? null);
519519
}
520520

521521
$values = [];
@@ -538,7 +538,7 @@ protected function denormalizeCollection(string $attribute, ApiProperty $propert
538538
$values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $childContext);
539539
continue 2;
540540
}
541-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the key "%s" must be "%s", "%s" given.', $index, $collectionKeyTypes[0]->getBuiltinType(), \gettype($index)), $index, [$collectionKeyTypes[0]->getBuiltinType()], ($context['deserialization_path'] ?? false) ? sprintf('key(%s)', $context['deserialization_path']) : null, true);
541+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the key "%s" must be "%s", "%s" given.', $index, $collectionKeyTypes[0]->getBuiltinType(), \gettype($index)), $index, [$collectionKeyTypes[0]->getBuiltinType()], ($context['deserialization_path'] ?? false) ? \sprintf('key(%s)', $context['deserialization_path']) : null, true);
542542
}
543543

544544
return $values;
@@ -573,7 +573,7 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
573573
return null;
574574
} catch (InvalidArgumentException $e) {
575575
if (!isset($context['not_normalizable_value_exceptions'])) {
576-
throw new UnexpectedValueException(sprintf('Invalid IRI "%s".', $value), $e->getCode(), $e);
576+
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $value), $e->getCode(), $e);
577577
}
578578
$context['not_normalizable_value_exceptions'][] = NotNormalizableValueException::createForUnexpectedDataType(
579579
$e->getMessage(),
@@ -593,7 +593,7 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
593593
$context['api_allow_update'] = true;
594594

595595
if (!$this->serializer instanceof DenormalizerInterface) {
596-
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
596+
throw new LogicException(\sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
597597
}
598598

599599
$item = $this->serializer->denormalize($value, $className, $format, $context);
@@ -605,10 +605,10 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
605605
}
606606

607607
if (!\is_array($value)) {
608-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute must be "array" (nested document) or "string" (IRI), "%s" given.', $attributeName, \gettype($value)), $value, [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
608+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute must be "array" (nested document) or "string" (IRI), "%s" given.', $attributeName, \gettype($value)), $value, [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
609609
}
610610

611-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Nested documents for attribute "%s" are not allowed. Use IRIs instead.', $attributeName), $value, [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
611+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Nested documents for attribute "%s" are not allowed. Use IRIs instead.', $attributeName), $value, [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
612612
}
613613

614614
/**
@@ -732,7 +732,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
732732
}
733733

734734
if (!$this->serializer instanceof NormalizerInterface) {
735-
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
735+
throw new LogicException(\sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
736736
}
737737

738738
unset(
@@ -766,7 +766,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
766766
}
767767

768768
if (!$this->serializer instanceof NormalizerInterface) {
769-
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
769+
throw new LogicException(\sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
770770
}
771771

772772
unset(
@@ -816,7 +816,7 @@ protected function normalizeRelation(ApiProperty $propertyMetadata, ?object $rel
816816
{
817817
if (null === $relatedObject || !empty($context['attributes']) || $propertyMetadata->isReadableLink()) {
818818
if (!$this->serializer instanceof NormalizerInterface) {
819-
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
819+
throw new LogicException(\sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
820820
}
821821

822822
$relatedContext = $this->createOperationContext($context, $resourceClass);
@@ -911,7 +911,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
911911
&& \is_array($value)
912912
) {
913913
if (!$this->serializer instanceof DenormalizerInterface) {
914-
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
914+
throw new LogicException(\sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
915915
}
916916

917917
unset($context['resource_class'], $context['uri_variables']);
@@ -921,7 +921,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
921921

922922
if (null !== $className = $type->getClassName()) {
923923
if (!$this->serializer instanceof DenormalizerInterface) {
924-
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
924+
throw new LogicException(\sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
925925
}
926926

927927
unset($context['resource_class'], $context['uri_variables']);
@@ -950,7 +950,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
950950
if ($isMultipleTypes) {
951951
break 2;
952952
}
953-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be bool ("%s" given).', $attribute, $className, $value), $value, [Type::BUILTIN_TYPE_BOOL], $context['deserialization_path'] ?? null);
953+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be bool ("%s" given).', $attribute, $className, $value), $value, [Type::BUILTIN_TYPE_BOOL], $context['deserialization_path'] ?? null);
954954
}
955955
break;
956956
case Type::BUILTIN_TYPE_INT:
@@ -961,7 +961,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
961961
if ($isMultipleTypes) {
962962
break 2;
963963
}
964-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be int ("%s" given).', $attribute, $className, $value), $value, [Type::BUILTIN_TYPE_INT], $context['deserialization_path'] ?? null);
964+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be int ("%s" given).', $attribute, $className, $value), $value, [Type::BUILTIN_TYPE_INT], $context['deserialization_path'] ?? null);
965965
}
966966
break;
967967
case Type::BUILTIN_TYPE_FLOAT:
@@ -981,7 +981,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
981981
if ($isMultipleTypes) {
982982
break 3;
983983
}
984-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be float ("%s" given).', $attribute, $className, $value), $value, [Type::BUILTIN_TYPE_FLOAT], $context['deserialization_path'] ?? null);
984+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" attribute for class "%s" must be float ("%s" given).', $attribute, $className, $value), $value, [Type::BUILTIN_TYPE_FLOAT], $context['deserialization_path'] ?? null);
985985
}
986986
}
987987
}

Filter/PropertyFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function apply(Request $request, bool $normalization, array $attributes,
158158
*/
159159
public function getDescription(string $resourceClass): array
160160
{
161-
$example = sprintf('%1$s[]={propertyName}&%1$s[]={anotherPropertyName}&%1$s[{nestedPropertyParent}][]={nestedProperty}',
161+
$example = \sprintf('%1$s[]={propertyName}&%1$s[]={anotherPropertyName}&%1$s[{nestedPropertyParent}][]={nestedProperty}',
162162
$this->parameterName
163163
);
164164

Tests/AbstractItemNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ public function testCacheKey(): void
13411341
]));
13421342

13431343
$operationCacheKey = (new \ReflectionClass($normalizer))->getProperty('localFactoryOptionsCache')->getValue($normalizer);
1344-
$this->assertEquals(array_keys($operationCacheKey), [sprintf('%s%s%s%s', Dummy::class, 'operation_name', 'root_operation_name', 'n')]);
1344+
$this->assertEquals(array_keys($operationCacheKey), [\sprintf('%s%s%s%s', Dummy::class, 'operation_name', 'root_operation_name', 'n')]);
13451345
$this->assertEquals(current($operationCacheKey), ['serializer_groups' => ['group']]);
13461346
}
13471347
}

0 commit comments

Comments
 (0)