Test Failed
Push — main ( 33bb6d...d24563 )
by Vasil
03:10
created

SerializerFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace VasilDakov\Econt\Serializer;
4
5
use JMS\Serializer;
6
use JMS\Serializer\SerializationContext;
7
use JMS\Serializer\SerializerInterface;
8
use VasilDakov\Econt\Exception\ServiceNotCreatedException;
9
10
class SerializerFactory
11
{
12
    /**
13
     * @return SerializerInterface
14
     */
15
    public function __invoke(): SerializerInterface
16
    {
17
        try {
18
            return Serializer\SerializerBuilder::create()
19
                ->setPropertyNamingStrategy(
20
                    new Serializer\Naming\SerializedNameAnnotationStrategy(
21
                        new Serializer\Naming\IdenticalPropertyNamingStrategy()
22
                    )
23
                )
24
                ->setSerializationContextFactory(function () {
25
                    return SerializationContext::create()
26
                        ->setSerializeNull(true);
27
                })
28
                ->build()
29
                ;
30
            // @codeCoverageIgnoreStart
31
        } catch (\Throwable $e) {
32
            throw new ServiceNotCreatedException();
33
        }
34
        // @codeCoverageIgnoreEnd
35
    }
36
}
37