Skip to content

Commit

Permalink
Reformat with PHP CS Fixer.
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 2, 2016
1 parent 6d03dae commit aaed2d5
Show file tree
Hide file tree
Showing 91 changed files with 839 additions and 790 deletions.
3 changes: 2 additions & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
update_site_option('comet_cache_mbstring_deprecated_warning_bypass', time());
}

${__FILE__}['apc_enabled'] = (extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN) && stripos((string)ini_get('apc.filters'), 'comet-cache') === false) ? true : false;
${__FILE__}['apc_enabled'] = (extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN) && stripos((string) ini_get('apc.filters'), 'comet-cache') === false) ? true : false;

if ((!version_compare(PHP_VERSION, '5.4', '>=') || ${__FILE__}['apc_enabled'])) { // If PHP <= 5.4 or APC is enabled

Expand Down Expand Up @@ -87,3 +87,4 @@
}

unset(${__FILE__}); // Housekeeping.

16 changes: 9 additions & 7 deletions src/includes/classes/AbsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ abstract class AbsBase
*
* @since 150422 Rewrite.
*/
protected $cache = array();
protected $cache = [];

/**
* @type array Global static cache ref.
*
* @since 150422 Rewrite.
*/
protected $static = array();
protected $static = [];

/**
* @type array Global static cache.
*
* @since 150422 Rewrite.
*/
protected static $global_static = array();
protected static $global_static = [];

/**
* @type \stdClass Overload properties.
Expand All @@ -55,7 +55,7 @@ public function __construct()
$class = get_called_class();

if (empty(static::$global_static[$class])) {
static::$global_static[$class] = array();
static::$global_static[$class] = [];
}
$this->static = &static::$global_static[$class];

Expand All @@ -76,7 +76,8 @@ public static function instance()
if (isset($instance)) {
return $instance;
}
return ($instance = new static());

return $instance = new static();
}

/**
Expand Down Expand Up @@ -167,7 +168,7 @@ public function __unset($property)
* @note This function returns by reference. The use of `&` is highly recommended when calling this utility.
* See also: <http://php.net/manual/en/language.references.return.php>
*/
public function &cacheKey($function, $args = array(), $___prop = 'cache')
public function &cacheKey($function, $args = [], $___prop = 'cache')
{
$function = (string) $function;
$args = (array) $args;
Expand Down Expand Up @@ -210,6 +211,7 @@ public function &cacheKey($function, $args = array(), $___prop = 'cache')
}
$cache_key = &$cache_key[$_key];
}

return $cache_key;
}

Expand All @@ -224,7 +226,7 @@ public function &cacheKey($function, $args = array(), $___prop = 'cache')
* @note This function returns by reference. The use of `&` is highly recommended when calling this utility.
* See also: <http://php.net/manual/en/language.references.return.php>
*/
public function &staticKey($function, $args = array())
public function &staticKey($function, $args = [])
{
$key = &$this->cacheKey($function, $args, 'static');

Expand Down
1 change: 0 additions & 1 deletion src/includes/classes/AbsBaseAp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace WebSharks\CometCache\Pro\Classes;

use WebSharks\CometCache\Pro\Traits;

use WebSharks\CometCache\Pro\Interfaces;

/**
Expand Down
60 changes: 30 additions & 30 deletions src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Actions extends AbsBase
*
* @since 150422 Rewrite.
*/
protected $allowed_actions = array(
protected $allowed_actions = [
'wipeCache',
'clearCache',

Expand Down Expand Up @@ -58,7 +58,7 @@ class Actions extends AbsBase
/*[/pro]*/

'dismissNotice',
);
];

/**
* Class constructor.
Expand Down Expand Up @@ -107,7 +107,7 @@ protected function wipeCache($args)
/*[/pro]*/

$redirect_to = self_admin_url('/admin.php');
$query_args = array('page' => GLOBAL_NS, GLOBAL_NS.'_cache_wiped' => '1');
$query_args = ['page' => GLOBAL_NS, GLOBAL_NS.'_cache_wiped' => '1'];
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);

