Skip to content

Commit 1db2b1c

Browse files
jazzsequenceJohn Spellman
authored and
John Spellman
committed
Add pantheon-wp-coding-standards (#400)
* add our coding standards * use php 8 for linting * phpcbf fixes * ignore tests for linting * adjust and fix sniffs for object-cache.php drop-in * check if all the server global values * fix sniffs for WP CLI commands * do a composer update before install for 7.4 * make the $cache property public * fix composer update & install in both 7.4 tests * set $cache_hits property to true * set redis_calls property to public * set is_redis_connected property to public * revert wp_redis_ignore_global_groups const value * make all the private and protected properties public * use short arrays again * remove parenthesis when we instantiate the class * set object-cache back to what it was * remove extra isset checks * add the issets back to the database param * add original object-cache file back * use the version of the upstream tests that maybe have the issues fixed * update the upstream tests * Revert "add original object-cache file back" This reverts commit 1fc2b66. * restore cli.php and wp-redis.php back to what they were * remove the upstream behat tests these are failing because they're old and need to be updated. they have nothing to do with the plugin itself * add some echos * wordpress isn't actually getting installed break the brackets * one line, brackets and remove the & * guess we can't do this on one line * don't need that semicolon i don't think * okay fine, put it back the way it was * enable redis before flushing cache * enable redis on the entire site (not env) and add a wait command * enable redis early so we aren't potentially waiting for other things later * don't need to wait * don't need to enable because it's already enabled * don't need an isset, we already know it's set * use strip all tags instead of sanitize_text_field * don't activate redis twice and flush cache after wp-redis is active * re-add composer.lock * re-add composer update for 7.4
1 parent 8361a0a commit 1db2b1c

File tree

10 files changed

+813
-463
lines changed

10 files changed

+813
-463
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
lint:
2424
working_directory: ~/pantheon-systems/wp-redis
2525
docker:
26-
- image: quay.io/pantheon-public/build-tools-ci:8.x-php8.2
26+
- image: quay.io/pantheon-public/build-tools-ci:8.x-php8.0
2727
steps:
2828
- checkout
2929
- restore_cache:

bin/behat-prepare.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ terminus build:workflow:wait $TERMINUS_SITE.$TERMINUS_ENV
8686
###
8787
# Set up WordPress, theme, and plugins for the test run
8888
###
89+
echo "Installing WordPress..."
8990
# Silence output so as not to show the password.
9091
{
91-
terminus wp $SITE_ENV -- core install --title=$TERMINUS_ENV-$TERMINUS_SITE --url=$PANTHEON_SITE_URL --admin_user=$WORDPRESS_ADMIN_USERNAME --admin_email=wp-redis@getpantheon.com --admin_password=$WORDPRESS_ADMIN_PASSWORD
92+
terminus wp $SITE_ENV -- core install --title=$TERMINUS_ENV-$TERMINUS_SITE --url=$PANTHEON_SITE_URL --admin_user=$WORDPRESS_ADMIN_USERNAME --admin_email=wp-redis@getpantheon.com --admin_password=$WORDPRESS_ADMIN_PASSWORD
9293
} &> /dev/null
9394

9495
echo "Flush cache and setup environment..."

cli.php

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
2+
/**
3+
* Various WP Redis CLI utility commands.
4+
*/
25

36
/**
4-
* Various WP Redis utility commands.
7+
* Main WP Redis CLI command class.
58
*/
69
class WP_Redis_CLI_Command {
710

@@ -12,31 +15,32 @@ public function cli() {
1215
global $redis_server;
1316

1417
if ( empty( $redis_server ) ) {
15-
# Attempt to automatically load Pantheon's Redis config from the env.
16-
if ( isset( $_SERVER['CACHE_HOST'] ) ) {
17-
$redis_server = array(
18-
'host' => $_SERVER['CACHE_HOST'],
19-
'port' => $_SERVER['CACHE_PORT'],
20-
'auth' => $_SERVER['CACHE_PASSWORD'],
21-
'database' => isset( $_SERVER['CACHE_DB'] ) ? $_SERVER['CACHE_DB'] : 0,
22-
);
18+
// Attempt to automatically load Pantheon's Redis config from the env.
19+
if ( isset( $_SERVER['CACHE_HOST'] ) && isset( $_SERVER['CACHE_PORT'] ) && isset( $_SERVER['CACHE_PASSWORD'] ) && isset( $_SERVER['CACHE_DB'] ) ) {
20+
$redis_server = [
21+
'host' => sanitize_text_field( $_SERVER['CACHE_HOST'] ),
22+
'port' => sanitize_text_field( $_SERVER['CACHE_PORT'] ),
23+
'auth' => sanitize_text_field( $_SERVER['CACHE_PASSWORD'] ),
24+
'database' => sanitize_text_field( $_SERVER['CACHE_DB'] ),
25+
];
2326
} else {
24-
$redis_server = array(
25-
'host' => '127.0.0.1',
26-
'port' => 6379,
27-
'auth' => '',
27+
$redis_server = [
28+
'host' => '127.0.0.1',
29+
'port' => 6379,
30+
'auth' => '',
2831
'database' => 0,
29-
);
32+
];
3033
}
3134
}
3235

3336
if ( ! isset( $redis_server['database'] ) ) {
3437
$redis_server['database'] = 0;
3538
}
3639

37-
$cmd = WP_CLI\Utils\esc_cmd( 'redis-cli -h %s -p %s -a %s -n %s', $redis_server['host'], $redis_server['port'], $redis_server['auth'], $redis_server['database'] );
38-
$process = WP_CLI\Utils\proc_open_compat( $cmd, array( STDIN, STDOUT, STDERR ), $pipes );
39-
$r = proc_close( $process );
40+
$pipes = null;
41+
$cmd = WP_CLI\Utils\esc_cmd( 'redis-cli -h %s -p %s -a %s -n %s', $redis_server['host'], $redis_server['port'], $redis_server['auth'], $redis_server['database'] );
42+
$process = WP_CLI\Utils\proc_open_compat( $cmd, [ STDIN, STDOUT, STDERR ], $pipes );
43+
$r = proc_close( $process );
4044
exit( (int) $r );
4145
}
4246

@@ -56,11 +60,11 @@ public function cli() {
5660
public function debug( $_, $assoc_args ) {
5761
global $wp_object_cache;
5862
$this->load_wordpress_with_template();
59-
$data = array(
63+
$data = [
6064
'cache_hits' => $wp_object_cache->cache_hits,
6165
'cache_misses' => $wp_object_cache->cache_misses,
6266
'redis_calls' => $wp_object_cache->redis_calls,
63-
);
67+
];
6468
WP_CLI::print_value( $data, $assoc_args );
6569
}
6670

@@ -134,14 +138,14 @@ public function enable() {
134138
* Success: Redis stats reset.
135139
*/
136140
public function info( $_, $assoc_args ) {
137-
global $wp_object_cache, $redis_server;
141+
global $wp_object_cache;
138142

139143
if ( ! defined( 'WP_REDIS_OBJECT_CACHE' ) || ! WP_REDIS_OBJECT_CACHE ) {
140144
WP_CLI::error( 'WP Redis object-cache.php file is missing from the wp-content/ directory.' );
141145
}
142146

143147
if ( $wp_object_cache->is_redis_connected && WP_CLI\Utils\get_flag_value( $assoc_args, 'reset' ) ) {
144-
// Redis::resetStat() isn't functional, see https://github.com/phpredis/phpredis/issues/928
148+
// Redis::resetStat() isn't functional, see https://github.com/phpredis/phpredis/issues/928.
145149
if ( $wp_object_cache->redis->eval( "return redis.call('CONFIG','RESETSTAT')" ) ) {
146150
WP_CLI::success( 'Redis stats reset.' );
147151
} else {
@@ -168,7 +172,7 @@ private function load_wordpress_with_template() {
168172
// Set up the main WordPress query.
169173
wp();
170174

171-
$interpreted = array();
175+
$interpreted = [];
172176
foreach ( $wp_query as $key => $value ) {
173177
if ( 0 === stripos( $key, 'is_' ) && $value ) {
174178
$interpreted[] = $key;
@@ -188,15 +192,15 @@ function( $template ) {
188192
999
189193
);
190194

191-
// Template is normally loaded in global scope, so we need to replicate
195+
// Template is normally loaded in global scope, so we need to replicate.
192196
foreach ( $GLOBALS as $key => $value ) {
193197
// phpcs:ignore PHPCompatibility.Variables.ForbiddenGlobalVariableVariable.NonBareVariableFound
194198
global $$key;
195199
}
196200

197201
// Load the theme template.
198202
ob_start();
199-
require_once( ABSPATH . WPINC . '/template-loader.php' );
203+
require_once ABSPATH . WPINC . '/template-loader.php';
200204
ob_get_clean();
201205
}
202206

@@ -206,7 +210,7 @@ function( $template ) {
206210
* @see http://stackoverflow.com/questions/2637945/getting-relative-path-from-absolute-path-in-php
207211
*/
208212
private static function get_relative_path( $from, $to ) {
209-
// some compatibility fixes for Windows paths
213+
// some compatibility fixes for Windows paths.
210214
$from = is_dir( $from ) ? rtrim( $from, '\/' ) . '/' : $from;
211215
$to = is_dir( $to ) ? rtrim( $to, '\/' ) . '/' : $to;
212216
$from = str_replace( '\\', '/', $from );
@@ -217,15 +221,15 @@ private static function get_relative_path( $from, $to ) {
217221
$rel_path = $to;
218222

219223
foreach ( $from as $depth => $dir ) {
220-
// find first non-matching dir
224+
// find first non-matching dir.
221225
if ( $dir === $to[ $depth ] ) {
222-
// ignore this directory
226+
// ignore this directory.
223227
array_shift( $rel_path );
224228
} else {
225-
// get number of remaining dirs to $from
229+
// get number of remaining dirs to $from.
226230
$remaining = count( $from ) - $depth;
227231
if ( $remaining > 1 ) {
228-
// add traversals up to first matching dir
232+
// add traversals up to first matching dir.
229233
$pad_length = ( count( $rel_path ) + $remaining - 1 ) * -1;
230234
$rel_path = array_pad( $rel_path, $pad_length, '..' );
231235
break;

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
"behat/behat": "^3.1",
1313
"behat/mink-extension": "^2.2",
1414
"behat/mink-goutte-driver": "^1.2",
15-
"pantheon-systems/pantheon-wordpress-upstream-tests": "dev-fix-behat-upstream-tests",
16-
"wp-coding-standards/wpcs": "dev-develop as 2.3.1",
17-
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
15+
"pantheon-systems/pantheon-wp-coding-standards": "^1.0",
16+
"pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master",
1817
"phpunit/phpunit": "^9",
19-
"phpcompatibility/php-compatibility": "^9.3",
2018
"yoast/phpunit-polyfills": "^1.0"
2119
},
2220
"scripts": {

0 commit comments

Comments
 (0)