Conditions | 2 |
Paths | 2 |
Total Lines | 69 |
Code Lines | 44 |
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 |
||
92 | public function browserForm($mids) { |
||
93 | $selection = [ |
||
94 | '#type' => 'container', |
||
95 | '#attributes' => ['id' => 'media-embed-block-browser'], |
||
96 | ]; |
||
97 | |||
98 | $selection['mids'] = [ |
||
99 | '#type' => 'entity_browser', |
||
100 | '#entity_browser' => 'media_browser_in_modal', |
||
101 | '#entity_browser_validators' => [ |
||
102 | 'entity_type' => ['type' => 'media'] |
||
103 | ], |
||
104 | '#process' => [ |
||
105 | [ |
||
106 | '\Drupal\entity_browser\Element\EntityBrowserElement', |
||
107 | 'processEntityBrowser' |
||
108 | ], |
||
109 | [get_called_class(), 'processEntityBrowser'], |
||
110 | ], |
||
111 | ]; |
||
112 | |||
113 | $order_class = 'media-embed-block-delta-order'; |
||
114 | |||
115 | $selection['table'] = [ |
||
116 | '#type' => 'table', |
||
117 | '#header' => [ |
||
118 | t('Title'), |
||
119 | t('Type'), |
||
120 | t('Order', [], ['context' => 'Sort order']), |
||
121 | ], |
||
122 | '#empty' => t('No media yet'), |
||
123 | '#tabledrag' => [ |
||
124 | [ |
||
125 | 'action' => 'order', |
||
126 | 'relationship' => 'sibling', |
||
127 | 'group' => $order_class, |
||
128 | ], |
||
129 | ], |
||
130 | ]; |
||
131 | |||
132 | $delta = 0; |
||
133 | $bundle_info = \Drupal::service('entity_type.bundle.info')->getBundleInfo('media'); |
||
134 | |||
135 | foreach ($mids as $mid) { |
||
136 | /** @var \Drupal\media_entity\Entity\Media $media */ |
||
137 | $media = Media::load($mid); |
||
138 | |||
139 | $selection['table'][$mid] = [ |
||
140 | '#attributes' => [ |
||
141 | 'class' => ['draggable'], |
||
142 | 'data-entity-id' => $media->getEntityTypeId() . ':' . $mid, |
||
143 | ], |
||
144 | 'title' => ['#markup' => $media->label()], |
||
145 | 'type' => ['#markup' => $bundle_info[$media->bundle()]['label']], |
||
146 | '_weight' => [ |
||
147 | '#type' => 'weight', |
||
148 | '#title' => t('Weight for row @number', ['@number' => $delta + 1]), |
||
149 | '#title_display' => 'invisible', |
||
150 | '#delta' => count($mids), |
||
151 | '#default_value' => $delta, |
||
152 | '#attributes' => ['class' => [$order_class]], |
||
153 | ], |
||
154 | ]; |
||
155 | |||
156 | $delta++; |
||
157 | } |
||
158 | |||
159 | return $selection; |
||
160 | } |
||
161 | |||
251 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.