From fbe6c5010b85a7beaa680dc9709d225056fba009 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Wed, 31 Jan 2024 23:57:36 +0700 Subject: [PATCH] refactor(`ArrayLikeTransformerTrait`): Cleanup. --- CHANGELOG.md | 1 + .../Trait/ArrayLikeTransformerTrait.php | 25 ++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 542d2b25..b658f3ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * refactor(`ArrayLikeMetadata`): Add `$type`. * refactor(`PropertyMapping`): Add `$sourceTypes`. * refactor(`TraversableToArrayAccessTransformer`): Refactor for clarity. +* refactor(`ArrayLikeTransformerTrait`): Cleanup. ## 0.5.22 diff --git a/src/Transformer/Trait/ArrayLikeTransformerTrait.php b/src/Transformer/Trait/ArrayLikeTransformerTrait.php index 2642fd26..2fc71349 100644 --- a/src/Transformer/Trait/ArrayLikeTransformerTrait.php +++ b/src/Transformer/Trait/ArrayLikeTransformerTrait.php @@ -44,7 +44,11 @@ private function transformTraversableSource( * @var mixed $sourceMemberValue */ foreach ($source as $sourceMemberKey => $sourceMemberValue) { - $result = $this->transformMember( + /** + * @var mixed $key + * @var mixed $value + */ + [$key, $value] = $this->transformMember( counter: $i, sourceMemberKey: $sourceMemberKey, sourceMemberValue: $sourceMemberValue, @@ -53,7 +57,7 @@ private function transformTraversableSource( context: $context, ); - yield $result['key'] => $result['value']; + yield $key => $value; $i++; } @@ -61,7 +65,7 @@ private function transformTraversableSource( /** * @param null|\ArrayAccess|array $target - * @return array{key:mixed,value:mixed} + * @return array{0:mixed,1:mixed} */ private function transformMember( mixed $sourceMemberKey, @@ -165,10 +169,7 @@ private function transformMember( // the target value if ($targetMetadata->memberValueIsUntyped()) { - return [ - 'key' => $targetMemberKey, - 'value' => $sourceMemberValue, - ]; + return [$targetMemberKey, $sourceMemberValue]; } // if the target value types has a type compatible with the source @@ -176,10 +177,7 @@ private function transformMember( foreach ($targetMetadata->getMemberValueTypes() as $memberValueType) { if (TypeCheck::isVariableInstanceOf($sourceMemberValue, $memberValueType)) { - return [ - 'key' => $targetMemberKey, - 'value' => $sourceMemberValue, - ]; + return [$targetMemberKey, $sourceMemberValue]; } } @@ -219,9 +217,6 @@ private function transformMember( path: $path, ); - return [ - 'key' => $targetMemberKey, - 'value' => $targetMemberValue, - ]; + return [$targetMemberKey, $targetMemberValue]; } }