| Conditions | 23 |
| Paths | 13 |
| Total Lines | 106 |
| Code Lines | 67 |
| 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 |
||
| 33 | function drush_df_tools_config_df_cex() { |
||
| 34 | global $config_directories; |
||
| 35 | |||
| 36 | // Allow user to choose the destination. |
||
| 37 | $choices = drush_map_assoc(array_keys($config_directories)); |
||
| 38 | unset($choices[CONFIG_ACTIVE_DIRECTORY]); |
||
| 39 | if (count($choices) >= 2) { |
||
| 40 | $destination = drush_choice($choices, dt('Choose a destination.')); |
||
| 41 | if (empty($destination)) { |
||
| 42 | return drush_user_abort(); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | elseif (!isset($destination)) { |
||
| 46 | $destination = CONFIG_SYNC_DIRECTORY; |
||
| 47 | } |
||
| 48 | $destination_dir = config_get_config_directory($destination); |
||
| 49 | |||
| 50 | $change_list = _df_tools_config_get_change_list($destination_dir); |
||
| 51 | // Return early if there are no pending changes. |
||
| 52 | if (empty($change_list)) { |
||
| 53 | return TRUE; |
||
| 54 | } |
||
| 55 | |||
| 56 | // Initiate the normal export routines. |
||
| 57 | $result = _drush_config_export(NULL, $destination_dir, NULL); |
||
| 58 | |||
| 59 | // If config was exported by _drush_config_export(), cycle through the config |
||
| 60 | // CRUD operations and attempt to automatically update config. |
||
| 61 | if ($result) { |
||
| 62 | $storage_filters = drush_config_get_storage_filters(); |
||
| 63 | $destination_storage = new FileStorage($destination_dir); |
||
| 64 | // If there are any filters, then attach them to the destination storage |
||
| 65 | if (!empty($storage_filters)) { |
||
| 66 | $destination_storage = new StorageWrapper($destination_storage, $storage_filters); |
||
| 67 | } |
||
| 68 | |||
| 69 | foreach ($change_list as $type => $list) { |
||
| 70 | switch ($type) { |
||
| 71 | case 'create': |
||
| 72 | foreach ($list as $config) { |
||
| 73 | $input = drush_prompt(dt('Enter destination module for new config @config, or "none" to skip', ['@config' => $config])); |
||
| 74 | if ($input == 'none') { |
||
| 75 | continue; |
||
| 76 | } |
||
| 77 | try { |
||
| 78 | $module_info = \Drupal::moduleHandler()->getModule($input); |
||
| 79 | $destination_dir = DRUPAL_ROOT . '/' . $module_info->getPath() . '/config/install/'; |
||
| 80 | $source = DRUPAL_ROOT . '/' . $destination_storage->getFilePath($config); |
||
| 81 | // Create /config/install directory if it does not exist. |
||
| 82 | if (!file_exists($destination_dir)) { |
||
| 83 | mkdir($destination_dir, 0755, true); |
||
| 84 | } |
||
| 85 | $destination = $destination_dir . basename($source); |
||
| 86 | if (!copy($source, $destination)) { |
||
| 87 | drush_log(dt('New copy from @source to @destination failed.', ['@source' => $source, '@destination' => $destination]), LogLevel::ERROR); |
||
| 88 | } |
||
| 89 | else { |
||
| 90 | _df_tools_config_strip_uuid($destination); |
||
| 91 | drush_log(dt('Successfully created @config.', ['@config' => $config]), LogLevel::OK); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | catch (InvalidArgumentException $e) { |
||
| 95 | drush_log(dt('Module @input does not exist or is not enabled.', ['@input' => $input]), LogLevel::ERROR); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | break; |
||
| 99 | case 'update': |
||
| 100 | foreach ($list as $config) { |
||
| 101 | $source = DRUPAL_ROOT . '/' . $destination_storage->getFilePath($config); |
||
| 102 | |||
| 103 | $instances = _df_tools_config_find_config_instances($destination_storage, $config); |
||
| 104 | $choice = drush_choice($instances, dt('Choose update destination for @config.', ['@config' => $config])); |
||
| 105 | if ($choice !== FALSE) { |
||
| 106 | $destination = $instances[$choice]; |
||
| 107 | if (!copy($source, $destination)) { |
||
| 108 | drush_log(dt('Copy from @source to @destination failed.', ['@source' => $source, '@destination' => $destination]), LogLevel::ERROR); |
||
| 109 | } |
||
| 110 | else { |
||
| 111 | _df_tools_config_strip_uuid($destination); |
||
| 112 | drush_log(dt('Successfully copied @config.', ['@config' => $config]), LogLevel::OK); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | break; |
||
| 117 | case 'delete': |
||
| 118 | foreach ($list as $config) { |
||
| 119 | $instances = _df_tools_config_find_config_instances($destination_storage, $config); |
||
| 120 | $choice = drush_choice($instances, dt('Choose delete destination for @config.', ['@config' => $config])); |
||
| 121 | if ($choice !== FALSE) { |
||
| 122 | if (!unlink($instances[$choice])) { |
||
| 123 | drush_log(dt('Deletion of @path failed.', ['@path' => $instances[$choice]]), LogLevel::ERROR); |
||
| 124 | } |
||
| 125 | else { |
||
| 126 | drush_log(dt('Successfully deleted @config.', ['@config' => $config]), LogLevel::OK); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | break; |
||
| 131 | case 'rename': |
||
| 132 | // Never seen this in practice, but we can add support if needed. |
||
| 133 | break; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return TRUE; |
||
| 139 | } |
||
| 230 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths