| Conditions | 4 |
| Paths | 8 |
| Total Lines | 70 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 67 | public function buildForm(array $form, FormStateInterface $form_state) { |
||
| 68 | /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */ |
||
| 69 | $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser']; |
||
| 70 | |||
| 71 | $widgets = []; |
||
| 72 | foreach ($this->widgetManager->getDefinitions() as $plugin_id => $plugin_definition) { |
||
| 73 | $widgets[$plugin_id] = $plugin_definition['label']; |
||
| 74 | } |
||
| 75 | $default_widgets = []; |
||
| 76 | foreach ($entity_browser->getWidgets() as $widget) { |
||
| 77 | /** @var \Drupal\entity_browser\WidgetInterface $widget */ |
||
| 78 | $default_widgets[] = $widget->id(); |
||
| 79 | } |
||
| 80 | $form['widget'] = [ |
||
| 81 | '#type' => 'select', |
||
| 82 | '#title' => $this->t('Add widget plugin'), |
||
| 83 | '#options' => ['_none_' => '- ' . $this->t('Select a widget to add it') . ' -'] + $widgets, |
||
| 84 | '#ajax' => [ |
||
| 85 | 'callback' => [get_class($this), 'addWidgetCallback'], |
||
| 86 | 'wrapper' => 'widgets', |
||
| 87 | ], |
||
| 88 | '#executes_submit_callback' => TRUE, |
||
| 89 | '#submit' => [[get_class($this), 'submitAddWidget']], |
||
| 90 | '#limit_validation_errors' => [['widget']], |
||
| 91 | ]; |
||
| 92 | $form_state->unsetValue('widget'); |
||
| 93 | |||
| 94 | $form['widgets'] = [ |
||
| 95 | '#type' => 'table', |
||
| 96 | '#header' => [ |
||
| 97 | $this->t('Form'), |
||
| 98 | $this->t('Operations'), |
||
| 99 | $this->t('Weight'), |
||
| 100 | ], |
||
| 101 | '#empty' => $this->t('There are no widgets.'), |
||
| 102 | '#tabledrag' => [[ |
||
| 103 | 'action' => 'order', |
||
| 104 | 'relationship' => 'sibling', |
||
| 105 | 'group' => 'variant-weight', |
||
| 106 | ]], |
||
| 107 | ]; |
||
| 108 | |||
| 109 | /** @var \Drupal\entity_browser\WidgetInterface $widget */ |
||
| 110 | foreach ($entity_browser->getWidgets() as $widget) { |
||
| 111 | $row = [ |
||
| 112 | '#attributes' => [ |
||
| 113 | 'class' => ['draggable'], |
||
| 114 | ], |
||
| 115 | ]; |
||
| 116 | $row['label'] = [ |
||
| 117 | '#type' => 'textfield', |
||
| 118 | '#default_value' => $widget->label(), |
||
| 119 | '#title' => $this->t('Label'), |
||
| 120 | ]; |
||
| 121 | $row['form'] = []; |
||
| 122 | $row['form'] = $widget->buildConfigurationForm($row['form'], $form_state); |
||
| 123 | $row['operations'] = []; |
||
| 124 | $row['weight'] = [ |
||
| 125 | '#type' => 'weight', |
||
| 126 | '#default_value' => $widget->getWeight(), |
||
| 127 | '#title' => $this->t('Weight for @widget widget', ['@widget' => $widget->label()]), |
||
| 128 | '#title_display' => 'invisible', |
||
| 129 | '#attributes' => [ |
||
| 130 | 'class' => ['variant-weight'], |
||
| 131 | ], |
||
| 132 | ]; |
||
| 133 | $form['widgets'][$widget->uuid()] = $row; |
||
| 134 | } |
||
| 135 | return $form; |
||
| 136 | } |
||
| 137 | |||
| 185 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.