From 69016bd2c3e3d2048dad3e245d9c24a38d43c208 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 25 Jul 2019 23:57:08 +0100 Subject: [PATCH] resourceloader: Merge $fileCache conditional blocks Also avoid conditional existence of variables ($fileCache). This avoids isset(), which means we won't hide problems during refactor. Raised by Codehealth (sonarcloud.io) as Major Code Smell: > Merge this if statement with the enclosing one. > https://sonarcloud.io/organizations/wmftest/rules?open=php%3AS1066&rule_key=php%3AS1066 Change-Id: Iacebbe6a68dac46cdfd1415a33a547d105b24b98 --- includes/resourceloader/ResourceLoader.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 671fe86c7c..4427a5387e 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -739,6 +739,8 @@ class ResourceLoader implements LoggerAwareInterface { if ( $this->tryRespondFromFileCache( $fileCache, $context, $etag ) ) { return; // output handled } + } else { + $fileCache = null; } // Generate a response @@ -753,15 +755,17 @@ class ResourceLoader implements LoggerAwareInterface { } } - // Save response to file cache unless there are errors - if ( isset( $fileCache ) && !$this->errors && $missing === [] ) { - // Cache single modules and images...and other requests if there are enough hits - if ( ResourceFileCache::useFileCache( $context ) ) { - if ( $fileCache->isCacheWorthy() ) { - $fileCache->saveText( $response ); - } else { - $fileCache->incrMissesRecent( $context->getRequest() ); - } + // Consider saving the response to file cache (unless there are errors). + if ( $fileCache && + !$this->errors && + $missing === [] && + ResourceFileCache::useFileCache( $context ) + ) { + if ( $fileCache->isCacheWorthy() ) { + // There were enough hits, save the response to the cache + $fileCache->saveText( $response ); + } else { + $fileCache->incrMissesRecent( $context->getRequest() ); } } -- 2.20.1