Passed
Pull Request — master (#1332)
by Asmir
02:32
created

AttributeDriverFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createDriver() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Builder;
6
7
use Doctrine\Common\Annotations\Reader;
8
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
9
use JMS\Serializer\Metadata\Driver\AttributeDriver;
10
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
11
use JMS\Serializer\Type\ParserInterface;
12
use Metadata\Driver\DriverInterface;
13
14
class AttributeDriverFactory implements DriverFactoryInterface
15
{
16
    /**
17
     * @var DriverFactoryInterface
18
     */
19
    private $driverFactoryToDecorate;
20
21
    /**
22
     * @var PropertyNamingStrategyInterface
23
     */
24
    private $propertyNamingStrategy;
25
26
    /**
27
     * @var ParserInterface|null
28
     */
29
    private $typeParser;
30
31
    public function __construct(
32
        DriverFactoryInterface $driverFactoryToDecorate,
33
        PropertyNamingStrategyInterface $propertyNamingStrategy,
34
        ?ParserInterface $typeParser = null,
35
    ) {
36
        $this->driverFactoryToDecorate = $driverFactoryToDecorate;
37
        $this->propertyNamingStrategy = $propertyNamingStrategy;
38
        $this->typeParser = $typeParser;
39
    }
40
41
    public function createDriver(array $metadataDirs, Reader $annotationReader): DriverInterface
42
    {
43
        $decoratedDriver = $this->driverFactoryToDecorate->createDriver($metadataDirs, $annotationReader);
44
45
        $attributeAnnotationDriver = new AnnotationDriver(new AttributeDriver\AttributeReader(), $this->propertyNamingStrategy, $this->typeParser);
46
47
        return new AttributeDriver($attributeAnnotationDriver, $decoratedDriver);
48
    }
49
}
50