| Conditions | 15 |
| Paths | 102 |
| Total Lines | 59 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 4 |
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 |
||
| 113 | public function createBuilder($key, $data = [], $options = [], $name = null) |
||
| 114 | { |
||
| 115 | if (!isset($this->configuration[$key])) { |
||
| 116 | throw new NonExistentFormException(sprintf('The form "%s" was not found.', $key)); |
||
| 117 | } |
||
| 118 | |||
| 119 | $formBuilder = $this->formFactory->createNamedBuilder($name ?: $key, 'form', $data, $options); |
||
| 120 | |||
| 121 | if (isset($this->eventSubscribers[$key])) { |
||
| 122 | foreach ($this->eventSubscribers[$key] as $eventSubscriber) { |
||
| 123 | $formBuilder->addEventSubscriber($eventSubscriber); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | foreach ($this->configuration[$key] as $key => $fieldConfiguration) { |
||
| 128 | if (!$fieldConfiguration['enabled']) { |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | |||
| 132 | $fieldOptions = isset($fieldConfiguration['options']) ? $fieldConfiguration['options'] : []; |
||
| 133 | |||
| 134 | if (isset($fieldConfiguration['data_provider'])) { |
||
| 135 | $fieldOptions['choices'] = $this->loadDataProvider($fieldConfiguration['data_provider'])->getData(); |
||
| 136 | } |
||
| 137 | |||
| 138 | if (isset($fieldConfiguration['help_message_provider'])) { |
||
| 139 | $fieldOptions['help'] = $this->loadHelpMessageProvider($fieldConfiguration['help_message_provider'])->getHelpMessage($fieldOptions['help']); |
||
| 140 | } |
||
| 141 | |||
| 142 | if (isset($fieldConfiguration['validation'])) { |
||
| 143 | $constraints = []; |
||
| 144 | |||
| 145 | foreach ($fieldConfiguration['validation'] as $validatorName => $options) { |
||
| 146 | $constraints[] = new $validatorName($options); |
||
| 147 | } |
||
| 148 | |||
| 149 | $fieldOptions['constraints'] = $constraints; |
||
| 150 | } |
||
| 151 | |||
| 152 | $field = $formBuilder->create($key, $fieldConfiguration['type'], $fieldOptions); |
||
| 153 | |||
| 154 | if (isset($fieldConfiguration['transformer'])) { |
||
| 155 | $transformerConfiguration = $fieldConfiguration['transformer']; |
||
| 156 | $transformer = new $transformerConfiguration['class'](); |
||
| 157 | |||
| 158 | if (isset($transformerConfiguration['calls'])) { |
||
| 159 | foreach ($transformerConfiguration['calls'] as $call) { |
||
| 160 | call_user_func([$transformer, $call[0]], $call[1]); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | $field->addModelTransformer($transformer); |
||
| 165 | } |
||
| 166 | |||
| 167 | $formBuilder->add($field); |
||
| 168 | } |
||
| 169 | |||
| 170 | return $formBuilder; |
||
| 171 | } |
||
| 172 | |||
| 237 |