Completed
Push — master ( baff27...3a9c47 )
by Daniel
02:56
created

SerializerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Config;
9
10
use Interop\Container\ContainerInterface;
11
use Interop\Container\Exception\ContainerException;
12
use Symfony\Component\Serializer\Encoder\JsonEncoder;
13
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
14
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
15
use Zend\ServiceManager\Exception\ServiceNotFoundException;
16
use Zend\ServiceManager\Factory\FactoryInterface;
17
18
/**
19
 * Config serializer factory class.
20
 *
21
 * @package GravityMedia\Commander\Serializer
22
 */
23
class SerializerFactory implements FactoryInterface
24
{
25
    /**
26
     * Create config serializer object.
27
     *
28
     * @param  ContainerInterface $container
29
     * @param  string             $requestedName
30
     * @param  null|array         $options
31
     *
32
     * @return Serializer
33
     *
34
     * @throws ServiceNotFoundException if unable to resolve the service.
35
     * @throws ServiceNotCreatedException if an exception is raised when creating a service.
36
     * @throws ContainerException if any other error occurs
37
     */
38 2
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
39
    {
40 2
        $normalizers = [new GetSetMethodNormalizer()];
41 2
        $encoders = [new JsonEncoder()];
42
43 2
        return new Serializer($normalizers, $encoders);
44
    }
45
}
46