wp_redirect($redirect_to).exit();
Expand Down Expand Up @@ -138,7 +138,7 @@ protected function clearCache($args)
/*[/pro]*/

$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => GLOBAL_NS, GLOBAL_NS.'_cache_cleared' => '1');
$query_args = ['page' => GLOBAL_NS, GLOBAL_NS.'_cache_cleared' => '1'];
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);

wp_redirect($redirect_to).exit();
Expand Down Expand Up @@ -392,7 +392,7 @@ protected function ajaxWipeExpiredTransients($args)
if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'])) {
return; // Unauthenticated POST data.
}
$counter = (int)($this->plugin->wipeExpiredTransients(true, false) / 2); // Divide in half for Dashboard message
$counter = (int) ($this->plugin->wipeExpiredTransients(true, false) / 2); // Divide in half for Dashboard message

$response = sprintf(__('<p>Expired transients wiped successfully.</p>', SLUG_TD), esc_html(NAME));
$response .= sprintf(__('<p>Wiped <code>%1$s</code> expired transients.</p>', SLUG_TD), esc_html($counter));
Expand All @@ -417,7 +417,7 @@ protected function ajaxClearExpiredTransients($args)
if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'])) {
return; // Unauthenticated POST data.
}
$counter = (int)($this->plugin->clearExpiredTransients(true, false) / 2); // Divide in half for Dashboard message
$counter = (int) ($this->plugin->clearExpiredTransients(true, false) / 2); // Divide in half for Dashboard message

$response = sprintf(__('<p>Expired transients cleared successfully.</p>', SLUG_TD), esc_html(NAME));
$response .= sprintf(__('<p>Cleared <code>%1$s</code> expired transients for this site.</p>', SLUG_TD), esc_html($counter));
Expand Down Expand Up @@ -449,7 +449,7 @@ protected function ajaxStats($args)
$is_multisite = is_multisite();

if (!$is_multisite || current_user_can($this->plugin->network_cap)) {
$stats_data = array(
$stats_data = [
'forCache' => $dir_stats->forCache(),
'forHtmlCCache' => $dir_stats->forHtmlCCache(),
'largestCacheSize' => $dir_stats->largestCacheSize(),
Expand All @@ -458,20 +458,20 @@ protected function ajaxStats($args)
'sysLoadAverages' => $this->plugin->sysLoadAverages(),
'sysMemoryStatus' => $this->plugin->sysMemoryStatus(),
'sysOpcacheStatus' => $this->plugin->sysOpcacheStatus(),
);
];
if ($is_multisite) {
$stats_data = array_merge($stats_data, array(
$stats_data = array_merge($stats_data, [
'forHostCache' => $dir_stats->forHostCache(),
'forHtmlCHostCache' => $dir_stats->forHtmlCHostCache(),
));
]);
}
} else { // Stats for a child blog owner.
$stats_data = array(
$stats_data = [
'forHostCache' => $dir_stats->forHostCache(),
'forHtmlCHostCache' => $dir_stats->forHtmlCHostCache(),
'largestHostCacheSize' => $dir_stats->largestHostCacheSize(),
'largestHostCacheCount' => $dir_stats->largestHostCacheCount(),
);
];
}
header('Content-Type: application/json; charset=UTF-8');

Expand Down Expand Up @@ -502,25 +502,25 @@ protected function ajaxDirStats($args)
$is_multisite = is_multisite();

if (!$is_multisite || current_user_can($this->plugin->network_cap)) {
$dir_stats_data = array(
$dir_stats_data = [
'forCache' => $dir_stats->forCache(),
'forHtmlCCache' => $dir_stats->forHtmlCCache(),
'largestCacheSize' => $dir_stats->largestCacheSize(),
'largestCacheCount' => $dir_stats->largestCacheCount(),
);
];
if ($is_multisite) {
$dir_stats_data = array_merge($dir_stats_data, array(
$dir_stats_data = array_merge($dir_stats_data, [
'forHostCache' => $dir_stats->forHostCache(),
'forHtmlCHostCache' => $dir_stats->forHtmlCHostCache(),
));
]);
}
} else { // Stats for a child blog owner.
$dir_stats_data = array(
$dir_stats_data = [
'forHostCache' => $dir_stats->forHostCache(),
'forHtmlCHostCache' => $dir_stats->forHtmlCHostCache(),
'largestHostCacheSize' => $dir_stats->largestHostCacheSize(),
'largestHostCacheCount' => $dir_stats->largestHostCacheCount(),
);
];
}
header('Content-Type: application/json; charset=UTF-8');

