From 48814794692b625db762da8ce0fb88a8c19ade37 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sun, 14 Apr 2024 06:57:44 +0100
Subject: [PATCH] Issue #3437178 by immaculatexavier, quietone, smustgrave,
 alexpott: Simplify getLegacyDrupalVersion()

---
 .../src/MigrationConfigurationTrait.php        | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php
index 670560761f53..5df2c0b06f2e 100644
--- a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php
+++ b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php
@@ -206,27 +206,23 @@ public static function getLegacyDrupalVersion(Connection $connection) {
     // we're querying. Catch exceptions and report that the source database is
     // not Drupal.
     // Drupal 5/6/7 can be detected by the schema_version in the system table.
-    $version_string = FALSE;
     if ($connection->schema()->tableExists('system')) {
       try {
-        $legacy_version_string = $connection
+        $version_string = $connection
           ->query('SELECT [schema_version] FROM {system} WHERE [name] = :module', [':module' => 'system'])
           ->fetchField();
-        if ($legacy_version_string && $legacy_version_string[0] == '1') {
-          if ((int) $legacy_version_string >= 1000) {
-            $version_string = '5';
-          }
-        }
-        else {
-          $version_string = substr($legacy_version_string, 0, 1);
-        }
       }
       catch (DatabaseExceptionWrapper $e) {
         // All database errors return FALSE.
       }
     }
 
-    return $version_string;
+    return match (TRUE) {
+      !isset($version_string) => FALSE,
+      (int) $version_string >= 6000 => substr($version_string, 0, 1),
+      (int) $version_string >= 1000 => '5',
+      default => FALSE,
+    };
   }
 
   /**
-- 
GitLab