Passed
Pull Request — main (#56)
by Niels
01:55
created

ServiceFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
rs 10
c 1
b 0
f 0
eloc 6
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A createSerializer() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the OpenapiBundle package.
7
 *
8
 * (c) Niels Nijens <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Nijens\OpenapiBundle\DependencyInjection;
15
16
use Symfony\Component\Serializer\Serializer;
17
use Traversable;
18
19
/**
20
 * Creates services that can not be created through only service container configuration.
21
 *
22
 * @author Niels Nijens <[email protected]>
23
 */
24
final class ServiceFactory
25
{
26
    public static function createSerializer($normalizers, $encoders): Serializer
27
    {
28
        if ($normalizers instanceof Traversable) {
29
            $normalizers = iterator_to_array($normalizers);
30
        }
31
32
        if ($encoders instanceof Traversable) {
33
            $encoders = iterator_to_array($encoders);
34
        }
35
36
        return new Serializer($normalizers, $encoders);
37
    }
38
}
39