From fbc635ff573b961d5452314249d51ec710b7d3e4 Mon Sep 17 00:00:00 2001 From: Danny van Wijk Date: Sat, 11 Dec 2021 15:53:19 +0100 Subject: [PATCH] Fix DataTransformer --- .../CollectionToStringTransformer.php | 10 +++++----- .../DataTransformer/RecursiveTransformer.php | 16 ++++++++-------- .../ResourceToIdentifierTransformer.php | 9 ++++++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php b/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php index 06b1849cb..68aaee00a 100644 --- a/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php +++ b/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php @@ -27,23 +27,23 @@ public function __construct(string $delimiter) $this->delimiter = $delimiter; } - public function transform($values): string + public function transform($value): string { - if (!($values instanceof Collection)) { + if (!($value instanceof Collection)) { throw new TransformationFailedException( sprintf( 'Expected "%s", but got "%s"', Collection::class, - is_object($values) ? get_class($values) : gettype($values) + is_object($value) ? get_class($value) : gettype($value) ) ); } - if ($values->isEmpty()) { + if ($value->isEmpty()) { return ''; } - return implode($this->delimiter, $values->toArray()); + return implode($this->delimiter, $value->toArray()); } public function reverseTransform($value): Collection diff --git a/src/Bundle/Form/DataTransformer/RecursiveTransformer.php b/src/Bundle/Form/DataTransformer/RecursiveTransformer.php index 8147c36de..9e7f187cb 100644 --- a/src/Bundle/Form/DataTransformer/RecursiveTransformer.php +++ b/src/Bundle/Form/DataTransformer/RecursiveTransformer.php @@ -27,15 +27,15 @@ public function __construct(DataTransformerInterface $decoratedTransformer) $this->decoratedTransformer = $decoratedTransformer; } - public function transform($values): Collection + public function transform($value): Collection { - if (null === $values) { + if (null === $value) { return new ArrayCollection(); } - $this->assertTransformationValueType($values, Collection::class); + $this->assertTransformationValueType($value, Collection::class); - return $values->map( + return $value->map( /** * @param mixed $value * @@ -47,15 +47,15 @@ function ($value) { ); } - public function reverseTransform($values): Collection + public function reverseTransform($value): Collection { - if (null === $values) { + if (null === $value) { return new ArrayCollection(); } - $this->assertTransformationValueType($values, Collection::class); + $this->assertTransformationValueType($value, Collection::class); - return $values->map( + return $value->map( /** * @param mixed $value * diff --git a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php index 6ecc9ba6d..4df887eb1 100644 --- a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php +++ b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php @@ -25,15 +25,15 @@ final class ResourceToIdentifierTransformer implements DataTransformerInterface private string $identifier; - /** - * @param string $identifier - */ public function __construct(RepositoryInterface $repository, ?string $identifier = null) { $this->repository = $repository; $this->identifier = $identifier ?? 'id'; } + /** + * @return string|null + */ public function transform($value) { if (null === $value) { @@ -46,6 +46,9 @@ public function transform($value) return PropertyAccess::createPropertyAccessor()->getValue($value, $this->identifier); } + /** + * @return object|null + */ public function reverseTransform($value) { if (null === $value) {