Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/DriverAdapter.php
  • Loading branch information
Jazz-Man committed Apr 3, 2021
2 parents 4cfb3d0 + 03211ee commit dc7faaa
Show file tree
Hide file tree
Showing 8 changed files with 1,081 additions and 999 deletions.
22 changes: 19 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,35 @@
"apcu-autoloader": true
},
"require": {
"php": ">=7.0",
"php": ">=7.1",
"ext-ctype": "*",
"ext-redis": "*",
"composer/installers": "^1",
"jazzman/singleton-trait": "^1.1",
"phpfastcache/phpfastcache": "^7.0"
"roots/wordpress": "^5"
},
"require-dev": {
"dg/composer-cleaner": "^2.1",
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^4.2"
"symfony/var-dumper": "^4.2",
"szepeviktor/phpstan-wordpress": "^0.7.5"
},
"extra": {
"installer-paths": {
"vendor/wp/wp-content/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"vendor/wp/wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
"vendor/wp/wp-content/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "vendor/wp"
},
"autoload": {
"psr-4": {
"JazzMan\\WPObjectCache\\": "src"
}
},
"replace": {
"symfony/polyfill-mbstring": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php72": "*"
}
}
148 changes: 72 additions & 76 deletions include/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,176 +4,172 @@
Plugin Name: WP Object Cache Drop-In
Plugin URI: https://github.com/Jazz-Man/wp-object-cache
Description: Redis, Memcached or Apcu backend for the WP Object Cache
Version: v1.3
Version: v2.0
Author: Vasyl Sokolyk
*/

use JazzMan\WPObjectCache\RedisAdapter;

use JazzMan\WPObjectCache\DriverAdapter;

/**
* @return bool
*/
function wp_cache_close()
function wp_cache_close(): bool
{
return true;
}

/**
* @param string|array $key
* @param $value
* @param string $group
* @param int|\DateInterval|null $expiration
* @param string $key
* @param mixed $value
* @param string $group
* @param int $expiration
*
* @return bool
*/
function wp_cache_add($key, $value, string $group = 'default', $expiration = 0)
function wp_cache_add(string $key, $value, string $group = 'default', int $expiration = 0): bool
{
return wp_object_cache()->add($key, $value, $group, $expiration);
}

/**
* @param string|array $key
* @param int $offset
* @param string $group
*
* @return bool
* @param string $key
* @param int $offset
* @param string $group
* @return bool|int
*/
function wp_cache_decr($key, int $offset = 1, string $group = 'default')
function wp_cache_decr(string $key, int $offset = 1, string $group = 'default')
{
return wp_object_cache()->decrement($key, $offset, $group);
}

/**
* @param string|array $key
* @param string $group
*
* @return bool
* @param string $key
* @param string $group
* @return bool|int
*/
function wp_cache_delete($key, string $group = 'default')
function wp_cache_delete(string $key, string $group = 'default')
{
return wp_object_cache()->delete($key, $group);
}

/**
* @return bool
*/
function wp_cache_flush()
function wp_cache_flush(): bool
{
return wp_object_cache()->flush();
}

/**
* @param string|array $key
* @param string $group
* @param bool $force
* @param bool|null $found
*
* @return mixed
* @param string $key
* @param string $group
* @param bool $force
* @param bool|null $found
* @return bool|mixed
*/
function wp_cache_get($key, string $group = 'default', $force = false, &$found = null)
function wp_cache_get(string $key, string $group = 'default', bool $force = false, bool &$found = null)
{
return wp_object_cache()->get($key, $group, $force, $found);
}

/**
* @param string|array $key
* @param int $offset
* @param string $group
*
* @return bool
* @param string $key
* @param int $offset
* @param string $group
* @return bool|int
*/
function wp_cache_incr($key, int $offset = 1, string $group = 'default')
function wp_cache_incr(string $key, int $offset = 1, string $group = 'default')
{
return wp_object_cache()->increment($key, $offset, $group);
}

/**
* @param string|array $key
* @param mixed|null $value
* @param string $group
* @param int|\DateInterval|null $expiration
*
* @param string $key
* @param mixed $value
* @param string $group
* @param int $expiration
* @return bool
*/
function wp_cache_replace($key, $value = null, string $group = 'default', $expiration = 0)
function wp_cache_replace(string $key, $value = null, string $group = 'default', int $expiration = 0): bool
{
return wp_object_cache()->replace($key, $value, $group, $expiration);
}

/**
* @param string|array $key
* @param mixed|null $value
* @param string $group
* @param int|\DateInterval|null $expiration
*
* @param string $key
* @param mixed $value
* @param string $group
* @param int $expiration
* @return bool
*/
function wp_cache_set($key, $value = null, string $group = 'default', $expiration = 0)
function wp_cache_set(string $key, $value = null, string $group = 'default', int $expiration = 0): bool
{
return wp_object_cache()->set($key, $value, $group, $expiration);
}

