Quantcast
Viewing all articles
Browse latest Browse all 294647

Clean up confusing code in ModuleInstaller that checks for dependencies

In #2885309: [PHP 7.2] each() function is deprecated some code was refactored to remove the use of PHP's each function, since it's been deprecated in PHP 7.2.

This patch that was committed was changed the following code in ModuleInstaller from:

     // Add dependencies to the list. The new modules will be processed as
      // the while loop continues.
      while (list($module) = each($module_list)) {
        foreach (array_keys($module_data[$module]->requires) as $dependency) {
          if (!isset($module_data[$dependency])) {
            // The dependency does not exist.
            throw new MissingDependencyException("Unable to install modules: module '$module' is missing its dependency module $dependency.");
          }

          // Skip already installed modules.
          if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) {
            $module_list[$dependency] = $dependency;
          }
        }
      }

to

      // Add dependencies to the list. The new modules will be processed as
      // the foreach loop continues.
      foreach ($module_list as $module => $value) {
        foreach (array_keys($module_data[$module]->requires) as $dependency) {
          if (!isset($module_data[$dependency])) {
            // The dependency does not exist.
            throw new MissingDependencyException("Unable to install modules: module '$module' is missing its dependency module $dependency.");
          }

          // Skip already installed modules.
          if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) {
            $module_list[$dependency] = $dependency;
          }
        }
      }

The outer loop was replaced with a foreach, which operates on a copy of the array, so module dependencies that are added to the list are not checked to see if they exist or not, as the foreach will never reach them.

Alex Pott looked into this and verified there's no actual bug here because the ->requires method on modules already includes dependencies of dependencies. But, the code should be cleaned up and made more clear.


Viewing all articles
Browse latest Browse all 294647

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>