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

SymfonySerializerFactory::factory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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