Expand Down Expand Up @@ -560,7 +560,7 @@ protected function saveOptions($args)
delete_transient(GLOBAL_NS.'-'.md5($this->plugin->options['auto_cache_sitemap_url']));

$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => GLOBAL_NS, GLOBAL_NS.'_updated' => '1');
$query_args = ['page' => GLOBAL_NS, GLOBAL_NS.'_updated' => '1'];

$this->plugin->autoWipeCache(); // May produce a notice.

Expand Down Expand Up @@ -625,7 +625,7 @@ protected function restoreDefaultOptions($args)
$this->plugin->restoreDefaultOptions(); // Restore defaults.

$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => GLOBAL_NS, GLOBAL_NS.'_restored' => '1');
$query_args = ['page' => GLOBAL_NS, GLOBAL_NS.'_restored' => '1'];

$this->plugin->autoWipeCache(); // May produce a notice.

Expand Down Expand Up @@ -736,15 +736,15 @@ protected function proUpdate($args)
$args['password'] = $this->plugin->options['pro_update_password'];
}
$product_api_url = 'https://'.urlencode(DOMAIN).'/';
$product_api_input_vars = array(
'product_api' => array(
$product_api_input_vars = [
'product_api' => [
'action' => 'latest_pro_update',
'stable' => $args['check_stable'],
'username' => $args['username'],
'password' => $args['password'],
),
);
$product_api_response = wp_remote_post($product_api_url, array('body' => $product_api_input_vars));
],
];
$product_api_response = wp_remote_post($product_api_url, ['body' => $product_api_input_vars]);
$product_api_response = json_decode(wp_remote_retrieve_body($product_api_response));

if (!is_object($product_api_response) || !empty($product_api_response->error) || empty($product_api_response->pro_version) || empty($product_api_response->pro_zip)) {
Expand All @@ -754,23 +754,23 @@ protected function proUpdate($args)
$error = __('Unknown error. Please wait 15 minutes and try again.', SLUG_TD);
}
$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => GLOBAL_NS.'-pro-updater', GLOBAL_NS.'_error' => $error);
$query_args = ['page' => GLOBAL_NS.'-pro-updater', GLOBAL_NS.'_error' => $error];
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);

wp_redirect($redirect_to).exit();
}
$this->plugin->updateOptions(array(
$this->plugin->updateOptions([
'last_pro_update_check' => time(),
'pro_update_check' => $args['check'],
'pro_update_check_stable' => $args['check_stable'],
'pro_update_username' => $args['username'],
'pro_update_password' => $args['password'],
'latest_pro_version' => $product_api_response->pro_version,
));
]);
$this->plugin->dismissMainNotice('new-pro-version-available');

$redirect_to = self_admin_url('/update.php');
$query_args = array( // Like a normal WP plugin.
$query_args = [ // Like a normal WP plugin.
'action' => 'upgrade-plugin',
'plugin' => plugin_basename(PLUGIN_FILE),
'_wpnonce' => wp_create_nonce('upgrade-plugin_'.plugin_basename(PLUGIN_FILE)),
Expand All @@ -779,7 +779,7 @@ protected function proUpdate($args)
GLOBAL_NS.'_update_pro_version' => $product_api_response->pro_version,
GLOBAL_NS.'_update_pro_zip' => base64_encode($product_api_response->pro_zip),
// @TODO Encrypt/decrypt to avoid mod_security issues. Base64 is not enough.
);
];
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);

