Skip to content

Commit

Permalink
Address unrelated PHPCS warnings
Browse files Browse the repository at this point in the history
```
Redeclaration of variable $cache_hit_callback as static variable. (VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration)
```
  • Loading branch information
swissspidy committed Sep 22, 2022
1 parent 5773928 commit bd2ee42
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Admin/SiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ public function get_page_cache_detail( $use_previous_result = false ) {
];
}

/**
* Callback for {@see get_page_cache_headers()}.
*
* @param string $header_value Header value.
* @return bool Whether header contains the value "hit"
*/
private static function cache_hit_callback( string $header_value ): bool {
return false !== stripos( $header_value, 'hit' );
}

/**
* List of header and it's verification callback to verify if page cache is enabled or not.
*
Expand All @@ -543,11 +553,6 @@ public function get_page_cache_detail( $use_previous_result = false ) {
* @return array List of client caching headers and their (optional) verification callbacks.
*/
protected static function get_page_cache_headers() {

$cache_hit_callback = static function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), 'hit' );
};

return [
'cache-control' => static function ( $header_value ) {
return (bool) preg_match( '/max-age=[1-9]/', $header_value );
Expand All @@ -560,10 +565,10 @@ protected static function get_page_cache_headers() {
},
'last-modified' => '',
'etag' => '',
'x-cache' => $cache_hit_callback,
'x-proxy-cache' => $cache_hit_callback,
'cf-cache-status' => $cache_hit_callback,
'x-kinsta-cache' => $cache_hit_callback,
'x-cache' => [ self::class, 'cache_hit_callback' ],
'x-proxy-cache' => [ self::class, 'cache_hit_callback' ],
'cf-cache-status' => [ self::class, 'cache_hit_callback' ],
'x-kinsta-cache' => [ self::class, 'cache_hit_callback' ],
'x-cache-enabled' => static function ( $header_value ) {
return 'true' === strtolower( $header_value );
},
Expand All @@ -573,8 +578,8 @@ protected static function get_page_cache_headers() {
'cf-apo-via' => static function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), 'tcache' );
},
'x-srcache-store-status' => $cache_hit_callback,
'x-srcache-fetch-status' => $cache_hit_callback,
'x-srcache-store-status' => [ self::class, 'cache_hit_callback' ],
'x-srcache-fetch-status' => [ self::class, 'cache_hit_callback' ],
'cf-edge-cache' => static function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), 'cache' );
},
Expand Down

0 comments on commit bd2ee42

Please sign in to comment.