Completed
Push — master ( d62d29...27939e )
by Marko
02:28
created

ExportReader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormats() 0 7 2
A getFields() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\Reader;
6
7
use Doctrine\Common\Annotations\Reader;
8
use KunicMarko\SonataAnnotationBundle\Annotation\ExportField;
9
use KunicMarko\SonataAnnotationBundle\Annotation\ExportFormats;
10
11
/**
12
 * @author Marko Kunic <[email protected]>
13
 */
14
class ExportReader
15
{
16
    use AnnotationReaderTrait;
17
18
    public function getFields(\ReflectionClass $class): array
19
    {
20
        $properties = [];
21
22
        foreach ($class->getProperties() as $property) {
23
            if ($annotation = $this->getPropertyAnnotation($property, ExportField::class)) {
24
                $properties[$annotation->label ?? $property->getName()] = $property->getName();
0 ignored issues
show
Bug introduced by
Accessing label on the interface KunicMarko\SonataAnnotat...ion\AnnotationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
25
            }
26
        }
27
28
        return $properties;
29
    }
30
31
    public function getFormats(\ReflectionClass $class): array
32
    {
33
        if ($annotation = $this->getClassAnnotation($class, ExportFormats::class)) {
34
            return $annotation->formats;
0 ignored issues
show
Bug introduced by
Accessing formats on the interface KunicMarko\SonataAnnotat...ion\AnnotationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
35
        }
36
37
        return [];
38
    }
39
}
40