SerializerFactory::createSerializer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Syncer\Factory;
4
5
use JMS\Serializer\Serializer;
6
use JMS\Serializer\SerializerBuilder;
7
8
/**
9
 * Class SerializerFactory
10
 * @package Syncer\Factory
11
 *
12
 * @author Matthieu Calie <[email protected]>
13
 */
14
class SerializerFactory
15
{
16
    /**
17
     * @var bool
18
     */
19
    private $debug;
20
21
    /**
22
     * @var string
23
     */
24
    private $configDir;
25
26
    /**
27
     * @var string
28
     */
29
    private $cacheDir;
30
31
    /**
32
     * SerializerFactory constructor.
33
     *
34
     * @param bool $debug
35
     * @param string $configDir
36
     * @param string $cacheDir
37
     */
38
    public function __construct(bool $debug, string $configDir, string $cacheDir)
39
    {
40
        $this->debug = $debug;
41
        $this->configDir = $configDir;
42
        $this->cacheDir = $cacheDir;
43
    }
44
45
    /**
46
     * @return Serializer
47
     */
48
    public function createSerializer(): Serializer
49
    {
50
        return SerializerBuilder::create()
51
            ->addMetadataDir($this->configDir, 'Syncer\Dto')
52
            ->setCacheDir($this->cacheDir)
53
            ->setDebug($this->debug)
54
            ->build();
55
    }
56
}
57