Completed
Push — 1.x ( d1a99d...be31ef )
by Marko
02:10
created

DatagridReader::configureFields()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 9
nc 5
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\Reader;
6
7
use KunicMarko\SonataAnnotationBundle\Annotation\DatagridAssociationField;
8
use KunicMarko\SonataAnnotationBundle\Annotation\DatagridField;
9
use Sonata\AdminBundle\Datagrid\DatagridMapper;
10
11
/**
12
 * @author Marko Kunic <[email protected]>
13
 */
14
class DatagridReader
15
{
16
    use AnnotationReaderTrait;
17
18
    public function configureFields(\ReflectionClass $class, DatagridMapper $datagridMapper): void
19
    {
20
        foreach ($class->getProperties() as $property) {
21
            foreach ($this->getPropertyAnnotations($property) as $annotation) {
22
                if ($annotation instanceof DatagridAssociationField) {
23
                    $datagridMapper->add(
24
                        $property->getName() . '.' . $annotation->field,
25
                        ...$annotation->getSettings()
0 ignored issues
show
Bug introduced by
$annotation->getSettings() is expanded, but the parameter $type of Sonata\AdminBundle\Datagrid\DatagridMapper::add() does not expect variable arguments. ( Ignorable by Annotation )

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

25
                        /** @scrutinizer ignore-type */ ...$annotation->getSettings()
Loading history...
26
                    );
27
28
                    continue;
29
                }
30
31
                if ($annotation instanceof DatagridField) {
32
                    $datagridMapper->add($property->getName(), ...$annotation->getSettings());
33
                }
34
            }
35
        }
36
    }
37
}
38