Completed
Push — 1.x ( 8bcf66...54c417 )
by Marko
03:54
created

FormReader::configureFields()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 5
nc 4
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\Reader;
6
7
use KunicMarko\SonataAnnotationBundle\Annotation\FormField;
8
use Sonata\AdminBundle\Form\FormMapper;
9
10
/**
11
 * @author Marko Kunic <[email protected]>
12
 */
13
class FormReader
14
{
15
    use AnnotationReaderTrait;
16
17
    public function configureCreateFields(\ReflectionClass $class, FormMapper $formMapper): void
18
    {
19
        $this->configureFields($class, $formMapper, FormField::ACTION_EDIT);
20
    }
21
22
    private function configureFields(\ReflectionClass $class, FormMapper $formMapper, string $action): void
23
    {
24
        foreach ($class->getProperties() as $property) {
25
            foreach ($this->getPropertyAnnotations($property) as $annotation) {
26
                if (!$annotation instanceof FormField || $annotation->action === $action) {
27
                    continue;
28
                }
29
30
                $formMapper->add($property->getName(), ...$annotation->getSettings());
0 ignored issues
show
Bug introduced by
$annotation->getSettings() is expanded, but the parameter $type of Sonata\AdminBundle\Form\FormMapper::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

30
                $formMapper->add($property->getName(), /** @scrutinizer ignore-type */ ...$annotation->getSettings());
Loading history...
31
            }
32
        }
33
    }
34
35
    public function configureEditFields(\ReflectionClass $class, FormMapper $formMapper): void
36
    {
37
        $this->configureFields($class, $formMapper, FormField::ACTION_CREATE);
38
    }
39
}
40