modules/custom/d_update/src/Updater.php
public function installModules(array $modules, $enableDependencies = TRUE) {
    if (empty($modules) || !is_array($modules)) {
      return FALSE;
    }

    $moduleData = system_rebuild_module_data();
    $modules = array_combine($modules, $modules);
    if ($missing_modules = array_diff_key($modules, $moduleData)) {
      return FALSE;
    }

    return $this->moduleInstaller->install($modules, $enableDependencies);
  }
public function installModules(array $modules, $enableDependencies = TRUE) {
    if (empty($modules) || !is_array($modules)) {
      return FALSE;
    }

    $moduleData = system_rebuild_module_data();
    $modules = array_combine($modules, $modules);
    if ($missing_modules = array_diff_key($modules, $moduleData)) {
      return FALSE;
    }

    return $this->moduleInstaller->install($modules, $enableDependencies);
  }
Install modules.

@param array $modules
Numeric array with module names.
@param bool $enableDependencies
Should dependencies for modules be enabled.

@return bool
Returns if modules were installed successfully.

@throws \Drupal\Core\Extension\MissingDependencyException