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

AttributeDriver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadMetadataForClass() 0 9 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Metadata\Driver;
6
7
use Metadata\ClassMetadata as BaseClassMetadata;
8
use Metadata\Driver\DriverInterface;
9
use Metadata\MergeableInterface;
10
11
class AttributeDriver implements DriverInterface
12
{
13
    private $annotationDriver;
14
15
    private $decorated;
16
17
    public function __construct(AnnotationDriver $annotationDriver, DriverInterface $decorated)
18
    {
19
        $this->annotationDriver = $annotationDriver;
20
        $this->decorated = $decorated;
21
    }
22
23
    public function loadMetadataForClass(\ReflectionClass $class): ?BaseClassMetadata
24
    {
25
        $metadata = $this->decorated->loadMetadataForClass($class);
26
        $attributeMetadata = !$class->isInternal() ? $this->annotationDriver->loadMetadataForClass($class) : null;
27
        if ($metadata instanceof MergeableInterface && $attributeMetadata instanceof MergeableInterface) {
28
            $metadata->merge($attributeMetadata);
29
        }
30
31
        return $metadata ?: $attributeMetadata;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $metadata ?: $attributeMetadata could return the type Metadata\MergeableInterface which is incompatible with the type-hinted return Metadata\ClassMetadata|null. Consider adding an additional type-check to rule them out.
Loading history...
32
    }
33
}
34