| Conditions | 8 |
| Paths | 128 |
| Total Lines | 62 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 11 | function df_tools_media_acquiadam_modules_installed($modules) { |
||
| 12 | $config_factory = \Drupal::configFactory(); |
||
| 13 | |||
| 14 | // Adds Acquia DAM to article images. |
||
| 15 | if (in_array('df_tools_articles', $modules)) { |
||
| 16 | $config_factory |
||
| 17 | ->getEditable('field.field.node.article.field_image') |
||
| 18 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 19 | ->save(TRUE); |
||
| 20 | } |
||
| 21 | |||
| 22 | // Adds Acquia DAM to hero images. |
||
| 23 | if (in_array('df_tools_blocks', $modules)) { |
||
| 24 | $config_factory |
||
| 25 | ->getEditable('field.field.block_content.hero.field_hero_background') |
||
| 26 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 27 | ->save(TRUE); |
||
| 28 | } |
||
| 29 | |||
| 30 | // Adds Acquia DAM to event images. |
||
| 31 | if (in_array('df_tools_events', $modules)) { |
||
| 32 | $config_factory |
||
| 33 | ->getEditable('field.field.node.event.field_image') |
||
| 34 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 35 | ->save(TRUE); |
||
| 36 | } |
||
| 37 | |||
| 38 | // Adds Acquia DAM to location images. |
||
| 39 | if (in_array('df_tools_locations', $modules)) { |
||
| 40 | $config_factory |
||
| 41 | ->getEditable('field.field.node.location.field_image') |
||
| 42 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 43 | ->save(TRUE); |
||
| 44 | } |
||
| 45 | |||
| 46 | // Adds Acquia DAM to page images. |
||
| 47 | if (in_array('df_tools_page', $modules)) { |
||
| 48 | $config_factory |
||
| 49 | ->getEditable('field.field.node.page.field_image') |
||
| 50 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 51 | ->save(TRUE); |
||
| 52 | } |
||
| 53 | |||
| 54 | // Adds Acquia DAM to person images. |
||
| 55 | if (in_array('df_tools_person', $modules)) { |
||
| 56 | $config_factory |
||
| 57 | ->getEditable('field.field.node.person.field_image') |
||
| 58 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 59 | ->save(TRUE); |
||
| 60 | } |
||
| 61 | |||
| 62 | // Adds Acquia DAM to product images. |
||
| 63 | if (in_array('acf_product', $modules)) { |
||
| 64 | $config_factory |
||
| 65 | ->getEditable('field.field.node.product.field_product_image') |
||
| 66 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 67 | ->save(TRUE); |
||
| 68 | |||
| 69 | $config_factory |
||
| 70 | ->getEditable('field.field.node.product.field_product_image_more') |
||
| 71 | ->set('settings.handler_settings.target_bundles.acquia_dam_asset', 'acquia_dam_asset') |
||
| 72 | ->save(TRUE); |
||
| 73 | } |
||
| 75 |