Skip to content

Commit

Permalink
[CMSP-667] Update to latest version of Pantheon WP Coding Standards (#…
Browse files Browse the repository at this point in the history
…445)

* use Pantheon-WP 2.0

* linting fixes

* Don't error on mixed function & structure declaratiosn
for object-cache.php

* ignore specific sniffs that are not important

* bump composer.lock

* bump changelog

* typo 🤦‍♂️

Co-authored-by: Phil Tyler <phil.tyler@pantheon.io>

---------

Co-authored-by: Phil Tyler <phil.tyler@pantheon.io>
  • Loading branch information
jazzsequence and pwtyler committed Sep 12, 2023
1 parent a4682d5 commit d8eb080
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 222 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -110,6 +110,7 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a

### 1.4.4-dev ###
* Updates security policy [[#441](https://github.com/pantheon-systems/wp-redis/pull/441)]
* Updates Pantheon WP Coding Standards to 2.0 [[#445](https://github.com/pantheon-systems/wp-redis/pull/445)]

### 1.4.3 (June 26, 2023) ###
* Bug fix: Fixes assumption that CACHE_PORT & CACHE_PASSWORD are Set. [[428](https://github.com/pantheon-systems/wp-redis/pull/428)] (props @timnolte)
Expand Down
5 changes: 2 additions & 3 deletions cli.php
Expand Up @@ -80,7 +80,7 @@ public function enable() {
if ( file_exists( $drop_in ) ) {
WP_CLI::error( 'Unknown wp-content/object-cache.php already exists.' );
}
$object_cache = dirname( __FILE__ ) . '/object-cache.php';
$object_cache = __DIR__ . '/object-cache.php';
$target = self::get_relative_path( $drop_in, $object_cache );
chdir( WP_CONTENT_DIR );
// @codingStandardsIgnoreStart
Expand Down Expand Up @@ -184,7 +184,7 @@ private function load_wordpress_with_template() {

add_filter(
'template_include',
function( $template ) {
function ( $template ) {
$display_template = str_replace( dirname( get_template_directory() ) . '/', '', $template );
WP_CLI::debug( "Theme template: {$display_template}", 'redis-debug' );
return $template;
Expand Down Expand Up @@ -240,7 +240,6 @@ private static function get_relative_path( $from, $to ) {
}
return implode( '/', $rel_path );
}

}

WP_CLI::add_command( 'redis', 'WP_Redis_CLI_Command' );
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -12,7 +12,7 @@
"behat/behat": "^3.1",
"behat/mink-extension": "^2.2",
"behat/mink-goutte-driver": "^1.2",
"pantheon-systems/pantheon-wp-coding-standards": "^1.0",
"pantheon-systems/pantheon-wp-coding-standards": "^2.0",
"pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master",
"phpunit/phpunit": "^9",
"yoast/phpunit-polyfills": "^1.0"
Expand Down
561 changes: 351 additions & 210 deletions composer.lock

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions object-cache.php
Expand Up @@ -773,7 +773,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) {
foreach ( $keys as $key ) {
if ( $this->_isset_internal( $key, $group ) ) {
$cache[ $key ] = $this->_get_internal( $key, $group );
$this->cache_hits++;
++$this->cache_hits;
}
}
}
Expand All @@ -800,9 +800,9 @@ public function get_multiple( $keys, $group = 'default', $force = false ) {
// All non-numeric values are serialized.
$value = is_numeric( $value ) ? intval( $value ) : unserialize( $value );
$this->_set_internal( $key, $group, $value );
$this->cache_hits++;
++$this->cache_hits;
} else {
$this->cache_misses++;
++$this->cache_misses;
}
$cache[ $key ] = $value;
}
Expand Down Expand Up @@ -1329,7 +1329,7 @@ public function perform_client_connection( $redis, $client_parameters, $keys_met

// PhpRedis throws an Exception when it fails a server call.
// To prevent WordPress from fataling, we catch the Exception.
throw new Exception( $e->getMessage(), $e->getCode(), $e );
throw new Exception( $e->getMessage(), $e->getCode(), $e ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
return true;
Expand Down Expand Up @@ -1358,7 +1358,7 @@ protected function _call_redis( $method ) {
if ( ! isset( $this->redis_calls[ $method ] ) ) {
$this->redis_calls[ $method ] = 0;
}
$this->redis_calls[ $method ]++;
++$this->redis_calls[ $method ];
$retval = call_user_func_array( [ $this->redis, $method ], $arguments );
return $retval;
} catch ( Exception $e ) {
Expand Down Expand Up @@ -1424,7 +1424,6 @@ protected function _call_redis( $method ) {
case 'hmGet':
return false;
}

}

/**
Expand Down Expand Up @@ -1557,6 +1556,6 @@ public function __construct() {
* @return bool True value. Won't be used by PHP
*/
public function __destruct() {
return true;
return true; // phpcs:ignore Universal.CodeAnalysis.ConstructorDestructorReturn.ReturnValueFound
}
}
4 changes: 4 additions & 0 deletions phpcs.xml.dist
Expand Up @@ -34,6 +34,10 @@
<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery">
<file>/object-cache.php</file>
</exclude>
<!-- Don't error on mixed function & structure declarations for object-cache.php -->
<exclude name="Universal.Files.SeparateFunctionsFromOO.Mixed">
<file>/object-cache.php</file>
</exclude>

<!-- Rules we ignore for WP-CLI. -->
<!-- Function comments work differently for WP-CLI functions, so don't throw CS errors on them. -->
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Expand Up @@ -107,6 +107,7 @@ Please report security bugs found in the source code of the WP Redis plugin thro

= 1.4.4-dev =
* Updates security policy [[#441](https://github.com/pantheon-systems/wp-redis/pull/441)]
* Updates Pantheon WP Coding Standards to 2.0 [[#445](https://github.com/pantheon-systems/wp-redis/pull/445)]

= 1.4.3 (June 26, 2023) =
* Bug fix: Fixes assumption that CACHE_PORT & CACHE_PASSWORD are Set. [[428](https://github.com/pantheon-systems/wp-redis/pull/428)] (props @tnolte)
Expand Down
2 changes: 1 addition & 1 deletion wp-redis.php
Expand Up @@ -25,7 +25,7 @@
*/

if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'WP_Redis_CLI_Command' ) ) {
require_once dirname( __FILE__ ) . '/cli.php';
require_once __DIR__ . '/cli.php';
}

/**
Expand Down

0 comments on commit d8eb080

Please sign in to comment.