From c8fd0e5a766b6580cf634bc18382b33542b11a5b Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Mon, 19 Oct 2026 15:34:36 +0400 Subject: [PATCH 1/2] [#587] Fix the Rector findings and run rector:check in CI --- .github/workflows/php.yml | 3 +++ CHANGELOG.md | 1 + src/App/Factories/AppFactory.php | 4 +--- src/Archive/Adapters/ZipAdapter.php | 4 +--- src/Archive/Factories/ArchiveFactory.php | 4 +--- src/Asset/AssetManager.php | 2 +- src/Auth/Factories/AuthFactory.php | 4 +--- src/Cache/Factories/CacheFactory.php | 4 +--- src/Captcha/Factories/CaptchaFactory.php | 4 +--- src/Config/Config.php | 6 +++--- src/Database/Adapters/Sleekdb/SleekDbal.php | 4 +--- src/Debugger/DebuggerStore.php | 4 +--- src/Di/DiContainer.php | 4 +--- src/Encryption/Factories/CryptorFactory.php | 4 +--- src/Environment/Helpers/env.php | 2 +- src/HttpClient/Adapters/CurlAdapter.php | 8 ++++---- src/Lang/Adapters/FileAdapter.php | 2 +- src/Logger/Factories/LoggerFactory.php | 4 +--- src/Mailer/Factories/MailerFactory.php | 4 +--- src/RateLimit/Factories/RateLimiterFactory.php | 4 +--- src/Renderer/Factories/RendererFactory.php | 4 +--- src/Session/Factories/SessionFactory.php | 4 +--- src/Storage/Factories/FileSystemFactory.php | 4 +--- src/Validation/Validator.php | 8 ++------ 24 files changed, 32 insertions(+), 64 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f508c8062..bd8026f7d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -60,6 +60,9 @@ jobs: - name: Run PHPStan run: composer phpstan + - name: Run Rector + run: composer rector:check + - name: Run tests run: composer test -- --fail-on-warning --fail-on-risky diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b763b9ec..821a0ea4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ The format is based on Keep a Changelog. - Refactored the Lang package to resolve adapter instances through `LangFactory` configuration and load file translations lazily on first use instead of preloading them during web boot (#533) - **BREAKING:** Reshaped Lang configuration so `lang.default` now selects the adapter, locale fallback moved to `lang.default_locale`, and the unused `lang.enabled` toggle was removed (#533) - **BREAKING:** Removed `Lang::isEnabled()` from the public Lang API because it no longer affected runtime behavior (#533) +- Applied the pending Rector refactors across `src/` (null-coalescing assignment for lazy initialization, explicit `instanceof` checks instead of truthiness checks on nullable objects, native return types on `env()`, `CurlAdapter::getId()` and `CurlAdapter::getResponseCookies()`) and added `composer rector:check` to the CI workflow after PHPStan (#587) ### Fixed - The page not found response is JSON for every client that asks for JSON, not only when the `Accept` header is exactly `application/json`: clients such as axios (`application/json, text/plain, */*`), a `charset` parameter, `+json` types and AJAX requests used to get the HTML page. `page_not_found_response()` decides with `Request::expectsJson()` and takes an optional request (#581) diff --git a/src/App/Factories/AppFactory.php b/src/App/Factories/AppFactory.php index f6d565ce2..e5ba7793e 100644 --- a/src/App/Factories/AppFactory.php +++ b/src/App/Factories/AppFactory.php @@ -44,9 +44,7 @@ class AppFactory public static function create(string $type, string $baseDir): App { - if (!isset(self::$instances[$type])) { - self::$instances[$type] = self::createInstance($type, $baseDir); - } + self::$instances[$type] ??= self::createInstance($type, $baseDir); return self::$instances[$type]; } diff --git a/src/Archive/Adapters/ZipAdapter.php b/src/Archive/Adapters/ZipAdapter.php index 284a7cf18..ace661dd4 100644 --- a/src/Archive/Adapters/ZipAdapter.php +++ b/src/Archive/Adapters/ZipAdapter.php @@ -209,9 +209,7 @@ private function openArchive(): void throw ArchiveException::missingArchiveName(); } - if ($this->archive === null) { - $this->archive = new ZipArchive(); - } + $this->archive ??= new ZipArchive(); if ($this->archive->filename) { $this->archive->close(); diff --git a/src/Archive/Factories/ArchiveFactory.php b/src/Archive/Factories/ArchiveFactory.php index 8595e9042..6c29c221a 100644 --- a/src/Archive/Factories/ArchiveFactory.php +++ b/src/Archive/Factories/ArchiveFactory.php @@ -52,9 +52,7 @@ public static function get(string $type = ArchiveType::PHAR): Archive */ public function resolve(string $type = ArchiveType::PHAR): Archive { - if (!isset($this->instances[$type])) { - $this->instances[$type] = $this->createInstance($type); - } + $this->instances[$type] ??= $this->createInstance($type); return $this->instances[$type]; } diff --git a/src/Asset/AssetManager.php b/src/Asset/AssetManager.php index b0da67896..8b52ea227 100644 --- a/src/Asset/AssetManager.php +++ b/src/Asset/AssetManager.php @@ -92,7 +92,7 @@ public function register(array $assets): void */ public function registerAsset(Asset $asset): void { - if ($asset->getName() && $this->get($asset->getName())) { + if ($asset->getName() && $this->get($asset->getName()) instanceof Asset) { throw AssetException::nameInUse($asset->getName()); } diff --git a/src/Auth/Factories/AuthFactory.php b/src/Auth/Factories/AuthFactory.php index 37d47db29..dc122316e 100644 --- a/src/Auth/Factories/AuthFactory.php +++ b/src/Auth/Factories/AuthFactory.php @@ -75,9 +75,7 @@ public function resolve(?string $adapter = null): Auth $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Cache/Factories/CacheFactory.php b/src/Cache/Factories/CacheFactory.php index 7c1373179..759440e09 100644 --- a/src/Cache/Factories/CacheFactory.php +++ b/src/Cache/Factories/CacheFactory.php @@ -68,9 +68,7 @@ public function resolve(?string $adapter = null): Cache $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Captcha/Factories/CaptchaFactory.php b/src/Captcha/Factories/CaptchaFactory.php index f700f84e1..167c70d14 100644 --- a/src/Captcha/Factories/CaptchaFactory.php +++ b/src/Captcha/Factories/CaptchaFactory.php @@ -68,9 +68,7 @@ public function resolve(?string $adapter = null): Captcha $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Config/Config.php b/src/Config/Config.php index 6cc2a360c..346fd70c0 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -77,7 +77,7 @@ public function importIfExists(Setup $setup): bool */ public function get(string $key, $default = null) { - if ($this->configs && $this->configs->has($key)) { + if ($this->configs instanceof Data && $this->configs->has($key)) { return $this->configs->get($key); } @@ -97,7 +97,7 @@ public function all(): ?Data */ public function has(string $key): bool { - return $this->configs && !empty($this->configs->has($key)); + return $this->configs instanceof Data && !empty($this->configs->has($key)); } /** @@ -117,7 +117,7 @@ public function set(string $key, $value): void */ public function delete(string $key): void { - $this->configs && $this->configs->remove($key); + $this->configs instanceof Data && $this->configs->remove($key); } /** diff --git a/src/Database/Adapters/Sleekdb/SleekDbal.php b/src/Database/Adapters/Sleekdb/SleekDbal.php index d0fa5aeee..7c266022a 100644 --- a/src/Database/Adapters/Sleekdb/SleekDbal.php +++ b/src/Database/Adapters/Sleekdb/SleekDbal.php @@ -367,9 +367,7 @@ protected function buildJoinPath(string $currentPath, string $table): string */ protected function getQueryBuilder(): QueryBuilder { - if ($this->queryBuilder === null) { - $this->queryBuilder = $this->getOrmModel()->createQueryBuilder(); - } + $this->queryBuilder ??= $this->getOrmModel()->createQueryBuilder(); return $this->queryBuilder; } diff --git a/src/Debugger/DebuggerStore.php b/src/Debugger/DebuggerStore.php index f35fb860b..d9d4e6b0c 100644 --- a/src/Debugger/DebuggerStore.php +++ b/src/Debugger/DebuggerStore.php @@ -29,9 +29,7 @@ class DebuggerStore implements DebuggerStoreInterface public function init(array $keys): void { foreach ($keys as $key) { - if (!isset(self::$store[$key])) { - self::$store[$key] = []; - } + self::$store[$key] ??= []; } } diff --git a/src/Di/DiContainer.php b/src/Di/DiContainer.php index 3b9324dce..658c2ecdb 100644 --- a/src/Di/DiContainer.php +++ b/src/Di/DiContainer.php @@ -193,9 +193,7 @@ private function resolve(string $abstract, array $args = [], bool $singleton = t $concrete = $this->registry->getConcrete($abstract); if ($singleton) { - if (!isset($this->container[$abstract])) { - $this->container[$abstract] = $this->instantiate($concrete, $args); - } + $this->container[$abstract] ??= $this->instantiate($concrete, $args); return $this->container[$abstract]; } diff --git a/src/Encryption/Factories/CryptorFactory.php b/src/Encryption/Factories/CryptorFactory.php index 2be432720..36e902662 100644 --- a/src/Encryption/Factories/CryptorFactory.php +++ b/src/Encryption/Factories/CryptorFactory.php @@ -52,9 +52,7 @@ public static function get(string $type = CryptorType::SYMMETRIC): Cryptor */ public function resolve(string $type = CryptorType::SYMMETRIC): Cryptor { - if (!isset($this->instances[$type])) { - $this->instances[$type] = $this->createInstance($type); - } + $this->instances[$type] ??= $this->createInstance($type); return $this->instances[$type]; } diff --git a/src/Environment/Helpers/env.php b/src/Environment/Helpers/env.php index 860cbe84c..49ba01d93 100644 --- a/src/Environment/Helpers/env.php +++ b/src/Environment/Helpers/env.php @@ -31,7 +31,7 @@ function environment(): Environment * @return mixed * @throws EnvException|DiException|\ReflectionException */ -function env(string $var, $default = null) +function env(string $var, $default = null): mixed { return environment()->getValue($var, $default); } diff --git a/src/HttpClient/Adapters/CurlAdapter.php b/src/HttpClient/Adapters/CurlAdapter.php index 275c20048..462d93b8e 100644 --- a/src/HttpClient/Adapters/CurlAdapter.php +++ b/src/HttpClient/Adapters/CurlAdapter.php @@ -260,9 +260,9 @@ public function finalizeResponse($rawResponse): void } /** - * @return int|string + * @return int */ - public function getId() + public function getId(): int { return $this->id; } @@ -291,9 +291,9 @@ public function getResponseHeaders(): iterable } /** - * @return mixed + * @return array */ - public function getResponseCookies() + public function getResponseCookies(): array { return $this->responseCookies; } diff --git a/src/Lang/Adapters/FileAdapter.php b/src/Lang/Adapters/FileAdapter.php index 424b80696..f36b7c9e0 100644 --- a/src/Lang/Adapters/FileAdapter.php +++ b/src/Lang/Adapters/FileAdapter.php @@ -91,7 +91,7 @@ public function get(string $key, array|string $params = null): string $this->loadTranslations(); } - if ($this->translations && $this->translations->has($key)) { + if ($this->translations instanceof Data && $this->translations->has($key)) { $message = $this->translations->get($key); return $params ? _message($message, $params) : $message; } diff --git a/src/Logger/Factories/LoggerFactory.php b/src/Logger/Factories/LoggerFactory.php index fa82c5fee..56ffdf1d2 100644 --- a/src/Logger/Factories/LoggerFactory.php +++ b/src/Logger/Factories/LoggerFactory.php @@ -77,9 +77,7 @@ public function resolve(?string $adapter = null): Logger LoggerConfig::setAppLogLevel($logLevel); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Mailer/Factories/MailerFactory.php b/src/Mailer/Factories/MailerFactory.php index 272364e8a..fa88c174e 100644 --- a/src/Mailer/Factories/MailerFactory.php +++ b/src/Mailer/Factories/MailerFactory.php @@ -72,9 +72,7 @@ public function resolve(?string $adapter = null): Mailer $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/RateLimit/Factories/RateLimiterFactory.php b/src/RateLimit/Factories/RateLimiterFactory.php index 32e15276d..de188b598 100644 --- a/src/RateLimit/Factories/RateLimiterFactory.php +++ b/src/RateLimit/Factories/RateLimiterFactory.php @@ -63,9 +63,7 @@ public function resolve(?string $adapter = null): RateLimiter $adapter ??= (string) config()->get('rate_limit.default', RateLimitType::FILE); $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Renderer/Factories/RendererFactory.php b/src/Renderer/Factories/RendererFactory.php index c156b11a7..7bacf51cd 100644 --- a/src/Renderer/Factories/RendererFactory.php +++ b/src/Renderer/Factories/RendererFactory.php @@ -64,9 +64,7 @@ public function resolve(?string $adapter = null): Renderer $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Session/Factories/SessionFactory.php b/src/Session/Factories/SessionFactory.php index 934848562..883ded3cf 100644 --- a/src/Session/Factories/SessionFactory.php +++ b/src/Session/Factories/SessionFactory.php @@ -64,9 +64,7 @@ public function resolve(?string $adapter = null): Session $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Storage/Factories/FileSystemFactory.php b/src/Storage/Factories/FileSystemFactory.php index 9098d6a97..8357b9a22 100644 --- a/src/Storage/Factories/FileSystemFactory.php +++ b/src/Storage/Factories/FileSystemFactory.php @@ -78,9 +78,7 @@ public function resolve(?string $adapter = null): FileSystem $adapterClass = $this->getAdapterClass($adapter); - if (!isset($this->instances[$adapter])) { - $this->instances[$adapter] = $this->createInstance($adapterClass, $adapter); - } + $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); return $this->instances[$adapter]; } diff --git a/src/Validation/Validator.php b/src/Validation/Validator.php index 065c7a3bd..de79ee275 100644 --- a/src/Validation/Validator.php +++ b/src/Validation/Validator.php @@ -217,9 +217,7 @@ public function getErrors(): array */ protected function addError(string $field, string $rule, mixed $param = null): void { - if (!isset($this->errors[$field])) { - $this->errors[$field] = []; - } + $this->errors[$field] ??= []; $this->errors[$field][$rule] = $param; } @@ -249,9 +247,7 @@ protected function executeCustomRule(string $rule, mixed $value, ...$params): bo private function setOrUpdateRule(string $field, string $ruleName, mixed $ruleParam): void { - if (!isset($this->rules[$field])) { - $this->rules[$field] = []; - } + $this->rules[$field] ??= []; $this->rules[$field][$ruleName] = $ruleParam; } From cdb6a9db1d725080cd71523d48e3c8cb8dc05076 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Mon, 19 Oct 2026 17:05:22 +0400 Subject: [PATCH 2/2] [#587] Return the cached factory instance in one statement --- src/App/Factories/AppFactory.php | 4 +--- src/Archive/Factories/ArchiveFactory.php | 4 +--- src/Auth/Factories/AuthFactory.php | 4 +--- src/Cache/Factories/CacheFactory.php | 4 +--- src/Captcha/Factories/CaptchaFactory.php | 4 +--- src/Encryption/Factories/CryptorFactory.php | 4 +--- src/Logger/Factories/LoggerFactory.php | 4 +--- src/Mailer/Factories/MailerFactory.php | 4 +--- src/RateLimit/Factories/RateLimiterFactory.php | 4 +--- src/Renderer/Factories/RendererFactory.php | 4 +--- src/Session/Factories/SessionFactory.php | 4 +--- src/Storage/Factories/FileSystemFactory.php | 4 +--- 12 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/App/Factories/AppFactory.php b/src/App/Factories/AppFactory.php index e5ba7793e..becfd5186 100644 --- a/src/App/Factories/AppFactory.php +++ b/src/App/Factories/AppFactory.php @@ -44,9 +44,7 @@ class AppFactory public static function create(string $type, string $baseDir): App { - self::$instances[$type] ??= self::createInstance($type, $baseDir); - - return self::$instances[$type]; + return self::$instances[$type] ??= self::createInstance($type, $baseDir); } public static function destroy(string $type): void diff --git a/src/Archive/Factories/ArchiveFactory.php b/src/Archive/Factories/ArchiveFactory.php index 6c29c221a..1af2dd0b0 100644 --- a/src/Archive/Factories/ArchiveFactory.php +++ b/src/Archive/Factories/ArchiveFactory.php @@ -52,9 +52,7 @@ public static function get(string $type = ArchiveType::PHAR): Archive */ public function resolve(string $type = ArchiveType::PHAR): Archive { - $this->instances[$type] ??= $this->createInstance($type); - - return $this->instances[$type]; + return $this->instances[$type] ??= $this->createInstance($type); } /** diff --git a/src/Auth/Factories/AuthFactory.php b/src/Auth/Factories/AuthFactory.php index dc122316e..cdc8cb36c 100644 --- a/src/Auth/Factories/AuthFactory.php +++ b/src/Auth/Factories/AuthFactory.php @@ -75,9 +75,7 @@ public function resolve(?string $adapter = null): Auth $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Cache/Factories/CacheFactory.php b/src/Cache/Factories/CacheFactory.php index 759440e09..48f341aeb 100644 --- a/src/Cache/Factories/CacheFactory.php +++ b/src/Cache/Factories/CacheFactory.php @@ -68,9 +68,7 @@ public function resolve(?string $adapter = null): Cache $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Captcha/Factories/CaptchaFactory.php b/src/Captcha/Factories/CaptchaFactory.php index 167c70d14..8ce862b26 100644 --- a/src/Captcha/Factories/CaptchaFactory.php +++ b/src/Captcha/Factories/CaptchaFactory.php @@ -68,9 +68,7 @@ public function resolve(?string $adapter = null): Captcha $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Encryption/Factories/CryptorFactory.php b/src/Encryption/Factories/CryptorFactory.php index 36e902662..f781cc26a 100644 --- a/src/Encryption/Factories/CryptorFactory.php +++ b/src/Encryption/Factories/CryptorFactory.php @@ -52,9 +52,7 @@ public static function get(string $type = CryptorType::SYMMETRIC): Cryptor */ public function resolve(string $type = CryptorType::SYMMETRIC): Cryptor { - $this->instances[$type] ??= $this->createInstance($type); - - return $this->instances[$type]; + return $this->instances[$type] ??= $this->createInstance($type); } /** diff --git a/src/Logger/Factories/LoggerFactory.php b/src/Logger/Factories/LoggerFactory.php index 56ffdf1d2..f8e6afc39 100644 --- a/src/Logger/Factories/LoggerFactory.php +++ b/src/Logger/Factories/LoggerFactory.php @@ -77,9 +77,7 @@ public function resolve(?string $adapter = null): Logger LoggerConfig::setAppLogLevel($logLevel); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Mailer/Factories/MailerFactory.php b/src/Mailer/Factories/MailerFactory.php index fa88c174e..93b8fb7be 100644 --- a/src/Mailer/Factories/MailerFactory.php +++ b/src/Mailer/Factories/MailerFactory.php @@ -72,9 +72,7 @@ public function resolve(?string $adapter = null): Mailer $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/RateLimit/Factories/RateLimiterFactory.php b/src/RateLimit/Factories/RateLimiterFactory.php index de188b598..5b0504f48 100644 --- a/src/RateLimit/Factories/RateLimiterFactory.php +++ b/src/RateLimit/Factories/RateLimiterFactory.php @@ -63,9 +63,7 @@ public function resolve(?string $adapter = null): RateLimiter $adapter ??= (string) config()->get('rate_limit.default', RateLimitType::FILE); $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Renderer/Factories/RendererFactory.php b/src/Renderer/Factories/RendererFactory.php index 7bacf51cd..a70096afa 100644 --- a/src/Renderer/Factories/RendererFactory.php +++ b/src/Renderer/Factories/RendererFactory.php @@ -64,9 +64,7 @@ public function resolve(?string $adapter = null): Renderer $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Session/Factories/SessionFactory.php b/src/Session/Factories/SessionFactory.php index 883ded3cf..ff1d2ebd8 100644 --- a/src/Session/Factories/SessionFactory.php +++ b/src/Session/Factories/SessionFactory.php @@ -64,9 +64,7 @@ public function resolve(?string $adapter = null): Session $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /** diff --git a/src/Storage/Factories/FileSystemFactory.php b/src/Storage/Factories/FileSystemFactory.php index 8357b9a22..554f688ed 100644 --- a/src/Storage/Factories/FileSystemFactory.php +++ b/src/Storage/Factories/FileSystemFactory.php @@ -78,9 +78,7 @@ public function resolve(?string $adapter = null): FileSystem $adapterClass = $this->getAdapterClass($adapter); - $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); - - return $this->instances[$adapter]; + return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter); } /**