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

BuildCreateFormStep::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
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Create;
4
5
use Doctrine\Common\Annotations\Reader;
6
use Kami\ApiCoreBundle\Annotation\Form;
7
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractBuildFormStep;
8
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetEntityFromReflectionStep;
0 ignored issues
show
Bug introduced by
The type Kami\ApiCoreBundle\Reque...ntityFromReflectionStep was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetReflectionFromRequestStep;
10
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateResourceAccessStep;
11
use Kami\ApiCoreBundle\Security\AccessManager;
12
use Symfony\Component\Form\FormFactory;
13
14
15
class BuildCreateFormStep extends AbstractBuildFormStep
16
{
17
    /**
18
     * @var FormFactory
19
     */
20
    protected $formFactory;
21
22
    /**
23
     * @var AccessManager
24
     */
25
    protected $accessManager;
26
27
    /**
28
     * @var Reader
29
     */
30
    protected $reader;
31
32
    public function execute()
33
    {
34
        $builder = $this->getBaseFormBuilder();
35
        /** @var \ReflectionClass $reflection */
36
        $reflection = $this->getFromResponse('reflection');
37
38
        foreach ($reflection->getProperties() as $property) {
39
            if ($this->accessManager->canCreateProperty($property)) {
40
                if($annotation = $this->reader->getPropertyAnnotation($property, Form::class)) {
41
                    $builder->add($property->getName(), $annotation->type, $annotation->options);
42
                }
43
                $builder->add($property->getName());
44
            }
45
        }
46
47
        return $this->createResponse(['form' => $builder->getForm()]);
48
    }
49
50
51
    public function requiresBefore()
52
    {
53
        return [
54
            ValidateResourceAccessStep::class,
55
            GetEntityFromReflectionStep::class,
56
            GetReflectionFromRequestStep::class
57
        ];
58
    }
59
}