Completed
Pull Request — master (#929)
by Asmir
02:40
created

SerializationGraphNavigatorFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
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
 * Copyright 2016 Johannes M. Schmitt <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace JMS\Serializer\GraphNavigator\Factory;
19
20
use JMS\Serializer\Accessor\AccessorStrategyInterface;
21
use JMS\Serializer\Accessor\DefaultAccessorStrategy;
22
use JMS\Serializer\EventDispatcher\EventDispatcher;
23
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
24
use JMS\Serializer\Expression\ExpressionEvaluatorInterface;
25
use JMS\Serializer\GraphNavigator\SerializationGraphNavigator;
26
use JMS\Serializer\GraphNavigatorInterface;
27
use JMS\Serializer\Handler\HandlerRegistryInterface;
28
use Metadata\MetadataFactoryInterface;
29
30
final class SerializationGraphNavigatorFactory implements GraphNavigatorFactoryInterface
31
{
32
    /**
33
     * @var MetadataFactoryInterface
34
     */
35
    private $metadataFactory;
36
    /**
37
     * @var HandlerRegistryInterface
38
     */
39
    private $handlerRegistry;
40
    /**
41
     * @var AccessorStrategyInterface
42
     */
43
    private $accessor;
44
    /**
45
     * @var EventDispatcherInterface
46
     */
47
    private $dispatcher;
48
    /**
49
     * @var ExpressionEvaluatorInterface
50
     */
51
    private $expressionEvaluator;
52
53 315
    public function __construct(
54
        MetadataFactoryInterface $metadataFactory,
55
        HandlerRegistryInterface $handlerRegistry,
56
        AccessorStrategyInterface $accessor = null,
57
        EventDispatcherInterface $dispatcher = null,
58
        ExpressionEvaluatorInterface $expressionEvaluator = null)
59
    {
60 315
        $this->metadataFactory = $metadataFactory;
61 315
        $this->handlerRegistry = $handlerRegistry;
62 315
        $this->accessor = $accessor ?: new DefaultAccessorStrategy();
63 315
        $this->dispatcher = $dispatcher ?: new EventDispatcher();
64 315
        $this->expressionEvaluator = $expressionEvaluator;
65 315
    }
66
67 273
    public function getGraphNavigator(): GraphNavigatorInterface
68
    {
69 273
        return new SerializationGraphNavigator($this->metadataFactory, $this->handlerRegistry, $this->accessor, $this->dispatcher, $this->expressionEvaluator);
70
    }
71
}
72