wp_redirect($redirect_to).exit();
Expand Down
6 changes: 3 additions & 3 deletions src/includes/classes/AdvCacheBackCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class AdvCacheBackCompat
*/
public static function zcRequestVars()
{
$super_gs = array(
$super_gs = [
'_GET' => &$_GET,
'_REQUEST' => &$_REQUEST,
);
$zc_suffixes = array('AC', 'ABC');
];
$zc_suffixes = ['AC', 'ABC'];

foreach ($super_gs as $_super_g_key => &$_super_g_value) {
foreach ($zc_suffixes as $_zc_suffix) {
Expand Down
1 change: 1 addition & 0 deletions src/includes/classes/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function clearPost($post_id)
public static function clearUrl($url)
{
$regex = $GLOBALS[GLOBAL_NS]->buildCachePathRegexFromWcUrl($url);

return $GLOBALS[GLOBAL_NS]->deleteFilesFromCacheDir($regex);
}

Expand Down
17 changes: 10 additions & 7 deletions src/includes/classes/AutoCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*[pro strip-from="lite"]*/
namespace WebSharks\CometCache\Pro\Classes;

Expand Down Expand Up @@ -69,7 +70,7 @@ protected function run()
$other_urls = $this->plugin->options['auto_cache_other_urls'];
$other_urls = preg_split('/\s+/', $other_urls, -1, PREG_SPLIT_NO_EMPTY);

$blogs = array((object) array('ID' => null, 'other' => $other_urls));
$blogs = [(object) ['ID' => null, 'other' => $other_urls]];

$is_multisite = is_multisite(); // Multisite network?
$can_consider_domain_mapping = $is_multisite && $this->plugin->canConsiderDomainMapping();
Expand All @@ -84,7 +85,7 @@ protected function run()
shuffle($blogs); // Randomize; i.e. don't always start from the top.

foreach ($blogs as $_blog) {
$_blog_sitemap_urls = $_blog_other_urls = $_blog_urls = array();
$_blog_sitemap_urls = $_blog_other_urls = $_blog_urls = [];

if (!isset($_blog->ID)) { // `home_url()` fallback.
$_blog_url = rtrim(network_home_url('', 'http'), '/');
Expand Down Expand Up @@ -154,11 +155,11 @@ protected function autoCacheUrl($url)
$url,
wp_remote_get(
$url,
array(
[
'blocking' => false,
'user-agent' => $this->plugin->options['auto_cache_user_agent'].
'; '.GLOBAL_NS.' '.VERSION,
)
]
)
);
}
Expand Down Expand Up @@ -248,7 +249,7 @@ protected function logAutoCacheRun($total_urls, $total_time)
*/
protected function getSitemapUrlsDeep($sitemap, $___recursive = false)
{
$urls = array();
$urls = [];
$xml_reader = new \XMLReader();
$failure = ''; // Initialize.

Expand Down Expand Up @@ -297,7 +298,7 @@ protected function getSitemapUrlsDeep($sitemap, $___recursive = false)
*/
protected function xmlGetSitemapIndexUrlsDeep(\XMLReader $xml_reader)
{
$urls = array(); // Initialize.
$urls = []; // Initialize.

if ($xml_reader->name === 'sitemapindex') {
while ($xml_reader->read()) {
Expand All @@ -319,6 +320,7 @@ protected function xmlGetSitemapIndexUrlsDeep(\XMLReader $xml_reader)
}
}
}

return $urls; // All sitemap URLs from this `<sitemapindex>` node; deeply.
}
}
Expand All @@ -334,7 +336,7 @@ protected function xmlGetSitemapIndexUrlsDeep(\XMLReader $xml_reader)
*/
protected function xmlGetUrlsetUrls(\XMLReader $xml_reader)
{
$urls = array(); // Initialize.
$urls = []; // Initialize.

if ($xml_reader->name === 'urlset') {
while ($xml_reader->read()) {
Expand All @@ -356,6 +358,7 @@ protected function xmlGetUrlsetUrls(\XMLReader $xml_reader)
}
}
}

return $urls; // All sitemap URLs from this `<urlset>` node.
}
}
Expand Down
Loading

0 comments on commit aaed2d5

Please sign in to comment.