Conditions | 11 |
Paths | 24 |
Total Lines | 50 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
51 | public function buildForEntityAndWidgetType(&$builder, $widgetName, $businessEntity) |
||
52 | { |
||
53 | //Try to add a new form for each entity with the correct annotation and business properties |
||
54 | $rawBusinessProperties = $this->businessPropertyRepository->getByBusinessEntity($businessEntity)->run(); |
||
55 | $businessProperties = []; |
||
56 | foreach ($rawBusinessProperties as $businessProperty) { |
||
57 | foreach ($businessProperty->getTypes() as $type) { |
||
58 | $businessProperties[$type][] = $businessProperty; |
||
59 | } |
||
60 | } |
||
61 | $receiverPropertiesTypes = $this->cacheReader->getReceiverProperties($widgetName); |
||
62 | |||
63 | if (!empty($receiverPropertiesTypes)) { |
||
64 | foreach ($receiverPropertiesTypes as $type => $receiverProperties) { |
||
65 | /* @var \Victoire\Bundle\BusinessEntityBundle\Entity\ReceiverProperty[] $receiverProperties */ |
||
66 | foreach ($receiverProperties as $receiverProperty) { |
||
67 | |||
68 | //Check if entity has all the required receiver properties as business properties |
||
69 | if (isset($businessProperties[$type]) && is_array($businessProperties[$type]) && count($businessProperties[$type])) { |
||
70 | |||
71 | //Create form types with field as key and values as choices |
||
72 | //TODO Add some formatter Class or a buildField method responsible to create this type |
||
73 | $label = $this->translator->trans( |
||
74 | 'widget_'.strtolower($widgetName).'.form.'.$receiverProperty->getFieldName().'.label', |
||
75 | [], |
||
76 | 'victoire' |
||
77 | ); |
||
78 | $choices = []; |
||
79 | foreach ($businessProperties[$type] as $choice) { |
||
80 | $choices[$choice->getName()] = $choice->getName(); |
||
81 | } |
||
82 | |||
83 | $options = [ |
||
84 | 'choices' => $choices, |
||
85 | 'label' => $label, |
||
86 | 'attr' => [ |
||
87 | 'title' => $label, |
||
88 | ], |
||
89 | ]; |
||
90 | |||
91 | if (!$receiverProperty->isRequired()) { |
||
92 | $options = array_merge(['required' => false], $options); |
||
93 | } |
||
94 | |||
95 | $builder->add($receiverProperty->getFieldName(), ChoiceType::class, $options); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..