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

AbstractReader::__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 Sonata\AdminBundle\Mapper\BaseMapper;
9
10
/**
11
 * @author Marko Kunic <[email protected]>
12
 */
13
abstract class AbstractReader
14
{
15
    use AnnotationReaderTrait;
16
17
    public function configureFields(\ReflectionClass $class, BaseMapper $baseMapper): void
18
    {
19
        $this->addPropertiesToMapper(
20
            $this->findProperties($class),
21
            $baseMapper
22
        );
23
    }
24
25
    protected function findProperties(\ReflectionClass $class): array
26
    {
27
        $properties = [];
28
29
        foreach ($class->getProperties() as $property) {
30
            if ($annotation = $this->getPropertyAnnotation($property, $this->getAnnotation())) {
31
                $properties[$property->getName()] = $annotation;
32
            }
33
        }
34
35
        return $properties;
36
    }
37
38
    protected function addPropertiesToMapper(array $properties, BaseMapper $baseMapper): void
39
    {
40
        foreach ($properties as $name => $annotation) {
41
            $baseMapper->add($name, ...$annotation->getSettings());
0 ignored issues
show
Bug introduced by
The method add() does not exist on Sonata\AdminBundle\Mapper\BaseMapper. It seems like you code against a sub-type of said class. However, the method does not exist in Sonata\AdminBundle\Mapper\BaseGroupedMapper. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
            $baseMapper->/** @scrutinizer ignore-call */ 
42
                         add($name, ...$annotation->getSettings());
Loading history...
42
        }
43
    }
44
45
    abstract protected function getAnnotation(): string;
46
}
47