SerializerFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.3755

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 4
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 11
cp 0.5455
crap 2.3755
1
<?php declare(strict_types = 1);
2
3
namespace Simplex\Quickstart\Shared\Factory;
4
5
use Hateoas\Hateoas;
6
use Hateoas\HateoasBuilder;
7
use Hateoas\UrlGenerator\SymfonyUrlGenerator;
8
use Symfony\Component\Routing\Generator\UrlGenerator;
9
10
final class SerializerFactory
11
{
12
    private const SERIALIZER_CACHE_DIR = DIRECTORY_SEPARATOR . 'serializer';
13
14
    /**
15
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
16
     */
17 1
    public function create(
18
        UrlGenerator $urlGenerator,
19
        bool $enableCache,
20
        \SplFileInfo $cacheDir,
21
        bool $debugMode
22
    ): Hateoas {
23
24 1
        if ($enableCache) {
25
            return HateoasBuilder::create()
26
                ->setUrlGenerator(null, new SymfonyUrlGenerator($urlGenerator))
27
                ->setCacheDir($cacheDir->getPathname() . self::SERIALIZER_CACHE_DIR)
28
                ->setDebug($debugMode)
29
                ->build();
30
        }
31
32 1
        return HateoasBuilder::create()
33 1
            ->setUrlGenerator(null, new SymfonyUrlGenerator($urlGenerator))
34 1
            ->setDebug($debugMode)
35 1
            ->build();
36
    }
37
}
38