diff --git a/.circleci/config.yml b/.circleci/config.yml index d73a11a..ab7dece 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,7 @@ jobs: lint: working_directory: ~/pantheon-systems/wp-redis docker: - - image: quay.io/pantheon-public/build-tools-ci:8.x-php8.2 + - image: quay.io/pantheon-public/build-tools-ci:8.x-php8.0 steps: - checkout - restore_cache: diff --git a/bin/behat-prepare.sh b/bin/behat-prepare.sh index c709670..71d377c 100755 --- a/bin/behat-prepare.sh +++ b/bin/behat-prepare.sh @@ -86,9 +86,10 @@ terminus build:workflow:wait $TERMINUS_SITE.$TERMINUS_ENV ### # Set up WordPress, theme, and plugins for the test run ### +echo "Installing WordPress..." # Silence output so as not to show the password. { - 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 + 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 } &> /dev/null echo "Flush cache and setup environment..." diff --git a/cli.php b/cli.php index fa94e67..bfb2e03 100644 --- a/cli.php +++ b/cli.php @@ -1,7 +1,10 @@ $_SERVER['CACHE_HOST'], - 'port' => $_SERVER['CACHE_PORT'], - 'auth' => $_SERVER['CACHE_PASSWORD'], - 'database' => isset( $_SERVER['CACHE_DB'] ) ? $_SERVER['CACHE_DB'] : 0, - ); + // Attempt to automatically load Pantheon's Redis config from the env. + if ( isset( $_SERVER['CACHE_HOST'] ) && isset( $_SERVER['CACHE_PORT'] ) && isset( $_SERVER['CACHE_PASSWORD'] ) && isset( $_SERVER['CACHE_DB'] ) ) { + $redis_server = [ + 'host' => sanitize_text_field( $_SERVER['CACHE_HOST'] ), + 'port' => sanitize_text_field( $_SERVER['CACHE_PORT'] ), + 'auth' => sanitize_text_field( $_SERVER['CACHE_PASSWORD'] ), + 'database' => sanitize_text_field( $_SERVER['CACHE_DB'] ), + ]; } else { - $redis_server = array( - 'host' => '127.0.0.1', - 'port' => 6379, - 'auth' => '', + $redis_server = [ + 'host' => '127.0.0.1', + 'port' => 6379, + 'auth' => '', 'database' => 0, - ); + ]; } } @@ -34,9 +37,10 @@ public function cli() { $redis_server['database'] = 0; } - $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'] ); - $process = WP_CLI\Utils\proc_open_compat( $cmd, array( STDIN, STDOUT, STDERR ), $pipes ); - $r = proc_close( $process ); + $pipes = null; + $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'] ); + $process = WP_CLI\Utils\proc_open_compat( $cmd, [ STDIN, STDOUT, STDERR ], $pipes ); + $r = proc_close( $process ); exit( (int) $r ); } @@ -56,11 +60,11 @@ public function cli() { public function debug( $_, $assoc_args ) { global $wp_object_cache; $this->load_wordpress_with_template(); - $data = array( + $data = [ 'cache_hits' => $wp_object_cache->cache_hits, 'cache_misses' => $wp_object_cache->cache_misses, 'redis_calls' => $wp_object_cache->redis_calls, - ); + ]; WP_CLI::print_value( $data, $assoc_args ); } @@ -134,14 +138,14 @@ public function enable() { * Success: Redis stats reset. */ public function info( $_, $assoc_args ) { - global $wp_object_cache, $redis_server; + global $wp_object_cache; if ( ! defined( 'WP_REDIS_OBJECT_CACHE' ) || ! WP_REDIS_OBJECT_CACHE ) { WP_CLI::error( 'WP Redis object-cache.php file is missing from the wp-content/ directory.' ); } if ( $wp_object_cache->is_redis_connected && WP_CLI\Utils\get_flag_value( $assoc_args, 'reset' ) ) { - // Redis::resetStat() isn't functional, see https://github.com/phpredis/phpredis/issues/928 + // Redis::resetStat() isn't functional, see https://github.com/phpredis/phpredis/issues/928. if ( $wp_object_cache->redis->eval( "return redis.call('CONFIG','RESETSTAT')" ) ) { WP_CLI::success( 'Redis stats reset.' ); } else { @@ -168,7 +172,7 @@ private function load_wordpress_with_template() { // Set up the main WordPress query. wp(); - $interpreted = array(); + $interpreted = []; foreach ( $wp_query as $key => $value ) { if ( 0 === stripos( $key, 'is_' ) && $value ) { $interpreted[] = $key; @@ -188,7 +192,7 @@ function( $template ) { 999 ); - // Template is normally loaded in global scope, so we need to replicate + // Template is normally loaded in global scope, so we need to replicate. foreach ( $GLOBALS as $key => $value ) { // phpcs:ignore PHPCompatibility.Variables.ForbiddenGlobalVariableVariable.NonBareVariableFound global $$key; @@ -196,7 +200,7 @@ function( $template ) { // Load the theme template. ob_start(); - require_once( ABSPATH . WPINC . '/template-loader.php' ); + require_once ABSPATH . WPINC . '/template-loader.php'; ob_get_clean(); } @@ -206,7 +210,7 @@ function( $template ) { * @see http://stackoverflow.com/questions/2637945/getting-relative-path-from-absolute-path-in-php */ private static function get_relative_path( $from, $to ) { - // some compatibility fixes for Windows paths + // some compatibility fixes for Windows paths. $from = is_dir( $from ) ? rtrim( $from, '\/' ) . '/' : $from; $to = is_dir( $to ) ? rtrim( $to, '\/' ) . '/' : $to; $from = str_replace( '\\', '/', $from ); @@ -217,15 +221,15 @@ private static function get_relative_path( $from, $to ) { $rel_path = $to; foreach ( $from as $depth => $dir ) { - // find first non-matching dir + // find first non-matching dir. if ( $dir === $to[ $depth ] ) { - // ignore this directory + // ignore this directory. array_shift( $rel_path ); } else { - // get number of remaining dirs to $from + // get number of remaining dirs to $from. $remaining = count( $from ) - $depth; if ( $remaining > 1 ) { - // add traversals up to first matching dir + // add traversals up to first matching dir. $pad_length = ( count( $rel_path ) + $remaining - 1 ) * -1; $rel_path = array_pad( $rel_path, $pad_length, '..' ); break; diff --git a/composer.json b/composer.json index 4652b50..9bc37b1 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,9 @@ "behat/behat": "^3.1", "behat/mink-extension": "^2.2", "behat/mink-goutte-driver": "^1.2", - "pantheon-systems/pantheon-wordpress-upstream-tests": "dev-fix-behat-upstream-tests", - "wp-coding-standards/wpcs": "dev-develop as 2.3.1", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", + "pantheon-systems/pantheon-wp-coding-standards": "^1.0", + "pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master", "phpunit/phpunit": "^9", - "phpcompatibility/php-compatibility": "^9.3", "yoast/phpunit-polyfills": "^1.0" }, "scripts": { diff --git a/composer.lock b/composer.lock index 2a799ca..2bd200e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,61 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9632405459397716afbb9a9350dd6b98", + "content-hash": "ed9a1eaaf549f309898788e661ea2a5c", "packages": [], "packages-dev": [ + { + "name": "automattic/vipwpcs", + "version": "2.3.3", + "source": { + "type": "git", + "url": "https://github.com/Automattic/VIP-Coding-Standards.git", + "reference": "6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b", + "reference": "6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "php": ">=5.4", + "sirbrillig/phpcs-variable-analysis": "^2.11.1", + "squizlabs/php_codesniffer": "^3.5.5", + "wp-coding-standards/wpcs": "^2.3" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^0.5", + "php-parallel-lint/php-parallel-lint": "^1.0", + "phpcompatibility/php-compatibility": "^9", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4 || ^5 || ^6 || ^7" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/Automattic/VIP-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "support": { + "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues", + "source": "https://github.com/Automattic/VIP-Coding-Standards", + "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" + }, + "time": "2021-09-29T16:20:23+00:00" + }, { "name": "behat/behat", "version": "v3.13.0", @@ -456,38 +508,35 @@ }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v1.0.0", + "version": "v0.7.2", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/composer-installer.git", - "reference": "4be43904336affa5c2f70744a348312336afd0da" + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", - "reference": "4be43904336affa5c2f70744a348312336afd0da", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", "shasum": "" }, "require": { "composer-plugin-api": "^1.0 || ^2.0", - "php": ">=5.4", + "php": ">=5.3", "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", - "ext-json": "*", - "ext-zip": "*", "php-parallel-lint/php-parallel-lint": "^1.3.1", - "phpcompatibility/php-compatibility": "^9.0", - "yoast/phpunit-polyfills": "^1.0" + "phpcompatibility/php-compatibility": "^9.0" }, "type": "composer-plugin", "extra": { - "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" }, "autoload": { "psr-4": { - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -503,7 +552,7 @@ }, { "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -527,37 +576,37 @@ "tests" ], "support": { - "issues": "https://github.com/PHPCSStandards/composer-installer/issues", - "source": "https://github.com/PHPCSStandards/composer-installer" + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" }, - "time": "2023-01-05T11:28:13+00:00" + "time": "2022-02-04T12:51:07+00:00" }, { "name": "doctrine/instantiator", - "version": "2.0.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "shasum": "" }, "require": { - "php": "^8.1" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^11", + "doctrine/coding-standard": "^9 || ^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.9.4", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5.27", - "vimeo/psalm": "^5.4" + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.30 || ^5.4" }, "type": "library", "autoload": { @@ -584,7 +633,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.0" + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" }, "funding": [ { @@ -600,7 +649,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:23:10+00:00" + "time": "2022-12-30T00:15:36+00:00" }, { "name": "fabpot/goutte", @@ -662,6 +711,62 @@ "abandoned": "symfony/browser-kit", "time": "2020-11-01T09:30:18+00:00" }, + { + "name": "fig-r/psr2r-sniffer", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig-rectified/psr2r-sniffer.git", + "reference": "53ca1ecd62b0dc2ab8ea48635f583cb361c5e8f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig-rectified/psr2r-sniffer/zipball/53ca1ecd62b0dc2ab8ea48635f583cb361c5e8f2", + "reference": "53ca1ecd62b0dc2ab8ea48635f583cb361c5e8f2", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "slevomat/coding-standard": "^7.2.0 || ^8.3.0", + "spryker/code-sniffer": "^0.17.1", + "squizlabs/php_codesniffer": "^3.7.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.0.0" + }, + "bin": [ + "bin/tokenize", + "bin/sniff" + ], + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "PSR2R\\": "PSR2R/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Scherer", + "homepage": "https://www.dereuromark.de", + "role": "Contributor" + } + ], + "description": "Code-Sniffer, Auto-Fixer and Tokenizer for PSR2-R", + "keywords": [ + "codesniffer", + "cs", + "static analysis" + ], + "support": { + "issues": "https://github.com/php-fig-rectified/psr2r-sniffer/issues", + "source": "https://github.com/php-fig-rectified/psr2r-sniffer/tree/1.5.0" + }, + "time": "2023-01-01T15:31:05+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.5.8", @@ -1083,16 +1188,16 @@ }, { "name": "pantheon-systems/pantheon-wordpress-upstream-tests", - "version": "dev-fix-behat-upstream-tests", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/pantheon-systems/pantheon-wordpress-upstream-tests.git", - "reference": "0398d7183db0ad3ab0bf6c65c39174f297ad2c49" + "reference": "1a0d50c12413b3643a24b578a23b819f11e35ebf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pantheon-systems/pantheon-wordpress-upstream-tests/zipball/0398d7183db0ad3ab0bf6c65c39174f297ad2c49", - "reference": "0398d7183db0ad3ab0bf6c65c39174f297ad2c49", + "url": "https://api.github.com/repos/pantheon-systems/pantheon-wordpress-upstream-tests/zipball/1a0d50c12413b3643a24b578a23b819f11e35ebf", + "reference": "1a0d50c12413b3643a24b578a23b819f11e35ebf", "shasum": "" }, "require": { @@ -1100,6 +1205,7 @@ "behat/mink-extension": "^2.2", "behat/mink-goutte-driver": "^1.2" }, + "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -1115,9 +1221,51 @@ ], "support": { "issues": "https://github.com/pantheon-systems/pantheon-wordpress-upstream-tests/issues", - "source": "https://github.com/pantheon-systems/pantheon-wordpress-upstream-tests/tree/fix-behat-upstream-tests" + "source": "https://github.com/pantheon-systems/pantheon-wordpress-upstream-tests/tree/master" + }, + "time": "2020-04-17T11:46:11+00:00" + }, + { + "name": "pantheon-systems/pantheon-wp-coding-standards", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/pantheon-systems/Pantheon-WP-Coding-Standards.git", + "reference": "1e8fb654d52b9274f548c46f89d98f4913307fdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pantheon-systems/Pantheon-WP-Coding-Standards/zipball/1e8fb654d52b9274f548c46f89d98f4913307fdf", + "reference": "1e8fb654d52b9274f548c46f89d98f4913307fdf", + "shasum": "" + }, + "require": { + "automattic/vipwpcs": "^2.3", + "fig-r/psr2r-sniffer": "^1.5", + "phpcompatibility/phpcompatibility-wp": "^2.1", + "wp-coding-standards/wpcs": "^2.3" + }, + "require-dev": { + "phpunit/phpunit": "9.6.x-dev", + "yoast/phpunit-polyfills": "1.x-dev" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Pantheon", + "email": "noreply@pantheon.io" + } + ], + "description": "PHPCS Rulesets for WordPress projects on Pantheon.", + "support": { + "issues": "https://github.com/pantheon-systems/Pantheon-WP-Coding-Standards/issues", + "source": "https://github.com/pantheon-systems/Pantheon-WP-Coding-Standards/tree/1.0.1" }, - "time": "2023-04-21T22:01:33+00:00" + "time": "2023-04-14T16:54:02+00:00" }, { "name": "phar-io/manifest", @@ -1293,141 +1441,161 @@ "time": "2019-12-27T09:44:58+00:00" }, { - "name": "phpcsstandards/phpcsextra", - "version": "1.0.3", + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.2", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", - "reference": "7029c051cd310e2e17c6caea3429bfbe290c41ae" + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/7029c051cd310e2e17c6caea3429bfbe290c41ae", - "reference": "7029c051cd310e2e17c6caea3429bfbe290c41ae", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", "shasum": "" }, "require": { - "php": ">=5.4", - "phpcsstandards/phpcsutils": "^1.0", - "squizlabs/php_codesniffer": "^3.7.1" + "phpcompatibility/php-compatibility": "^9.0" }, "require-dev": { - "php-parallel-lint/php-console-highlighter": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", - "phpcsstandards/phpcsdevcs": "^1.1.5", - "phpcsstandards/phpcsdevtools": "^1.2.0", - "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" }, - "type": "phpcodesniffer-standard", - "extra": { - "branch-alias": { - "dev-stable": "1.x-dev", - "dev-develop": "1.x-dev" - } + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, + "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-3.0-or-later" ], "authors": [ { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", + "name": "Wim Godden", "role": "lead" }, { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + "name": "Juliette Reinders Folmer", + "role": "lead" } ], - "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", "keywords": [ - "PHP_CodeSniffer", - "phpcbf", - "phpcodesniffer-standard", + "compatibility", + "paragonie", "phpcs", + "polyfill", "standards", "static analysis" ], "support": { - "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", - "source": "https://github.com/PHPCSStandards/PHPCSExtra" + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" }, - "time": "2023-03-28T17:48:27+00:00" + "time": "2022-10-25T01:46:02+00:00" }, { - "name": "phpcsstandards/phpcsutils", - "version": "1.0.5", + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.4", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", - "reference": "0cfef5193e68e8ff179333d8ae937db62939b656" + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/0cfef5193e68e8ff179333d8ae937db62939b656", - "reference": "0cfef5193e68e8ff179333d8ae937db62939b656", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", - "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.7.1 || 4.0.x-dev@dev" + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" }, "require-dev": { - "ext-filter": "*", - "php-parallel-lint/php-console-highlighter": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", - "phpcsstandards/phpcsdevcs": "^1.1.3", - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.3", - "yoast/phpunit-polyfills": "^1.0.1" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7" }, - "type": "phpcodesniffer-standard", - "extra": { - "branch-alias": { - "dev-stable": "1.x-dev", - "dev-develop": "1.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHPCSUtils/" - ] + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, + "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-3.0-or-later" ], "authors": [ { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", + "name": "Wim Godden", "role": "lead" }, { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + "name": "Juliette Reinders Folmer", + "role": "lead" } ], - "description": "A suite of utility functions for use with PHP_CodeSniffer", - "homepage": "https://phpcsutils.com/", + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", "keywords": [ - "PHP_CodeSniffer", - "phpcbf", - "phpcodesniffer-standard", + "compatibility", "phpcs", - "phpcs3", "standards", "static analysis", - "tokens", - "utility" + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2022-10-24T09:00:36+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.20.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", + "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { - "docs": "https://phpcsutils.com/", - "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", - "source": "https://github.com/PHPCSStandards/PHPCSUtils" + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.4" }, - "time": "2023-04-17T16:27:27+00:00" + "time": "2023-05-02T09:19:37+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3009,6 +3177,187 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.11.16", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "dc5582dc5a93a235557af73e523c389aac9a8e88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/dc5582dc5a93a235557af73e523c389aac9a8e88", + "reference": "dc5582dc5a93a235557af73e523c389aac9a8e88", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpcsstandards/phpcsdevcs": "^1.1", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "sirbrillig/phpcs-import-detection": "^1.1", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2023-03-31T16:46:32+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "8.11.1", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "af87461316b257e46e15bb041dca6fca3796d822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/af87461316b257e46e15bb041dca6fca3796d822", + "reference": "af87461316b257e46e15bb041dca6fca3796d822", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": ">=1.20.0 <1.21.0", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.14", + "phpstan/phpstan-deprecation-rules": "1.1.3", + "phpstan/phpstan-phpunit": "1.3.11", + "phpstan/phpstan-strict-rules": "1.5.1", + "phpunit/phpunit": "7.5.20|8.5.21|9.6.6|10.1.1" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.11.1" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2023-04-24T08:19:01+00:00" + }, + { + "name": "spryker/code-sniffer", + "version": "0.17.18", + "source": { + "type": "git", + "url": "https://github.com/spryker/code-sniffer.git", + "reference": "5fb8b573abc4a906d0d364a4a03abd38e565ba29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spryker/code-sniffer/zipball/5fb8b573abc4a906d0d364a4a03abd38e565ba29", + "reference": "5fb8b573abc4a906d0d364a4a03abd38e565ba29", + "shasum": "" + }, + "require": { + "php": ">=7.4", + "slevomat/coding-standard": "^7.2.0 || ^8.0.1", + "squizlabs/php_codesniffer": "^3.6.2" + }, + "require-dev": { + "phpstan/phpstan": "^1.0.0", + "phpunit/phpunit": "^9.5" + }, + "bin": [ + "bin/tokenize" + ], + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "Spryker\\": "Spryker/", + "SprykerStrict\\": "SprykerStrict/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Spryker", + "homepage": "https://spryker.com" + } + ], + "description": "Spryker Code Sniffer Standards", + "homepage": "https://spryker.com", + "keywords": [ + "codesniffer", + "framework", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/spryker/code-sniffer/issues", + "source": "https://github.com/spryker/code-sniffer" + }, + "time": "2023-01-03T16:08:22+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.7.2", @@ -3469,25 +3818,25 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.2.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e" + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", "shasum": "" }, "require": { - "php": ">=8.1" + "php": ">=8.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.3-dev" + "dev-main": "3.0-dev" }, "thanks": { "name": "symfony/contracts", @@ -3516,7 +3865,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2" }, "funding": [ { @@ -3532,7 +3881,7 @@ "type": "tidelift" } ], - "time": "2023-03-01T10:25:55+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "symfony/dom-crawler", @@ -3695,20 +4044,20 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.2.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "0ad3b6f1e4e2da5690fefe075cd53a238646d8dd" + "reference": "7bc61cc2db649b4637d331240c5346dcc7708051" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/0ad3b6f1e4e2da5690fefe075cd53a238646d8dd", - "reference": "0ad3b6f1e4e2da5690fefe075cd53a238646d8dd", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/7bc61cc2db649b4637d331240c5346dcc7708051", + "reference": "7bc61cc2db649b4637d331240c5346dcc7708051", "shasum": "" }, "require": { - "php": ">=8.1", + "php": ">=8.0.2", "psr/event-dispatcher": "^1" }, "suggest": { @@ -3717,7 +4066,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.3-dev" + "dev-main": "3.0-dev" }, "thanks": { "name": "symfony/contracts", @@ -3754,7 +4103,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.2.1" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.0.2" }, "funding": [ { @@ -3770,7 +4119,7 @@ "type": "tidelift" } ], - "time": "2023-03-01T10:32:47+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "symfony/filesystem", @@ -4655,20 +5004,20 @@ }, { "name": "symfony/string", - "version": "v6.2.8", + "version": "v6.0.19", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "193e83bbd6617d6b2151c37fff10fa7168ebddef" + "reference": "d9e72497367c23e08bf94176d2be45b00a9d232a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/193e83bbd6617d6b2151c37fff10fa7168ebddef", - "reference": "193e83bbd6617d6b2151c37fff10fa7168ebddef", + "url": "https://api.github.com/repos/symfony/string/zipball/d9e72497367c23e08bf94176d2be45b00a9d232a", + "reference": "d9e72497367c23e08bf94176d2be45b00a9d232a", "shasum": "" }, "require": { - "php": ">=8.1", + "php": ">=8.0.2", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.0", "symfony/polyfill-intl-normalizer": "~1.0", @@ -4680,7 +5029,6 @@ "require-dev": { "symfony/error-handler": "^5.4|^6.0", "symfony/http-client": "^5.4|^6.0", - "symfony/intl": "^6.2", "symfony/translation-contracts": "^2.0|^3.0", "symfony/var-exporter": "^5.4|^6.0" }, @@ -4721,7 +5069,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.2.8" + "source": "https://github.com/symfony/string/tree/v6.0.19" }, "funding": [ { @@ -4737,7 +5085,7 @@ "type": "tidelift" } ], - "time": "2023-03-20T16:06:02+00:00" + "time": "2023-01-01T08:36:10+00:00" }, { "name": "symfony/translation", @@ -4908,20 +5256,20 @@ }, { "name": "symfony/yaml", - "version": "v6.2.10", + "version": "v6.0.19", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "61916f3861b1e9705b18cfde723921a71dd1559d" + "reference": "deec3a812a0305a50db8ae689b183f43d915c884" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/61916f3861b1e9705b18cfde723921a71dd1559d", - "reference": "61916f3861b1e9705b18cfde723921a71dd1559d", + "url": "https://api.github.com/repos/symfony/yaml/zipball/deec3a812a0305a50db8ae689b183f43d915c884", + "reference": "deec3a812a0305a50db8ae689b183f43d915c884", "shasum": "" }, "require": { - "php": ">=8.1", + "php": ">=8.0.2", "symfony/polyfill-ctype": "^1.8" }, "conflict": { @@ -4962,7 +5310,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v6.2.10" + "source": "https://github.com/symfony/yaml/tree/v6.0.19" }, "funding": [ { @@ -4978,7 +5326,7 @@ "type": "tidelift" } ], - "time": "2023-04-28T13:25:36+00:00" + "time": "2023-01-11T11:50:03+00:00" }, { "name": "theseer/tokenizer", @@ -5032,36 +5380,31 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "dev-develop", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "fca9d9ef2dcd042658ccb9df16552f5048e7bb04" + "reference": "7da1894633f168fe244afc6de00d141f27517b62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/fca9d9ef2dcd042658ccb9df16552f5048e7bb04", - "reference": "fca9d9ef2dcd042658ccb9df16552f5048e7bb04", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", + "reference": "7da1894633f168fe244afc6de00d141f27517b62", "shasum": "" }, "require": { - "ext-filter": "*", "php": ">=5.4", - "phpcsstandards/phpcsextra": "^1.0", - "phpcsstandards/phpcsutils": "^1.0.5", - "squizlabs/php_codesniffer": "^3.7.2" + "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { - "php-parallel-lint/php-console-highlighter": "^1.0.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", "phpcompatibility/php-compatibility": "^9.0", - "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpcsstandards/phpcsdevtools": "^1.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { - "ext-mbstring": "For improved results" + "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." }, - "default-branch": true, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ @@ -5077,7 +5420,6 @@ "keywords": [ "phpcs", "standards", - "static analysis", "wordpress" ], "support": { @@ -5085,7 +5427,7 @@ "source": "https://github.com/WordPress/WordPress-Coding-Standards", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, - "time": "2023-05-01T08:34:06+00:00" + "time": "2020-05-13T23:57:56+00:00" }, { "name": "yoast/phpunit-polyfills", @@ -5148,18 +5490,10 @@ "time": "2023-03-30T23:39:05+00:00" } ], - "aliases": [ - { - "package": "wp-coding-standards/wpcs", - "version": "dev-develop", - "alias": "2.3.1", - "alias_normalized": "2.3.1.0" - } - ], + "aliases": [], "minimum-stability": "stable", "stability-flags": { - "pantheon-systems/pantheon-wordpress-upstream-tests": 20, - "wp-coding-standards/wpcs": 20 + "pantheon-systems/pantheon-wordpress-upstream-tests": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/object-cache.php b/object-cache.php index 290d950..e849c2c 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1,10 +1,12 @@ _exists( $key, $group ) ) { return false; } @@ -629,7 +622,7 @@ public function delete_group( $group ) { * @return bool Always returns true */ public function flush( $redis = true ) { - $this->cache = array(); + $this->cache = []; if ( $redis ) { $this->_call_redis( 'flushdb' ); } @@ -658,15 +651,14 @@ public function get( $key, $group = 'default', $force = false, &$found = null ) $group = 'default'; } - // Key is set internally, so we can use this value + // Key is set internally, so we can use this value. if ( $this->_isset_internal( $key, $group ) && ! $force ) { $this->cache_hits += 1; $found = true; return $this->_get_internal( $key, $group ); } - // Not a persistent group, so don't try Redis if the value doesn't exist - // internally + // Not a persistent group, so don't try Redis if the value doesn't exist internally. if ( ! $this->_should_persist( $group ) ) { $this->cache_misses += 1; $found = false; @@ -681,14 +673,14 @@ public function get( $key, $group = 'default', $force = false, &$found = null ) $value = $this->_call_redis( 'get', $id ); } - // PhpRedis returns `false` when the key doesn't exist + // PhpRedis returns `false` when the key doesn't exist. if ( false === $value ) { $this->cache_misses += 1; $found = false; return false; } - // All non-numeric values are serialized + // All non-numeric values are serialized. $value = is_numeric( $value ) ? intval( $value ) : unserialize( $value ); $this->_set_internal( $key, $group, $value ); @@ -711,7 +703,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) { $group = 'default'; } - $cache = array(); + $cache = []; if ( ! $this->_should_persist( $group ) ) { foreach ( $keys as $key ) { $cache[ $key ] = $this->_isset_internal( $key, $group ) ? $this->_get_internal( $key, $group ) : false; @@ -739,7 +731,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) { $results = $this->_call_redis( 'hmGet', $redis_safe_group, $remaining_keys ); $results = is_array( $results ) ? array_values( $results ) : $results; } else { - $ids = array(); + $ids = []; foreach ( $remaining_keys as $key ) { $ids[] = $this->_key( $key, $group ); } @@ -749,7 +741,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) { foreach ( $remaining_keys as $i => $key ) { $value = isset( $results[ $i ] ) ? $results[ $i ] : false; if ( false !== $value ) { - // All non-numeric values are serialized + // All non-numeric values are serialized. $value = is_numeric( $value ) ? intval( $value ) : unserialize( $value ); $this->_set_internal( $key, $group, $value ); $this->cache_hits++; @@ -759,7 +751,7 @@ public function get_multiple( $keys, $group = 'default', $force = false ) { $cache[ $key ] = $value; } // Make sure return values are returned in the order of the passed keys. - $return_cache = array(); + $return_cache = []; foreach ( $keys as $key ) { $return_cache[ $key ] = isset( $cache[ $key ] ) ? $cache[ $key ] : false; } @@ -780,7 +772,7 @@ public function incr( $key, $offset = 1, $group = 'default' ) { $group = 'default'; } - // The key needs to exist in order to be incremented + // The key needs to exist in order to be incremented. if ( ! $this->_exists( $key, $group ) ) { return false; } @@ -826,6 +818,7 @@ public function incr( $key, $offset = 1, $group = 'default' ) { /** * Replace the contents in the cache, if contents already exist + * * @see WP_Object_Cache::set() * * @param int|string $key What to call the contents in the cache @@ -895,7 +888,7 @@ public function set( $key, $data, $group = 'default', $expire = WP_REDIS_DEFAULT $data = serialize( $data ); } - // Redis doesn't support expire on hash group keys + // Redis doesn't support expire on hash group keys. if ( $this->_should_use_redis_hashes( $group ) ) { $redis_safe_group = $this->_key( '', $group ); $this->_call_redis( 'hSet', $redis_safe_group, $key, $data ); @@ -922,7 +915,7 @@ public function stats() { foreach ( $this->redis_calls as $method => $calls ) { $total_redis_calls += $calls; } - $out = array(); + $out = []; $out[] = '

