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

AttributeDriver::loadMetadataForClass()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 9
rs 9.6111
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