protected function DeprecationAnalyzer::categorizeMessage in Upgrade Status 8.3
Same name and namespace in other branches
- 8.2 src/DeprecationAnalyzer.php \Drupal\upgrade_status\DeprecationAnalyzer::categorizeMessage()
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 DeprecationAnalyzer::categorizeMessage()
- DeprecationAnalyzer::analyze in src/
DeprecationAnalyzer.php - Analyze the codebase of an extension including all its sub-components.
File
- src/
DeprecationAnalyzer.php, line 615
Class
Namespace
Drupal\upgrade_statusCode
protected function categorizeMessage(string $error, Extension $extension) {
// Make the error more readable in case it has the deprecation text.
$error = preg_replace('!\\s+!', ' ', trim($error));
$error = preg_replace('!:\\s+(in|as of)!', '. Deprecated \\1', $error);
$error = preg_replace('!(u|U)se \\\\Drupal!', '\\1se Drupal', $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[ :](\\d+\\.\\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, ProjectCollector::getOldestSupportedMinor()) <= 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 error is covered by rector, override the result.
if ($this
->isRectorCovered($error)) {
$category = 'rector';
}
// If the deprecation is already for after the next Drupal major, put it in the
// ignore category. This overwrites any categorization before intentionally.
if (preg_match('!(will be|is) removed (before|from) [Dd]rupal[ :](\\d+)\\.!', $error, $version_removed)) {
if ($version_removed[3] > ProjectCollector::getDrupalCoreMajorVersion() + 1) {
$category = 'ignore';
}
}
return [
$error,
$category,
];
}