From ab1b1de0294314503af16d5b346e5e2536542210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Tue, 21 Jan 2020 19:06:21 +0100 Subject: [PATCH 1/2] magento/magento2#26479 Clear notice if Autoloader was not registered properly, instead of passing the error to higher levels --- .../Magento/Framework/Autoload/AutoloaderRegistry.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php b/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php index f051d215808a3..7a7e3501f89bd 100644 --- a/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php +++ b/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php @@ -34,12 +34,12 @@ public static function registerAutoloader(AutoloaderInterface $newAutoloader) * @throws \Exception * @return AutoloaderInterface */ - public static function getAutoloader() + public static function getAutoloader(): AutoloaderInterface { - if (self::$autoloader !== null) { - return self::$autoloader; - } else { + if (!self::$autoloader instanceof AutoloaderInterface) { throw new \Exception('Autoloader is not registered, cannot be retrieved.'); } + + return self::$autoloader; } } From 61bc535bc277a340fd43bf9722c331b2a08f5712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Thu, 23 Jan 2020 13:27:19 +0100 Subject: [PATCH 2/2] Fix: Static tests --- .../Magento/Framework/Autoload/AutoloaderRegistry.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php b/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php index 7a7e3501f89bd..037d8c2181dbf 100644 --- a/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php +++ b/lib/internal/Magento/Framework/Autoload/AutoloaderRegistry.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\Autoload; +use InvalidArgumentException; use Magento\Framework\Autoload\AutoloaderInterface; /** @@ -23,7 +24,7 @@ class AutoloaderRegistry * @param AutoloaderInterface $newAutoloader * @return void */ - public static function registerAutoloader(AutoloaderInterface $newAutoloader) + public static function registerAutoloader(AutoloaderInterface $newAutoloader): void { self::$autoloader = $newAutoloader; } @@ -31,13 +32,13 @@ public static function registerAutoloader(AutoloaderInterface $newAutoloader) /** * Returns the registered autoloader * - * @throws \Exception + * @throws InvalidArgumentException * @return AutoloaderInterface */ public static function getAutoloader(): AutoloaderInterface { if (!self::$autoloader instanceof AutoloaderInterface) { - throw new \Exception('Autoloader is not registered, cannot be retrieved.'); + throw new InvalidArgumentException('Autoloader is not registered, cannot be retrieved.'); } return self::$autoloader;