Passed
Branch request-processor (31ada2)
by Iakov
02:59
created

BuildUpdateForm::execute()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 0
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
4
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Update;
5
6
7
use Kami\ApiCoreBundle\Annotation\Form;
8
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractBuildFormStep;
9
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetReflectionFromRequestStep;
10
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateResourceAccessStep;
11
12
class BuildUpdateForm extends AbstractBuildFormStep
13
{
14
    public function execute()
15
    {
16
        $builder = $this->getBaseFormBuilder();
17
        /** @var \ReflectionClass $reflection */
18
        $reflection = $this->getFromResponse('reflection');
19
20
        foreach ($reflection->getProperties() as $property) {
21
            if ($this->accessManager->canUpdateProperty($property)) {
22
                if($annotation = $this->reader->getPropertyAnnotation($property, Form::class)) {
23
                    $builder->add($property->getName(), $annotation->type, $annotation->options);
24
                }
25
                $builder->add($property->getName());
26
            }
27
        }
28
29
        return $this->createResponse(['form' => $builder->getForm()]);
30
    }
31
32
    public function requiresBefore()
33
    {
34
        return [GetReflectionFromRequestStep::class, ValidateResourceAccessStep::class];
35
    }
36
37
}