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

DefaultDriverFactory::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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