You are here

private function LibraryDeprecationAnalyzer::analyzeLibraryDependencies in Upgrade Status 8.3

Same name and namespace in other branches
  1. 8.2 src/LibraryDeprecationAnalyzer.php \Drupal\upgrade_status\LibraryDeprecationAnalyzer::analyzeLibraryDependencies()

Analyzes libraries for dependencies on deprecated libraries.

Parameters

\Drupal\Core\Extension\Extension $extension: The extension to be analyzed.

Return value

\Drupal\upgrade_status\DeprecationMessage[]

1 call to LibraryDeprecationAnalyzer::analyzeLibraryDependencies()
LibraryDeprecationAnalyzer::analyze in src/LibraryDeprecationAnalyzer.php
Analyzes usages of deprecated libraries in an extension.

File

src/LibraryDeprecationAnalyzer.php, line 115

Class

LibraryDeprecationAnalyzer
A library deprecation analyzer.

Namespace

Drupal\upgrade_status

Code

private function analyzeLibraryDependencies(Extension $extension) : array {

  // Drupal\Core\Asset\LibraryDiscoveryParser::buildByExtension() assumes a
  // disabled module is a theme and fails not finding it then, so check if
  // the extension identified he is an installed module or theme. The library
  // info will not be available otherwise.
  $installed_modules = array_keys($this->moduleExtensionList
    ->getAllInstalledInfo());
  $installed_themes = array_keys($this->themeExtensionList
    ->getAllInstalledInfo());
  if (!in_array($extension
    ->getName(), $installed_modules) && !in_array($extension
    ->getName(), $installed_themes)) {
    $message = sprintf("The '%s' extension is not installed. Cannot check deprecated library use.", $extension
      ->getName());
    return [
      new DeprecationMessage($message, $extension
        ->getPath(), 0),
    ];
  }
  try {
    $libraries = $this->libraryDiscoveryParser
      ->buildByExtension($extension
      ->getName());
  } catch (\Exception $e) {
    return [
      new DeprecationMessage($e
        ->getMessage(), $extension
        ->getPath(), 0),
    ];
  }
  $libraries_with_dependencies = array_filter($libraries, function ($library) {
    return isset($library['dependencies']);
  });
  $deprecations = [];
  $file = sprintf('%s/%s.libraries.yml', $extension
    ->getPath(), $extension
    ->getName());
  foreach ($libraries_with_dependencies as $key => $library_with_dependency) {
    foreach ($library_with_dependency['dependencies'] as $dependency) {
      $is_deprecated = $this
        ->isLibraryDeprecated($dependency);
      if (is_null($is_deprecated)) {
        $message = sprintf("The '%s' library (a dependency of '%s') is not defined because the defining extension is not installed. Cannot decide if it is deprecated or not.", $dependency, $key);
        $deprecations[] = new DeprecationMessage($message, $file, 0);
      }
      elseif (!empty($is_deprecated)) {
        if ($is_deprecated instanceof DeprecationMessage) {
          $is_deprecated
            ->setFile($file);
          $deprecations[] = $is_deprecated;
        }
        else {
          $message = sprintf("The '%s' library is depending on a deprecated library. %s", $key, $is_deprecated);
          $deprecations[] = new DeprecationMessage($message, $file, 0);
        }
      }
    }
  }
  return $deprecations;
}