Passed
Pull Request — master (#9)
by Iakov
05:06
created

AbstractBuildFormStep   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A __construct() 0 5 1
A getBaseFormBuilder() 0 14 2
1
<?php
2
3
namespace Kami\ApiCoreBundle\RequestProcessor\Step;
4
5
6
use Doctrine\Common\Annotations\Reader;
7
use Doctrine\Common\Util\Inflector;
8
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractStep;
9
use Kami\ApiCoreBundle\Security\AccessManager;
10
use Symfony\Component\Form\Extension\Core\Type\FormType;
11
use Symfony\Component\Form\FormBuilderInterface;
12
use Symfony\Component\Form\FormFactory;
13
use Symfony\Component\Form\FormFactoryInterface;
14
15
abstract class AbstractBuildFormStep extends AbstractStep
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
    /**
33
     * AbstractBuildFormStep constructor.
34
     *
35
     * @param FormFactoryInterface $formFactory
36
     * @param AccessManager $accessManager
37
     * @param Reader $reader
38
     */
39
    public function __construct(FormFactoryInterface $formFactory, AccessManager $accessManager, Reader $reader)
40
    {
41
        $this->formFactory = $formFactory;
0 ignored issues
show
Documentation Bug introduced by
$formFactory is of type Symfony\Component\Form\FormFactoryInterface, but the property $formFactory was declared to be of type Symfony\Component\Form\FormFactory. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
42
        $this->accessManager = $accessManager;
43
        $this->reader = $reader;
44
    }
45
46
    /**
47
     * @return FormBuilderInterface
48
     */
49
    protected function getBaseFormBuilder()
50
    {
51
        $builder = $this->formFactory->createNamedBuilder(
52
            Inflector::tableize($this->getFromResponse('reflection')->getShortName()),
53
            FormType::class,
54
            $this->getFromResponse('entity'),
55
            ['csrf_protection' => false]
56
        );
57
58
        if ('PUT' === $this->request->getMethod()) {
59
            $builder->setMethod('PUT');
60
        }
61
62
        return $builder;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getName()
69
    {
70
        return 'generic_build_form_step';
71
    }
72
}