You are here

protected function DeprecationAnalyser::categorizeMessage in Upgrade Status 8

Annotate and categorize the error message.

Parameters

string $error: Error message as identified by phpstan.

\Drupal\Core\Extension\Extension $extension: Extension where the error was found.

Return value

array Two item array. The reformatted error and the category.

1 call to DeprecationAnalyser::categorizeMessage()
DeprecationAnalyser::analyse in src/DeprecationAnalyser.php
Analyse the codebase of an extension including all its sub-components.

File

src/DeprecationAnalyser.php, line 453

Class

DeprecationAnalyser

Namespace

Drupal\upgrade_status

Code

protected function categorizeMessage(string $error, Extension $extension) {

  // Make the error more readable in case it has the deprecation text.
  $error = preg_replace('!:\\s+(in|as of)!', '. Deprecated \\1', $error);

  // TestBase and WebTestBase replacements are available at least from Drupal
  // 8.6.0, so use that version number. Otherwise use the number from the
  // message.
  $version = '';
  if (preg_match('!\\\\(Web|)TestBase. Deprecated in [Dd]rupal[ :]8.8.0 !', $error)) {
    $version = '8.6.0';
    $error .= " Replacement available from drupal:8.6.0.";
  }
  elseif (preg_match('!Deprecated (in|as of) [Dd]rupal[ :](8.\\d)!', $error, $version_found)) {
    $version = $version_found[2];
  }

  // Set a default category for the messages we can't categorize.
  $category = 'uncategorized';
  if (!empty($version)) {

    // Categorize deprecations for contributed projects based on
    // community rules.
    if (!empty($extension->info['project'])) {

      // If the found deprecation is older or equal to the oldest
      // supported core version, it should be old enough to update
      // either way.
      if (version_compare($version, self::CORE_MINOR_OLDEST_SUPPORTED) <= 0) {
        $category = 'old';
      }
      else {
        $category = 'later';
      }
    }
    else {

      // If the found deprecation is older or equal to the current
      // Drupal version on this site, it should be safe to update.
      if (version_compare($version, \Drupal::VERSION) <= 0) {
        $category = 'safe';
      }
      else {
        $category = 'later';
      }
    }
  }

  // If the deprecation is already for Drupal 10, put it in the ignore
  // category. This overwrites any categorization before intentionally.
  if (preg_match('!(will be|is) removed (before|from) [Dd]rupal[ :](10.\\d)!', $error)) {
    $category = 'ignore';
  }
  return [
    $error,
    $category,
  ];
}