Completed
Pull Request — master (#80)
by John
03:04
created

SymfonySerializerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 7 2
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace KleijnWeb\SwaggerBundle\Serialize\Serializer\Factory;
9
10
use Symfony\Component\Serializer\Encoder\EncoderInterface;
11
use Symfony\Component\Serializer\Encoder\JsonEncoder;
12
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
13
use Symfony\Component\Serializer\Serializer;
14
15
/**
16
 * Creates a Symfony Serializer with defaults
17
 *
18
 * @author John Kleijn <[email protected]>
19
 */
20
class SymfonySerializerFactory
21
{
22
    /**
23
     * @param EncoderInterface $encoder
24
     *
25
     * @return Serializer
26
     */
27
    public static function factory($encoder = null): Serializer
28
    {
29
        $encoders    = [$encoder ?: new JsonEncoder()];
30
        $normalizers = [new GetSetMethodNormalizer()];
31
32
        return new Serializer($normalizers, $encoders);
33
    }
34
}
35