SerializationGraphNavigatorFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGraphNavigator() 0 3 1
A __construct() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\GraphNavigator\Factory;
6
7
use JMS\Serializer\Accessor\AccessorStrategyInterface;
8
use JMS\Serializer\Accessor\DefaultAccessorStrategy;
9
use JMS\Serializer\EventDispatcher\EventDispatcher;
10
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
11
use JMS\Serializer\Expression\ExpressionEvaluatorInterface;
12
use JMS\Serializer\GraphNavigator\SerializationGraphNavigator;
13
use JMS\Serializer\GraphNavigatorInterface;
14
use JMS\Serializer\Handler\HandlerRegistryInterface;
15
use Metadata\MetadataFactoryInterface;
16
17
final class SerializationGraphNavigatorFactory implements GraphNavigatorFactoryInterface
18
{
19
    /**
20
     * @var MetadataFactoryInterface
21
     */
22
    private $metadataFactory;
23
    /**
24
     * @var HandlerRegistryInterface
25
     */
26
    private $handlerRegistry;
27
    /**
28
     * @var AccessorStrategyInterface
29
     */
30
    private $accessor;
31
    /**
32
     * @var EventDispatcherInterface
33
     */
34
    private $dispatcher;
35
    /**
36
     * @var ExpressionEvaluatorInterface
37
     */
38 330
    private $expressionEvaluator;
39
40
    public function __construct(
41
        MetadataFactoryInterface $metadataFactory,
42
        HandlerRegistryInterface $handlerRegistry,
43
        ?AccessorStrategyInterface $accessor = null,
44
        ?EventDispatcherInterface $dispatcher = null,
45 330
        ?ExpressionEvaluatorInterface $expressionEvaluator = null
46 330
    ) {
47 330
        $this->metadataFactory = $metadataFactory;
48 330
        $this->handlerRegistry = $handlerRegistry;
49 330
        $this->accessor = $accessor ?: new DefaultAccessorStrategy();
50 330
        $this->dispatcher = $dispatcher ?: new EventDispatcher();
51
        $this->expressionEvaluator = $expressionEvaluator;
52 287
    }
53
54 287
    public function getGraphNavigator(): GraphNavigatorInterface
55
    {
56
        return new SerializationGraphNavigator($this->metadataFactory, $this->handlerRegistry, $this->accessor, $this->dispatcher, $this->expressionEvaluator);
57
    }
58
}
59