'; $out[] = 'Cache Hits:' . (int) $this->cache_hits . '
'; $out[] = 'Cache Misses:' . (int) $this->cache_misses . '
'; @@ -937,9 +930,7 @@ public function stats() { $out[] = '

  • Group: ' . esc_html( $group ) . ' - ( ' . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )
  • '; } $out[] = ''; - // @codingStandardsIgnoreStart - echo implode( PHP_EOL, $out ); - // @codingStandardsIgnoreEnd + echo implode( PHP_EOL, $out ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** @@ -957,6 +948,9 @@ public function switch_to_blog( $blog_id ) { /** * Utility function to determine whether a key exists in the cache. * + * @param string $key The key to check for existence. + * @param string $group The group to which the key belongs. + * * @access protected */ protected function _exists( $key, $group ) { @@ -979,8 +973,8 @@ protected function _exists( $key, $group ) { /** * Check whether there's a value in the internal object cache. * - * @param string $key - * @param string $group + * @param string $key The key to check for existence. + * @param string $group The group to which the key belongs. * @return boolean */ protected function _isset_internal( $key, $group ) { @@ -996,8 +990,8 @@ protected function _isset_internal( $key, $group ) { /** * Get a value from the internal object cache * - * @param string $key - * @param string $group + * @param string $key The key to the value to get. + * @param string $group The group to which the key belongs. * @return mixed */ protected function _get_internal( $key, $group ) { @@ -1022,15 +1016,15 @@ protected function _get_internal( $key, $group ) { /** * Set a value to the internal object cache * - * @param string $key - * @param string $group - * @param mixed $value + * @param string $key The key to the value to set. + * @param string $group The group to which the key belongs. + * @param mixed $value The value to set. */ protected function _set_internal( $key, $group, $value ) { if ( $this->_should_use_redis_hashes( $group ) ) { $multisite_safe_group = $this->multisite && ! isset( $this->global_groups[ $group ] ) ? $this->blog_prefix . $group : $group; if ( ! isset( $this->cache[ $multisite_safe_group ] ) ) { - $this->cache[ $multisite_safe_group ] = array(); + $this->cache[ $multisite_safe_group ] = []; } $this->cache[ $multisite_safe_group ][ $key ] = $value; } else { @@ -1042,8 +1036,8 @@ protected function _set_internal( $key, $group, $value ) { /** * Unset a value from the internal object cache * - * @param string $key - * @param string $group + * @param string $key The key to the value to unset. + * @param string $group The group to which the key belongs. */ protected function _unset_internal( $key, $group ) { if ( $this->_should_use_redis_hashes( $group ) ) { @@ -1109,7 +1103,7 @@ protected function _should_use_redis_hashes( $group ) { protected function _connect_redis() { global $redis_server; - $check_dependencies = array( $this, 'check_client_dependencies' ); + $check_dependencies = [ $this, 'check_client_dependencies' ]; /** * Permits alternate dependency check mechanism to be used. * @@ -1125,34 +1119,34 @@ protected function _connect_redis() { $client_parameters = $this->build_client_parameters( $redis_server ); try { - $client_connection = array( $this, 'prepare_client_connection' ); + $client_connection = [ $this, 'prepare_client_connection' ]; /** * Permits alternate initial client connection mechanism to be used. * * @param callable $client_connection Callback to execute. */ $client_connection = apply_filters( 'wp_redis_prepare_client_connection_callback', $client_connection ); - $this->redis = call_user_func_array( $client_connection, array( $client_parameters ) ); + $this->redis = call_user_func_array( $client_connection, [ $client_parameters ] ); } catch ( Exception $e ) { $this->_exception_handler( $e ); $this->is_redis_connected = false; return $this->is_redis_connected; } - $keys_methods = array( + $keys_methods = [ 'auth' => 'auth', 'database' => 'select', - ); + ]; try { - $setup_connection = array( $this, 'perform_client_connection' ); + $setup_connection = [ $this, 'perform_client_connection' ]; /** * Permits alternate setup client connection mechanism to be used. * * @param callable $setup_connection Callback to execute. */ $setup_connection = apply_filters( 'wp_redis_perform_client_connection_callback', $setup_connection ); - call_user_func_array( $setup_connection, array( $this->redis, $client_parameters, $keys_methods ) ); + call_user_func_array( $setup_connection, [ $this->redis, $client_parameters, $keys_methods ] ); } catch ( Exception $e ) { $this->_exception_handler( $e ); $this->is_redis_connected = false; @@ -1191,38 +1185,37 @@ public function build_client_parameters( $redis_server ) { if ( empty( $redis_server ) ) { // Attempt to automatically load Pantheon's Redis config from the env. if ( isset( $_SERVER['CACHE_HOST'] ) ) { - $redis_server = array( - 'host' => $_SERVER['CACHE_HOST'], - 'port' => $_SERVER['CACHE_PORT'], - 'auth' => $_SERVER['CACHE_PASSWORD'], - 'database' => isset( $_SERVER['CACHE_DB'] ) ? $_SERVER['CACHE_DB'] : 0, - ); + $redis_server = [ + 'host' => wp_strip_all_tags( $_SERVER['CACHE_HOST'] ), + 'port' => isset( $_SERVER['CACHE_PORT'] ) ? wp_strip_all_tags( $_SERVER['CACHE_PORT'] ) : 0, + 'auth' => isset( $_SERVER['CACHE_PASSWORD'] ) ? wp_strip_all_tags( $_SERVER['CACHE_PASSWORD'] ) : '', + 'database' => isset( $_SERVER['CACHE_DB'] ) ? wp_strip_all_tags( $_SERVER['CACHE_DB'] ) : 0, + ]; } else { - $redis_server = array( - 'host' => '127.0.0.1', - 'port' => 6379, + $redis_server = [ + 'host' => '127.0.0.1', + 'port' => 6379, 'database' => 0, - ); + ]; } } - if ( file_exists( $redis_server['host'] ) && 'socket' === filetype( $redis_server['host'] ) ) { //unix socket connection - //port must be null or socket won't connect + if ( file_exists( $redis_server['host'] ) && 'socket' === filetype( $redis_server['host'] ) ) { // unix socket connection. + // port must be null or socket won't connect. $port = null; - } else { //tcp connection + } else { // tcp connection. $port = ! empty( $redis_server['port'] ) ? $redis_server['port'] : 6379; } - $defaults = array( - 'host' => $redis_server['host'], - 'port' => $port, - 'timeout' => 1000, // I multiplied this by 1000 so we'd have a common measure of ms instead of s and ms, need to make sure this gets divided by 1000 + $defaults = [ + 'host' => $redis_server['host'], + 'port' => $port, + 'timeout' => 1000, // I multiplied this by 1000 so we'd have a common measure of ms instead of s and ms, need to make sure this gets divided by 1000. 'retry_interval' => 100, - ); - // 1s timeout, 100ms delay between reconnections + ]; + // 1s timeout, 100ms delay between reconnections. - // merging the defaults with the original $redis_server enables any - // custom parameters to get sent downstream to the redis client. + // merging the defaults with the original $redis_server enables any custom parameters to get sent downstream to the redis client. return array_replace_recursive( $redis_server, $defaults ); } @@ -1234,16 +1227,15 @@ public function build_client_parameters( $redis_server ) { */ public function prepare_client_connection( $client_parameters ) { if ( defined( 'WP_REDIS_USE_RELAY' ) && WP_REDIS_USE_RELAY ) { - $redis = new Relay\Relay; + $redis = new Relay\Relay(); } else { - $redis = new Redis; + $redis = new Redis(); } $redis->connect( $client_parameters['host'], $client_parameters['port'], - // $client_parameters['timeout'] is sent in milliseconds, - // connect() takes seconds, so divide by 1000 + // $client_parameters['timeout'] is sent in milliseconds, connect() takes seconds, so divide by 1000. $client_parameters['timeout'] / 1000, null, $client_parameters['retry_interval'] @@ -1259,6 +1251,7 @@ public function prepare_client_connection( $client_parameters ) { * @param array $client_parameters Parameters used to configure Redis. * @param array $keys_methods Associative array of keys from * $client_parameters to use as method arguments for $redis. + * @throws Exception If the connection fails. * @return bool True if successful. */ public function perform_client_connection( $redis, $client_parameters, $keys_methods ) { @@ -1281,17 +1274,17 @@ public function perform_client_connection( $redis, $client_parameters, $keys_met /** * Wrapper method for calls to Redis, which fails gracefully when Redis is unavailable * - * @param string $method - * @param mixed $args - * @return mixed + * @param string $method The name of the Redis method to call. + * @throws Exception If the connection fails. + * @return mixed The return value of the Redis method, or false if Redis is unavailable. */ protected function _call_redis( $method ) { global $wpdb; $arguments = func_get_args(); - array_shift( $arguments ); // ignore $method + array_shift( $arguments ); // ignore $method. - // $group is intended for the failback, and isn't passed to the Redis callback + // $group is intended for the failback, and isn't passed to the Redis callback. if ( 'hIncrBy' === $method ) { $group = array_pop( $arguments ); } @@ -1302,7 +1295,7 @@ protected function _call_redis( $method ) { $this->redis_calls[ $method ] = 0; } $this->redis_calls[ $method ]++; - $retval = call_user_func_array( array( $this->redis, $method ), $arguments ); + $retval = call_user_func_array( [ $this->redis, $method ], $arguments ); return $retval; } catch ( Exception $e ) { $retry_exception_messages = $this->retry_exception_messages(); @@ -1312,17 +1305,16 @@ protected function _call_redis( $method ) { $this->_exception_handler( $e ); - // Attempt to refresh the connection if it was successfully established once - // $this->is_redis_connected will be set inside _connect_redis() + // Attempt to refresh the connection if it was successfully established once $this->is_redis_connected will be set inside _connect_redis(). if ( $this->_connect_redis() ) { - return call_user_func_array( array( $this, '_call_redis' ), array_merge( array( $method ), $arguments ) ); + return call_user_func_array( [ $this, '_call_redis' ], array_merge( [ $method ], $arguments ) ); } - // Fall through to fallback below + // Fall through to fallback below. } else { throw $e; } } - } // End if(). + } // End if. if ( $this->is_redis_failback_flush_enabled() && ! $this->do_redis_failback_flush && ! empty( $wpdb ) ) { if ( $this->multisite ) { @@ -1334,13 +1326,11 @@ protected function _call_redis( $method ) { $col1 = 'option_name'; $col2 = 'option_value'; } - // @codingStandardsIgnoreStart $wpdb->query( "INSERT IGNORE INTO {$table} ({$col1},{$col2}) VALUES ('wp_redis_do_redis_failback_flush',1)" ); - // @codingStandardsIgnoreEnd $this->do_redis_failback_flush = true; } - // Mock expected behavior from Redis for these methods + // Mock expected behavior from Redis for these methods. switch ( $method ) { case 'incr': case 'incrBy': @@ -1379,7 +1369,7 @@ protected function _call_redis( $method ) { * @return array Array of expected exception messages */ public function retry_exception_messages() { - $retry_exception_messages = array( 'socket error on read socket', 'Connection closed', 'Redis server went away' ); + $retry_exception_messages = [ 'socket error on read socket', 'Connection closed', 'Redis server went away' ]; return apply_filters( 'wp_redis_retry_exception_messages', $retry_exception_messages ); } @@ -1417,20 +1407,16 @@ protected function _format_message_for_pattern( $message ) { /** * Handles exceptions by triggering a php error. * - * @param Exception $exception - * @return null + * @param Exception $exception The exception to handle. + * @return void */ protected function _exception_handler( $exception ) { try { $this->last_triggered_error = 'WP Redis: ' . $exception->getMessage(); - // Be friendly to developers debugging production servers by triggering an error - // @codingStandardsIgnoreStart - trigger_error( $this->last_triggered_error, E_USER_WARNING ); - // @codingStandardsIgnoreEnd - } catch ( PHPUnit_Framework_Error_Warning $e ) { - // PHPUnit throws an Exception when `trigger_error()` is called. - // To ensure our tests (which expect Exceptions to be caught) continue to run, - // we catch the PHPUnit exception and inspect the RedisException message + // Be friendly to developers debugging production servers by triggering an error. + trigger_error( esc_html( $this->last_triggered_error ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error + } catch ( PHPUnit_Framework_Error_Warning $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch + // PHPUnit throws an Exception when `trigger_error()` is called. To ensure our tests (which expect Exceptions to be caught) continue to run, we catch the PHPUnit exception and inspect the RedisException message. } } @@ -1460,8 +1446,6 @@ private function is_redis_failback_flush_enabled() { /** * Sets up object properties; PHP 5 style constructor - * - * @return null|WP_Object_Cache If cache is disabled, returns null. */ public function __construct() { global $blog_id, $table_prefix, $wpdb; @@ -1470,7 +1454,7 @@ public function __construct() { $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; if ( ! $this->_connect_redis() && function_exists( 'add_action' ) ) { - add_action( 'admin_notices', array( $this, 'wp_action_admin_notices_warn_missing_redis' ) ); + add_action( 'admin_notices', [ $this, 'wp_action_admin_notices_warn_missing_redis' ] ); } if ( $this->is_redis_failback_flush_enabled() && ! empty( $wpdb ) ) { @@ -1483,15 +1467,11 @@ public function __construct() { $col1 = 'option_name'; $col2 = 'option_value'; } - // @codingStandardsIgnoreStart $this->do_redis_failback_flush = (bool) $wpdb->get_results( "SELECT {$col2} FROM {$table} WHERE {$col1}='wp_redis_do_redis_failback_flush'" ); - // @codingStandardsIgnoreEnd if ( $this->is_redis_connected && $this->do_redis_failback_flush ) { $ret = $this->_call_redis( 'flushdb' ); if ( $ret ) { - // @codingStandardsIgnoreStart $wpdb->query( "DELETE FROM {$table} WHERE {$col1}='wp_redis_do_redis_failback_flush'" ); - // @codingStandardsIgnoreEnd $this->do_redis_failback_flush = false; } } @@ -1499,11 +1479,8 @@ public function __construct() { $this->global_prefix = ( $this->multisite || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix; - /** - * @todo This should be moved to the PHP4 style constructor, PHP5 - * already calls __destruct() - */ - register_shutdown_function( array( $this, '__destruct' ) ); + // @todo This should be moved to the PHP4 style constructor, PHP5 + register_shutdown_function( [ $this, '__destruct' ] ); } /** diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6ca9ae0..897e206 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -9,16 +9,50 @@ + + + + + /object-cache.php + + + + /object-cache.php + + + + /object-cache.php + + + + /object-cache.php + + + + /object-cache.php + + + /object-cache.php + + + + + + /cli.php + + - + */bin/* + */tests/* */vendor/* */node_modules/* + diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index ac7b0c8..d87bad4 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -21,7 +21,7 @@ define( 'WP_REDIS_USE_CACHE_GROUPS', true ); } -define( 'WP_REDIS_IGNORE_GLOBAL_GROUPS', array( 'wp-redis-ignored-group' ) ); +define( 'WP_REDIS_IGNORE_GLOBAL_GROUPS', [ 'wp-redis-ignored-group' ] ); // Easiest way to get this to where WordPress will load it copy( dirname( dirname( dirname( __FILE__ ) ) ) . '/object-cache.php', $_core_dir . '/wp-content/object-cache.php' ); diff --git a/tests/phpunit/test-cache.php b/tests/phpunit/test-cache.php index b893e65..1e5edca 100644 --- a/tests/phpunit/test-cache.php +++ b/tests/phpunit/test-cache.php @@ -23,25 +23,25 @@ class CacheTest extends WP_UnitTestCase { private static $flush_all_key; - private static $client_parameters = array( + private static $client_parameters = [ 'host' => 'localhost', 'port' => 6379, 'timeout' => 1000, 'retry_interval' => 100, - ); + ]; public function setUp(): void { parent::setUp(); - $GLOBALS['redis_server'] = array( + $GLOBALS['redis_server'] = [ 'host' => '127.0.0.1', 'port' => 6379, - ); + ]; // create two cache objects with a shared cache dir // this simulates a typical cache situation, two separate requests interacting $this->cache =& $this->init_cache(); $this->cache->cache_hits = 0; $this->cache->cache_misses = 0; - $this->cache->redis_calls = array(); + $this->cache->redis_calls = []; self::$exists_key = WP_Object_Cache::USE_GROUPS ? 'hExists' : 'exists'; self::$get_key = WP_Object_Cache::USE_GROUPS ? 'hGet' : 'get'; @@ -57,7 +57,7 @@ public function setUp(): void { public function &init_cache() { $cache = new WP_Object_Cache(); - $cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) ); + $cache->add_global_groups( [ 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ] ); return $cache; } @@ -66,24 +66,24 @@ public function test_loaded() { } public function test_connection_details() { - $redis_server = array( + $redis_server = [ 'host' => '127.0.0.1', 'port' => 6379, 'extra' => true, - 'recursive' => array( + 'recursive' => [ 'child' => true, - ), - ); - $expected = array( + ], + ]; + $expected = [ 'host' => '127.0.0.1', 'port' => 6379, 'extra' => true, - 'recursive' => array( + 'recursive' => [ 'child' => true, - ), + ], 'timeout' => 1000, 'retry_interval' => 100, - ); + ]; $actual = $this->cache->build_client_parameters( $redis_server ); $this->assertEquals( $expected, $actual ); } @@ -147,8 +147,8 @@ public function test_redis_reload_force_cache_flush() { $redis_server['host'] = '127.0.0.1'; $redis_server['port'] = 9999; $client_parameters = $this->cache->build_client_parameters( $redis_server ); - $client_connection = apply_filters( 'wp_redis_prepare_client_connection_callback', array( $this->cache, 'prepare_client_connection' ) ); - $this->cache->redis = call_user_func_array( $client_connection, array( $client_parameters ) ); + $client_connection = apply_filters( 'wp_redis_prepare_client_connection_callback', [ $this->cache, 'prepare_client_connection' ] ); + $this->cache->redis = call_user_func_array( $client_connection, [ $client_parameters ] ); // Setting cache value when redis connection fails saves wakeup flush $this->cache->set( 'foo', 'bar' ); $this->assertTrue( @@ -191,7 +191,7 @@ public function test_redis_bad_authentication() { $redis_server['host'] = '127.0.0.1'; $redis_server['port'] = 9999; $redis_server['auth'] = 'foobar'; - $cache = new WP_Object_Cache; + $cache = new WP_Object_Cache(); $this->assertTrue( $cache->exception_message_matches( str_replace( 'WP Redis: ', '', $cache->last_triggered_error ), @@ -210,9 +210,9 @@ public function test_miss() { $this->assertEquals( 1, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -230,10 +230,10 @@ public function test_add_get() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -252,10 +252,10 @@ public function test_add_get_0() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -273,10 +273,10 @@ public function test_add_get_null() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -299,10 +299,10 @@ public function test_add() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -324,11 +324,11 @@ public function test_replace() { $this->assertEquals( $val2, $this->cache->get( $key ) ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 2, self::$set_key => 2, self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -351,9 +351,9 @@ public function test_set() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$set_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -378,12 +378,12 @@ public function test_flush() { $this->assertEquals( 1, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, self::$get_key => 1, self::$flush_all_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -394,7 +394,7 @@ public function test_flush() { // Make sure objects are cloned going to and from the cache public function test_object_refs() { $key = rand_str(); - $object_a = new stdClass; + $object_a = new stdClass(); $object_a->foo = 'alpha'; $this->cache->set( $key, $object_a ); $object_a->foo = 'bravo'; @@ -404,7 +404,7 @@ public function test_object_refs() { $this->assertEquals( 'bravo', $object_a->foo ); $key = rand_str(); - $object_a = new stdClass; + $object_a = new stdClass(); $object_a->foo = 'alpha'; $this->cache->add( $key, $object_a ); $object_a->foo = 'bravo'; @@ -419,15 +419,15 @@ public function test_get_already_exists_internal() { $this->cache->set( $key, 'alpha' ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$set_key => 1, - ), + ], $this->cache->redis_calls ); } else { $this->assertEmpty( $this->cache->redis_calls ); } - $this->cache->redis_calls = array(); // reset to limit scope of test + $this->cache->redis_calls = []; // reset to limit scope of test $this->assertEquals( 'alpha', $this->cache->get( $key ) ); $this->assertEquals( 1, $this->cache->cache_hits ); $this->assertEquals( 0, $this->cache->cache_misses ); @@ -444,9 +444,9 @@ public function test_get_missing_persistent() { $this->assertEquals( 2, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -485,8 +485,8 @@ public function test_get_false_value_persistent_cache() { $this->cache->set( $key, false ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $found = null; $this->assertFalse( $this->cache->get( $key, 'default', false, $found ) ); $this->assertTrue( $found ); @@ -494,9 +494,9 @@ public function test_get_false_value_persistent_cache() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -512,8 +512,8 @@ public function test_get_true_value_persistent_cache() { $this->cache->set( $key, true ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $found = null; $this->assertTrue( $this->cache->get( $key, 'default', false, $found ) ); $this->assertTrue( $found ); @@ -521,9 +521,9 @@ public function test_get_true_value_persistent_cache() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -539,8 +539,8 @@ public function test_get_null_value_persistent_cache() { $this->cache->set( $key, null ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $found = null; $this->assertNull( $this->cache->get( $key, 'default', false, $found ) ); $this->assertTrue( $found ); @@ -548,9 +548,9 @@ public function test_get_null_value_persistent_cache() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -568,8 +568,8 @@ public function test_get_int_values_persistent_cache() { $this->cache->set( $key2, 0xf4c3b00c ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything // Should be upgraded to more strict comparison if change proposed in issue #181 is merged. $this->assertSame( 123, $this->cache->get( $key1 ) ); $this->assertSame( 4106465292, $this->cache->get( $key2 ) ); @@ -577,9 +577,9 @@ public function test_get_int_values_persistent_cache() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -597,17 +597,17 @@ public function test_get_float_values_persistent_cache() { $this->cache->set( $key2, + 0123.45e6 ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $this->assertSame( 123.456, $this->cache->get( $key1 ) ); $this->assertSame( 123450000.0, $this->cache->get( $key2 ) ); $this->assertEquals( 2, $this->cache->cache_hits ); $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -630,8 +630,8 @@ public function test_get_string_values_persistent_cache() { $this->cache->set( $key4, '+0123.45e6' ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $this->assertEquals( 'a plain old string', $this->cache->get( $key1 ) ); $this->assertSame( '42', $this->cache->get( $key2 ) ); $this->assertSame( '123.456', $this->cache->get( $key3 ) ); @@ -640,9 +640,9 @@ public function test_get_string_values_persistent_cache() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 4, - ), + ], $this->cache->redis_calls ); } else { @@ -655,20 +655,20 @@ public function test_get_array_values_persistent_cache() { $this->markTestSkipped( 'PHPRedis extension not available.' ); } $key = rand_str(); - $value = array( 'one', 2, true ); + $value = [ 'one', 2, true ]; $this->cache->set( $key, $value ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $this->assertEquals( $value, $this->cache->get( $key ) ); $this->assertEquals( 1, $this->cache->cache_hits ); $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -681,22 +681,22 @@ public function test_get_object_values_persistent_cache() { $this->markTestSkipped( 'PHPRedis extension not available.' ); } $key = rand_str(); - $value = new stdClass; + $value = new stdClass(); $value->one = 'two'; $value->three = 'four'; $this->cache->set( $key, $value ); $this->cache->cache_hits = 0; // reset everything $this->cache->cache_misses = 0; // reset everything - $this->cache->redis_calls = array(); // reset everything - $this->cache->cache = array(); // reset everything + $this->cache->redis_calls = []; // reset everything + $this->cache->cache = []; // reset everything $this->assertEquals( $value, $this->cache->get( $key ) ); $this->assertEquals( 1, $this->cache->cache_hits ); $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -719,7 +719,7 @@ public function test_get_force() { if ( WP_Object_Cache::USE_GROUPS ) { $multisite_safe_group = $this->cache->multisite && ! isset( $this->cache->global_groups[ $group ] ) ? $this->cache->blog_prefix . $group : $group; if ( ! isset( $this->cache->cache[ $multisite_safe_group ] ) ) { - $this->cache->cache[ $multisite_safe_group ] = array(); + $this->cache->cache[ $multisite_safe_group ] = []; } $this->cache->cache[ $multisite_safe_group ][ $key ] = 'beta'; } else { @@ -737,10 +737,10 @@ public function test_get_force() { $this->assertEquals( 3, $this->cache->cache_hits ); $this->assertEquals( 0, $this->cache->cache_misses ); $this->assertEquals( - array( + [ self::$get_key => 1, self::$set_key => 1, - ), + ], $this->cache->redis_calls ); } @@ -764,23 +764,23 @@ public function test_get_multiple() { $this->cache->set( 'foo2', 'bar', 'group1' ); $this->cache->set( 'foo1', 'bar', 'group2' ); - $found = $this->cache->get_multiple( array( 'foo1', 'foo2', 'foo3' ), 'group1' ); + $found = $this->cache->get_multiple( [ 'foo1', 'foo2', 'foo3' ], 'group1' ); - $expected = array( + $expected = [ 'foo1' => 'bar', 'foo2' => 'bar', 'foo3' => false, - ); + ]; $this->assertSame( $expected, $found ); $this->assertEquals( 2, $this->cache->cache_hits ); $this->assertEquals( 1, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$mget_key => 1, self::$set_key => 3, - ), + ], $this->cache->redis_calls ); } else { @@ -796,44 +796,44 @@ public function test_get_multiple_partial_cache_miss() { $this->cache->set( 'foo2', 'baz', 'group1' ); $this->cache->set( 'foo3', 'bap', 'group1' ); // Reset the internal cache. - $this->cache->cache = array(); + $this->cache->cache = []; // Prime the second item into the internal cache. $this->cache->get( 'foo2', 'group1' ); - $found = $this->cache->get_multiple( array( 'foo1', 'foo2', 'foo3', 'foo4' ), 'group1' ); + $found = $this->cache->get_multiple( [ 'foo1', 'foo2', 'foo3', 'foo4' ], 'group1' ); - $expected = array( + $expected = [ 'foo1' => 'bar', 'foo2' => 'baz', 'foo3' => 'bap', 'foo4' => false, - ); + ]; $this->assertSame( $expected, $found ); $this->assertEquals( 4, $this->cache->cache_hits ); $this->assertEquals( 1, $this->cache->cache_misses ); $this->assertEquals( - array( + [ self::$get_key => 1, self::$mget_key => 1, self::$set_key => 3, - ), + ], $this->cache->redis_calls ); } public function test_get_multiple_non_persistent() { - $this->cache->add_non_persistent_groups( array( 'group1' ) ); + $this->cache->add_non_persistent_groups( [ 'group1' ] ); $this->cache->set( 'foo1', 'bar', 'group1' ); $this->cache->set( 'foo2', 'bar', 'group1' ); - $found = $this->cache->get_multiple( array( 'foo1', 'foo2', 'foo3' ), 'group1' ); + $found = $this->cache->get_multiple( [ 'foo1', 'foo2', 'foo3' ], 'group1' ); - $expected = array( + $expected = [ 'foo1' => 'bar', 'foo2' => 'bar', 'foo3' => false, - ); + ]; $this->assertSame( $expected, $found ); $this->assertEquals( 2, $this->cache->cache_hits ); $this->assertEquals( 1, $this->cache->cache_misses ); @@ -859,11 +859,11 @@ public function test_incr() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, self::$incr_by_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -898,11 +898,11 @@ public function test_incr_separate_groups() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 2, self::$set_key => 2, self::$incr_by_key => 4, - ), + ], $this->cache->redis_calls ); } else { @@ -922,10 +922,10 @@ public function test_incr_never_below_zero() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$incr_by_key => 1, self::$set_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -936,7 +936,7 @@ public function test_incr_never_below_zero() { public function test_incr_non_persistent() { $key = rand_str(); - $this->cache->add_non_persistent_groups( array( 'nonpersistent' ) ); + $this->cache->add_non_persistent_groups( [ 'nonpersistent' ] ); $this->assertFalse( $this->cache->incr( $key, 1, 'nonpersistent' ) ); $this->cache->set( $key, 0, 'nonpersistent' ); @@ -950,7 +950,7 @@ public function test_incr_non_persistent() { public function test_incr_non_persistent_never_below_zero() { $key = rand_str(); - $this->cache->add_non_persistent_groups( array( 'nonpersistent' ) ); + $this->cache->add_non_persistent_groups( [ 'nonpersistent' ] ); $this->cache->set( $key, 1, 'nonpersistent' ); $this->assertEquals( 1, $this->cache->get( $key, 'nonpersistent' ) ); $this->cache->incr( $key, -2, 'nonpersistent' ); @@ -996,11 +996,11 @@ public function test_decr() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 3, self::$decr_by_key => 3, - ), + ], $this->cache->redis_calls ); } else { @@ -1044,11 +1044,11 @@ public function test_decr_separate_groups() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 2, self::$set_key => 7, self::$decr_by_key => 6, - ), + ], $this->cache->redis_calls ); } else { @@ -1068,10 +1068,10 @@ public function test_decr_never_below_zero() { $this->assertEquals( 0, $this->cache->cache_misses ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$decr_by_key => 1, self::$set_key => 2, - ), + ], $this->cache->redis_calls ); } else { @@ -1082,7 +1082,7 @@ public function test_decr_never_below_zero() { public function test_decr_non_persistent() { $key = rand_str(); - $this->cache->add_non_persistent_groups( array( 'nonpersistent' ) ); + $this->cache->add_non_persistent_groups( [ 'nonpersistent' ] ); $this->assertFalse( $this->cache->decr( $key, 1, 'nonpersistent' ) ); $this->cache->set( $key, 0, 'nonpersistent' ); @@ -1100,7 +1100,7 @@ public function test_decr_non_persistent() { public function test_decr_non_persistent_never_below_zero() { $key = rand_str(); - $this->cache->add_non_persistent_groups( array( 'nonpersistent' ) ); + $this->cache->add_non_persistent_groups( [ 'nonpersistent' ] ); $this->cache->set( $key, 1, 'nonpersistent' ); $this->assertEquals( 1, $this->cache->get( $key, 'nonpersistent' ) ); $this->cache->decr( $key, 2, 'nonpersistent' ); @@ -1147,12 +1147,12 @@ public function test_delete() { $this->assertFalse( $this->cache->delete( $key, 'default' ) ); if ( $this->cache->is_redis_connected ) { $this->assertEquals( - array( + [ self::$exists_key => 1, self::$set_key => 1, self::$delete_key => 1, self::$get_key => 1, - ), + ], $this->cache->redis_calls ); } else { @@ -1190,7 +1190,7 @@ public function test_delete_group() { $group2 = 'bar'; if ( ! defined( 'WP_REDIS_USE_CACHE_GROUPS' ) || ! WP_REDIS_USE_CACHE_GROUPS ) { - $this->cache->add_redis_hash_groups( array( $group, $group2 ) ); + $this->cache->add_redis_hash_groups( [ $group, $group2 ] ); } // Set up the values @@ -1224,10 +1224,10 @@ public function test_delete_group_non_persistent() { $val3 = rand_str(); $group = 'foo'; $group2 = 'bar'; - $this->cache->add_non_persistent_groups( array( $group, $group2 ) ); + $this->cache->add_non_persistent_groups( [ $group, $group2 ] ); if ( ! defined( 'WP_REDIS_USE_CACHE_GROUPS' ) || ! WP_REDIS_USE_CACHE_GROUPS ) { - $this->cache->add_redis_hash_groups( array( $group, $group2 ) ); + $this->cache->add_redis_hash_groups( [ $group, $group2 ] ); } // Set up the values @@ -1259,7 +1259,7 @@ public function test_wp_cache_delete_group() { $group2 = 'bar'; if ( ! defined( 'WP_REDIS_USE_CACHE_GROUPS' ) || ! WP_REDIS_USE_CACHE_GROUPS ) { - $GLOBALS['wp_object_cache']->add_redis_hash_groups( array( $group, $group2 ) ); + $GLOBALS['wp_object_cache']->add_redis_hash_groups( [ $group, $group2 ] ); } // Set up the values @@ -1345,7 +1345,7 @@ public function test_redis_connect_custom_database() { $this->markTestSkipped( 'PHPRedis extension not available.' ); } $redis_server['database'] = 2; - $second_cache = new WP_Object_Cache; + $second_cache = new WP_Object_Cache(); $second_cache->flush(); // Make sure it's in pristine state. $this->cache->set( 'foo', 'bar' ); $this->assertEquals( 'bar', $this->cache->get( 'foo' ) ); @@ -1378,9 +1378,9 @@ public function test_wp_cache_replace() { } public function test_ignore_global_groups() { - $this->cache->add_global_groups( array( 'wp-redis-respected-group' ) ); + $this->cache->add_global_groups( [ 'wp-redis-respected-group' ] ); $this->assertTrue( isset( $this->cache->global_groups['wp-redis-respected-group'] ) ); - $this->cache->add_global_groups( array( 'wp-redis-ignored-group' ) ); + $this->cache->add_global_groups( [ 'wp-redis-ignored-group' ] ); $this->assertFalse( isset( $this->cache->global_groups['wp-redis-ignored-group'] ) ); } @@ -1419,7 +1419,7 @@ public function test_setup_connection() { } $redis = $this->cache->prepare_client_connection( self::$client_parameters ); - $isSetUp = $this->cache->perform_client_connection( $redis, array(), array() ); + $isSetUp = $this->cache->perform_client_connection( $redis, [], [] ); $this->assertTrue( $isSetUp ); } @@ -1430,7 +1430,7 @@ public function test_setup_connection_throws_exception() { $redis = $this->getMockBuilder( 'Redis' )->getMock(); $redis->method( 'select' ) - ->will( $this->throwException( new RedisException ) ); + ->will( $this->throwException( new RedisException() ) ); $redis->connect( self::$client_parameters['host'], @@ -1439,12 +1439,12 @@ public function test_setup_connection_throws_exception() { null, self::$client_parameters['retry_interval'] ); - $settings = array( + $settings = [ 'database' => 2, - ); - $keys_methods = array( + ]; + $keys_methods = [ 'database' => 'select', - ); + ]; $this->setExpectedException( 'Exception' ); $this->cache->perform_client_connection( $redis, $settings, $keys_methods ); } diff --git a/wp-redis.php b/wp-redis.php index aedbda0..95fc714 100644 --- a/wp-redis.php +++ b/wp-redis.php @@ -7,7 +7,9 @@ * Author: Pantheon, Josh Koenig, Matthew Boynes, Daniel Bachhuber, Alley Interactive * Author URI: https://pantheon.io/ */ -/* This program is free software; you can redistribute it and/or modify + +/* + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -36,19 +38,19 @@ function wp_redis_get_info() { if ( empty( $redis_server ) ) { // Attempt to automatically load Pantheon's Redis config from the env. - if ( isset( $_SERVER['CACHE_HOST'] ) ) { - $redis_server = array( - 'host' => $_SERVER['CACHE_HOST'], - 'port' => $_SERVER['CACHE_PORT'], - 'auth' => $_SERVER['CACHE_PASSWORD'], - 'database' => isset( $_SERVER['CACHE_DB'] ) ? $_SERVER['CACHE_DB'] : 0, - ); + if ( isset( $_SERVER['CACHE_HOST'] ) && isset( $_SERVER['CACHE_PORT'] ) && isset( $_SERVER['CACHE_PASSWORD'] ) && isset( $_SERVER['CACHE_DB'] ) ) { + $redis_server = [ + 'host' => sanitize_text_field( $_SERVER['CACHE_HOST'] ), + 'port' => sanitize_text_field( $_SERVER['CACHE_PORT'] ), + 'auth' => sanitize_text_field( $_SERVER['CACHE_PASSWORD'] ), + 'database' => sanitize_text_field( $_SERVER['CACHE_DB'] ), + ]; } else { - $redis_server = array( - 'host' => '127.0.0.1', - 'port' => 6379, + $redis_server = [ + 'host' => '127.0.0.1', + 'port' => 6379, 'database' => 0, - ); + ]; } } @@ -76,7 +78,7 @@ function wp_redis_get_info() { if ( isset( $info[ 'db' . $database ] ) && preg_match( '#keys=([\d]+)#', $info[ 'db' . $database ], $matches ) ) { $key_count = $matches[1]; } - return array( + return [ 'status' => 'connected', 'used_memory' => $info['used_memory_human'], 'uptime' => $uptime_in_days, @@ -87,5 +89,5 @@ function wp_redis_get_info() { 'redis_port' => ! empty( $redis_server['port'] ) ? $redis_server['port'] : 6379, 'redis_auth' => ! empty( $redis_server['auth'] ) ? $redis_server['auth'] : '', 'redis_database' => $database, - ); + ]; }