/**
* Switch blog prefix, which changes the cache that is accessed.
*
*
* @param int $blog_id blog to switch to
* @param int $blogId
* @return bool
*/
function wp_cache_switch_to_blog($blog_id)
function wp_cache_switch_to_blog(int $blogId): bool
{
wp_object_cache()->switchToBlog($blog_id);
return wp_object_cache()->switchToBlog($blogId);
}

/**
* Adds a group or set of groups to the list of non-persistent groups.
*
*
* @param string|array $groups a group or an array of groups to add
* @param string|string[] $groups a group or an array of groups to add
*/
function wp_cache_add_global_groups($groups)
function wp_cache_add_global_groups($groups): void
{
wp_object_cache()->setGlobalGroups($groups);
wp_object_cache()->addGlobalGroups($groups);
}

/**
* Adds a group or set of groups to the list of non-persistent groups.
*
*
* @param string|array $groups a group or an array of groups to add
* @param string|string[] $groups a group or an array of groups to add
*/
function wp_cache_add_non_persistent_groups($groups)
function wp_cache_add_non_persistent_groups($groups): void
{
wp_object_cache()->setIgnoredGroups($groups);
wp_object_cache()->addNonPersistentGroups($groups);
}

/**
* Sets up Object Cache Global and assigns it.
*/
function wp_cache_init()
function wp_cache_init(): void
{
global $wp_object_cache;

if ( ! ($wp_object_cache instanceof DriverAdapter)) {
$wp_object_cache = new DriverAdapter;
if (!($wp_object_cache instanceof RedisAdapter)) {
$wp_object_cache = new RedisAdapter();
}
}

/**
* @return \Phpfastcache\Entities\DriverStatistic
*/
function wp_object_cache_get_stats()
function wp_object_cache_get_stats(): void
{
return wp_object_cache()->getStats();
wp_object_cache()->stats();
}


/**
* @return DriverAdapter
* @return \JazzMan\WPObjectCache\RedisAdapter
*/
function wp_object_cache()
function wp_object_cache(): RedisAdapter
{
global $wp_object_cache;

return $wp_object_cache;
}

/**
* @return \Redis
*/
function wp_object_cache_instance(): Redis
{
return wp_object_cache()->redisInstance();
}

/**
* @return bool
*/
function wp_object_redis_status(): bool
{
return wp_object_cache()->redisStatus();
}
26 changes: 26 additions & 0 deletions phpmd.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="phpmd-no-controversial"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Enable all rulesets, except Controversial ("camelCase" rules).
Required for WordPress development.
</description>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<!-- common in WP -->
<property name="exceptions" value="id,wp" />
</properties>
</rule>

<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/design.xml">
<!-- normal in WP for redirects, etc -->
<exclude name="ExitExpression" />
</rule>
<rule ref="rulesets/naming.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/cleancode.xml"/>
</ruleset>
38 changes: 38 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#$ composer update --optimize-autoloader
#$ vendor/bin/phpstan analyze

includes:
# @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
# Include this extension
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: max
inferPrivatePropertyTypeFromConstructor: true
bootstrapFiles:
# Missing constants, function and class stubs
- %currentWorkingDirectory%/vendor/autoload.php
scanFiles:
- %currentWorkingDirectory%/wp-object-cache.php
# autoload_directories:
# - %currentWorkingDirectory%/inc/
paths:
- %currentWorkingDirectory%/src/
- %currentWorkingDirectory%/include/
# excludes_analyse:
# - %currentWorkingDirectory%/inc/views/
ignoreErrors:
# Uses func_get_args()
- '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'
# Fixed in WordPress 5.3
- '#^Function do_action(_ref_array)? invoked with [3456] parameters, 1-2 required\.$#'
- '#^Function current_user_can invoked with 2 parameters, 1 required\.$#'
- '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#'
- '#^Function wp_sprintf invoked with [23456] parameters, 1 required\.$#'
- '#^Function add_post_type_support invoked with [345] parameters, 2 required\.$#'
- '#^Function ((get|add)_theme_support|current_theme_supports) invoked with [2345] parameters, 1 required\.$#'
# https://core.trac.wordpress.org/ticket/43304
- '/^Parameter #2 \$deprecated of function load_plugin_textdomain expects string, false given\.$/'
# WP-CLI accepts a class name as callable
- '/^Parameter #2 \$callable of static method WP_CLI::add_command\(\) expects callable\(\): mixed, \S+ given\.$/'
# Please consider commenting ignores: issue URL or reason for ignoring
Loading

0 comments on commit dc7faaa

Please sign in to comment.