From: Timo Tijhof Date: Thu, 25 Jul 2019 22:57:08 +0000 (+0100) Subject: resourceloader: Merge $fileCache conditional blocks X-Git-Tag: 1.34.0-rc.0~807^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=69016bd2c3e3d2048dad3e245d9c24a38d43c208;p=lhc%2Fweb%2Fwiklou.git 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 --- 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() ); } }