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

ExportReader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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