Passed
Branch master (bf85d9)
by Johannes
05:40
created

DefaultDriverFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 7
cts 12
cp 0.5833
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A createDriver() 0 13 2
1
<?php
2
3
namespace JMS\Serializer\Builder;
4
5
use Doctrine\Common\Annotations\Reader;
6
use JMS\Parser\AbstractParser;
7
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
8
use JMS\Serializer\Metadata\Driver\XmlDriver;
9
use JMS\Serializer\Metadata\Driver\YamlDriver;
10
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
11
use JMS\Serializer\TypeParser;
12
use Metadata\Driver\DriverChain;
13
use Metadata\Driver\FileLocator;
14
15
final class DefaultDriverFactory implements DriverFactoryInterface
16
{
17
    private $typeParser;
18
    /**
19
     * @var PropertyNamingStrategyInterface
20
     */
21
    private $propertyNamingStrategy;
22
23 31
    public function __construct(PropertyNamingStrategyInterface $propertyNamingStrategy, AbstractParser $typeParser = null)
24
    {
25 31
        $this->typeParser = $typeParser ?: new TypeParser();
26 31
        $this->propertyNamingStrategy = $propertyNamingStrategy;
27 31
    }
28
29 31
    public function createDriver(array $metadataDirs, Reader $annotationReader)
30
    {
31 31
        if (!empty($metadataDirs)) {
32
            $fileLocator = new FileLocator($metadataDirs);
33
34
            return new DriverChain(array(
35
                new YamlDriver($fileLocator, $this->propertyNamingStrategy, $this->typeParser),
36
                new XmlDriver($fileLocator, $this->propertyNamingStrategy, $this->typeParser),
37
                new AnnotationDriver($annotationReader, $this->propertyNamingStrategy, $this->typeParser),
38
            ));
39
        }
40
41 31
        return new AnnotationDriver($annotationReader, $this->propertyNamingStrategy, $this->typeParser);
42
    }
43
}
44