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
if ( $this->tryRespondFromFileCache( $fileCache, $context, $etag ) ) {
return; // output handled
}
if ( $this->tryRespondFromFileCache( $fileCache, $context, $etag ) ) {
return; // output handled
}
+ } else {
+ $fileCache = null;
- // 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() );