Skip to content

Commit 102f43b

Browse files
MateuszKolankowskitomaszszopinski
authored andcommitted
Refactored SerializerFactory to simplify create method by removing redundant Traversable checks and improving property encapsulation.
1 parent ea49696 commit 102f43b

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

src/bundle/Core/Serializer/SerializerFactory.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace Ibexa\Bundle\Core\Serializer;
1010

1111
use Symfony\Component\Serializer\Serializer;
12-
use Traversable;
1312

1413
final readonly class SerializerFactory
1514
{
@@ -18,21 +17,15 @@
1817
* @param iterable<\Symfony\Component\Serializer\Encoder\EncoderInterface|\Symfony\Component\Serializer\Encoder\DecoderInterface> $encoders
1918
*/
2019
public function __construct(
21-
public iterable $normalizers,
22-
public iterable $encoders
23-
) {}
20+
private iterable $normalizers,
21+
private iterable $encoders
22+
) {
23+
}
2424

2525
public function create(): Serializer
2626
{
27-
$normalizers = $this->normalizers;
28-
if ($normalizers instanceof Traversable) {
29-
$normalizers = iterator_to_array($normalizers);
30-
}
31-
32-
$encoders = $this->encoders;
33-
if ($encoders instanceof Traversable) {
34-
$encoders = iterator_to_array($encoders);
35-
}
27+
$normalizers = iterator_to_array($this->normalizers);
28+
$encoders = iterator_to_array($this->encoders);
3629

3730
return new Serializer($normalizers, $encoders);
3831
}

0 commit comments

Comments
 (0)