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

BuildUpdateForm   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 16 4
A requiresBefore() 0 3 1
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
}