diff --git a/setup/src/Magento/Setup/Module/Di/Code/Scanner/XmlScanner.php b/setup/src/Magento/Setup/Module/Di/Code/Scanner/XmlScanner.php
index a606c26..5baefb1 100644
--- a/setup/src/Magento/Setup/Module/Di/Code/Scanner/XmlScanner.php
+++ b/setup/src/Magento/Setup/Module/Di/Code/Scanner/XmlScanner.php
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types=1);
+
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
@@ -42,42 +44,55 @@ class XmlScanner implements ScannerInterface
             $virtualTypeQuery = "//virtualType/@name";
 
             foreach ($xpath->query($virtualTypeQuery) as $virtualNode) {
-                $virtualTypes[] = $virtualNode->nodeValue;
-            }
-
-            $regex = '/^(.*)\\\(.*)Proxy$/';
-            $query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " .
-                "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
-                "//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
-                "/config/virtualType[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type";
-            /** @var \DOMNode $node */
-            foreach ($xpath->query($query) as $node) {
-                $output[] = $node->nodeValue;
+                $virtualTypes[] = ltrim($virtualNode->nodeValue, '\\');
             }
 
-            $factoriesOutput = array_merge($factoriesOutput, $this->scanFactories($xpath));
+            $output[] = $this->scanProxies($xpath);
+            $factoriesOutput[] = $this->scanFactories($xpath);
         }
 
-        $output = array_unique($output);
-        $factoriesOutput = array_unique($factoriesOutput);
+        $output = array_unique(array_merge([], ...$output));
+        $factoriesOutput = array_unique(array_merge([], ...$factoriesOutput));
         $factoriesOutput = array_diff($factoriesOutput, $virtualTypes);
         return array_merge($this->_filterEntities($output), $factoriesOutput);
     }
 
     /**
-     * Scan factories from all di.xml and retrieve non virtual one
+     * Scan proxies from all di.xml
+     *
+     * @param \DOMXPath $xpath
+     * @return array
+     */
+    private function scanProxies(\DOMXPath $xpath): array
+    {
+        $result = [];
+        $regex = '/^(\s+)?(.*)\\\(.*)Proxy(\s+)?$/';
+        $query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " .
+            "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
+            "//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
+            "/config/virtualType[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type";
+        /** @var \DOMNode $node */
+        foreach ($xpath->query($query) as $node) {
+            $result[] = ltrim(trim($node->nodeValue), '\\');
+        }
+        return $result;
+    }
+
+    /**
+     * Scan factories from all di.xml and retrieve non-virtual one
      *
      * @param \DOMXPath $domXpath
      * @return array
      */
-    private function scanFactories(\DOMXPath $domXpath)
+    private function scanFactories(\DOMXPath $domXpath): array
     {
         $output = [];
-        $regex = '/^(.*)Factory$/';
+        $regex = '/^(\s+)?(.*)Factory(\s+)?$/';
         $query = "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
             "//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0]";
+
         foreach ($domXpath->query($query) as $node) {
-            $output[] = $node->nodeValue;
+            $output[] = ltrim(trim($node->nodeValue), '\\');
         }
 
         return $output;
@@ -94,13 +109,13 @@ class XmlScanner implements ScannerInterface
         $entitySuffix = '\\' . ucfirst(ProxyGenerator::ENTITY_TYPE);
         $filteredEntities = [];
         foreach ($output as $className) {
-            $entityName = substr($className, -strlen($entitySuffix)) === $entitySuffix
+            $entityName = str_ends_with($className, $entitySuffix)
                 ? substr($className, 0, -strlen($entitySuffix))
                 : $className;
             $isClassExists = false;
             try {
                 $isClassExists = class_exists($className);
-            } catch (\RuntimeException $e) {
+            } catch (\RuntimeException $e) { //@codingStandardsIgnoreLine
             }
             if (false === $isClassExists) {
                 if (class_exists($entityName) || interface_exists($entityName)) {
