Completed
Push — master ( 0eab77...b2f729 )
by Paul
05:35
created

AdditionnalPropertiesType   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 5
dl 0
loc 64
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C buildForm() 0 41 8
A configureOptions() 0 8 1
1
<?php
2
3
namespace Victoire\Bundle\CoreBundle\Form;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
7
use Symfony\Component\Form\Extension\Core\Type\TextType;
8
use Symfony\Component\Form\FormBuilderInterface;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIBusinessEntity;
11
12
/**
13
 * Create an entity proxy for the widget.*.
14
 */
15
class AdditionnalPropertiesType extends AbstractType
16
{
17
    /**
18
     * define form fields.
19
     *
20
     * @param FormBuilderInterface $builder
21
     * @param array                $options
22
     */
23
    public function buildForm(FormBuilderInterface $builder, array $options)
24
    {
25
        $matches = [];
26
        /** @var APIBusinessEntity $businessEntity */
27
        $businessEntity = $options['businessEntity'];
28
        $getMethod = $businessEntity->getGetMethod();
29
        preg_match_all('/{{([a-zA-Z]+)}}/', $getMethod, $matches);
30
        $identifiers = array_map(function ($property) {
31
            return $property->getName();
32
        },
33
            $businessEntity->getBusinessIdentifiers()->toArray()
34
        );
35
        foreach ($matches[1] as $match) {
36
            if (!in_array($match, $identifiers)) {
37
                if ($property = $businessEntity->getBusinessPropertyByName($match)) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $property is correct as $businessEntity->getBusi...sPropertyByName($match) (which targets Victoire\Bundle\Business...usinessPropertyByName()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
38
                    if (!$property->getChoices() && !$property->getListMethod()) {
39
                        $builder->add(
40
                            $match,
41
                            TextType::class,
42
                            [
43
                                'label'    => false,
44
                                'required' => false,
45
                            ]
46
                        );
47
                    } elseif ($property->getListMethod()) {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
48
                        //TODO
49
                    } elseif ($choices = $property->getChoices()) {
50
                        $builder->add(
51
                            $match,
52
                            ChoiceType::class,
53
                            [
54
                                'choices'  => $choices,
55
                                'label'    => false,
56
                                'required' => false,
57
                            ]
58
                        );
59
                    }
60
                }
61
            }
62
        }
63
    }
64
65
    /**
66
     * bind to Menu entity.
67
     *
68
     * @param OptionsResolver $resolver
69
     */
70
    public function configureOptions(OptionsResolver $resolver)
71
    {
72
        $resolver->setDefaults(
73
            [
74
                'businessEntity' => null,
75
            ]
76
        );
77
    }
78
}
79