NormalizerFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getNormalizer() 0 12 4
1
<?php
2
3
/**
4
 * This file is part of the bugloos/error-response-bundle project.
5
 * (c) Bugloos <https://bugloos.com/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Bugloos\ErrorResponseBundle\Factory;
11
12
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
13
14
/**
15
 * @author Mojtaba Gheytasi <[email protected]>
16
 */
17
class NormalizerFactory
18
{
19
    private iterable $normalizers;
20
21
    public function __construct($normalizers)
22
    {
23
        $this->normalizers = $normalizers;
24
    }
25
26
    public function getNormalizer($data): ?NormalizerInterface
27
    {
28
        foreach ($this->normalizers as $normalizer) {
29
            if (
30
                $normalizer instanceof NormalizerInterface
31
                && $normalizer->supportsNormalization($data)
32
            ) {
33
                return $normalizer;
34
            }
35
        }
36
37
        return null;
38
    }
39
}
40