diff --git a/composer.json b/composer.json
index 8f9dfcf..f38ea55 100644
--- a/composer.json
+++ b/composer.json
@@ -38,6 +38,18 @@
"require-dev": {
"newfold-labs/wp-php-standards": "^1.2.4"
},
+ "scripts": {
+ "cs-fix": [
+ "phpcbf --standard=phpcs.xml ."
+ ],
+ "cs-lint": [
+ "phpcs --standard=phpcs.xml -s ."
+ ]
+ },
+ "scripts-descriptions": {
+ "fix": "Automatically fix coding standards issues where possible.",
+ "lint": "Check files against coding standards."
+ },
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
diff --git a/includes/BurstSafetyMode/Browser.php b/includes/BurstSafetyMode/Browser.php
index 6f97d3b..ecf1c1f 100644
--- a/includes/BurstSafetyMode/Browser.php
+++ b/includes/BurstSafetyMode/Browser.php
@@ -4,6 +4,9 @@
use NewfoldLabs\WP\Module\Performance\BurstSafetyMode\ResponseHeaderManager;
use WP_Forge\WP_Htaccess_Manager\htaccess;
+/**
+ * Browser cache.
+ */
class Browser {
/**
* The file marker name.
@@ -12,6 +15,9 @@ class Browser {
*/
const MARKER = 'Newfold Browser Cache';
+ /**
+ * Constructor.
+ */
public function __construct() {
$responseHeaderManager = new ResponseHeaderManager();
$responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', BURST_SAFETY_CACHE_LEVEL );
@@ -20,8 +26,6 @@ public function __construct() {
/**
* Add htaccess rules.
- *
- * @return void
*/
public static function addRules() {
diff --git a/includes/BurstSafetyMode/ResponseHeaderManager.php b/includes/BurstSafetyMode/ResponseHeaderManager.php
index 3a3365c..1ca0509 100644
--- a/includes/BurstSafetyMode/ResponseHeaderManager.php
+++ b/includes/BurstSafetyMode/ResponseHeaderManager.php
@@ -5,6 +5,9 @@
use WP_Forge\WP_Htaccess_Manager\htaccess;
use function WP_Forge\WP_Htaccess_Manager\convertContentToLines;
+/**
+ * Response header manager.
+ */
class ResponseHeaderManager {
/**
@@ -14,6 +17,11 @@ class ResponseHeaderManager {
*/
const MARKER = 'Newfold Headers';
+ /**
+ * Htaccess instance.
+ *
+ * @var htaccess
+ */
public $htaccess;
/**
@@ -67,7 +75,7 @@ public function addHeader( string $name, string $value ) {
/**
* Add multiple headers at once.
*
- * @param string[] $headers
+ * @param string[] $headers Headers to add.
*/
public function addHeaders( array $headers ) {
$headers = array_merge( $this->parseHeaders(), $headers );
@@ -95,7 +103,7 @@ public function removeAllHeaders() {
/**
* Set headers.
*
- * @param array $headers
+ * @param array $headers Headers to set.
*/
public function setHeaders( array $headers ) {
@@ -107,7 +115,7 @@ public function setHeaders( array $headers ) {
$content = '' . PHP_EOL;
foreach ( $headers as $key => $value ) {
- $content .= "\t" . "Header set {$key} \"{$value}\"" . PHP_EOL;
+ $content .= "\tHeader set {$key} \"{$value}\"" . PHP_EOL;
}
$content .= '';
diff --git a/includes/BurstSafetyMode/Skip404.php b/includes/BurstSafetyMode/Skip404.php
index 18afd04..bd63513 100644
--- a/includes/BurstSafetyMode/Skip404.php
+++ b/includes/BurstSafetyMode/Skip404.php
@@ -4,24 +4,26 @@
use function WP_Forge\WP_Htaccess_Manager\addContent;
use function WP_Forge\WP_Htaccess_Manager\removeMarkers;
+/**
+ * Skip 404 cache type.
+ */
class Skip404 {
- /**
+ /**
* The file marker name.
*/
const MARKER = 'Newfold Skip 404 Handling for Static Files';
- /**
- * Constructor.
- */
+ /**
+ * Constructor.
+ */
public function __construct() {
-
$this->addRules();
}
- /**
- * Add our rules to the .htacces file.
- */
+ /**
+ * Add our rules to the .htacces file.
+ */
public static function addRules() {
$content = <<
diff --git a/includes/CacheManager.php b/includes/CacheManager.php
index 28cf7cf..d72b008 100644
--- a/includes/CacheManager.php
+++ b/includes/CacheManager.php
@@ -5,8 +5,9 @@
use NewfoldLabs\WP\Module\Performance\CacheTypes\CacheBase;
use NewfoldLabs\WP\ModuleLoader\Container;
use WP_Forge\Collection\Collection;
+
/**
- * Cache Manager Class
+ * Cache manager.
*/
class CacheManager {
/**
@@ -73,7 +74,7 @@ public function enabledCacheTypes() {
/**
* Get an array of page cache type instances based on the enabled cache types.
*
- * @return CacheBase[]
+ * @return CacheBase[] An array of cache type instances.
*/
public function getInstances() {
$instances = array();
diff --git a/includes/CachePurgingService.php b/includes/CachePurgingService.php
index 9eee387..6d85f5c 100644
--- a/includes/CachePurgingService.php
+++ b/includes/CachePurgingService.php
@@ -6,28 +6,31 @@
use NewfoldLabs\WP\Module\Performance\Concerns\Purgeable;
use wpscholar\Url;
+/**
+ * Cache purging service.
+ */
class CachePurgingService {
/**
* Cache types.
*
- * @var CacheBase[]
+ * @var CacheBase[] $cacheTypes Cache types.
*/
- public $cacheTypes = [];
+ public $cacheTypes = array(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase
/**
* Constructor.
*
- * @param CacheBase[] $cacheTypes
+ * @param CacheBase[] $cacheTypes Cache types.
*/
public function __construct( array $cacheTypes ) {
- $this->cacheTypes = $cacheTypes;
+ $this->cacheTypes = $cacheTypes; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( $this->canPurge() ) {
// Handle manual purge requests
- add_action( 'init', [ $this, 'manualPurgeRequest' ] );
+ add_action( 'init', array( $this, 'manualPurgeRequest' ) );
// Handle automatic purging
add_action( 'transition_post_status', array( $this, 'onSavePost' ), 10, 3 );
@@ -45,7 +48,7 @@ public function __construct( array $cacheTypes ) {
* @return bool
*/
public function canPurge() {
- foreach ( $this->cacheTypes as $instance ) {
+ foreach ( $this->cacheTypes as $instance ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( array_key_exists( Purgeable::class, class_implements( $instance ) ) ) {
return true;
}
@@ -86,9 +89,11 @@ public function manualPurgeRequest() {
* Purge everything.
*/
public function purgeAll() {
- foreach ( $this->cacheTypes as $instance ) {
+ foreach ( $this->cacheTypes as $instance ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( array_key_exists( Purgeable::class, class_implements( $instance ) ) ) {
/**
+ * Purgeable instance.
+ *
* @var Purgeable $instance
*/
$instance->purgeAll();
@@ -99,12 +104,14 @@ public function purgeAll() {
/**
* Purge a specific URL.
*
- * @param string $url The URL to be purged.
+ * @param string $url The URL to be purged.
*/
public function purgeUrl( $url ) {
- foreach ( $this->cacheTypes as $instance ) {
+ foreach ( $this->cacheTypes as $instance ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( array_key_exists( Purgeable::class, class_implements( $instance ) ) ) {
/**
+ * Purgeable instance.
+ *
* @var Purgeable $instance
*/
$instance->purgeUrl( $url );
@@ -115,9 +122,9 @@ public function purgeUrl( $url ) {
/**
* Purge appropriate caches when a post is updated.
*
- * @param string $oldStatus The previous post status
- * @param string $newStatus The new post status
- * @param \WP_Post $post The post object of the edited or created post
+ * @param string $oldStatus The previous post status
+ * @param string $newStatus The new post status
+ * @param \WP_Post $post The post object of the edited or created post
*/
public function onSavePost( $oldStatus, $newStatus, \WP_Post $post ) {
@@ -160,13 +167,12 @@ public function onSavePost( $oldStatus, $newStatus, \WP_Post $post ) {
// Purge date archive URL when post is updated.
$year_archive = get_year_link( (int) get_the_date( 'y', $post ) );
$this->purgeUrl( $year_archive );
-
}
/**
* Purge taxonomy term URL when a term is updated.
*
- * @param int $termId Term ID
+ * @param int $termId Term ID
*/
public function onEditTerm( $termId ) {
$url = get_term_link( $termId );
@@ -178,7 +184,7 @@ public function onEditTerm( $termId ) {
/**
* Purge a single post when a comment is updated.
*
- * @param int $commentId ID of the comment.
+ * @param int $commentId ID of the comment.
*/
public function onUpdateComment( $commentId ) {
$comment = get_comment( $commentId );
@@ -190,8 +196,16 @@ public function onUpdateComment( $commentId ) {
}
}
+ /**
+ * Purge all caches when an option is updated.
+ *
+ * @param string $option Option name.
+ * @param mixed $oldValue Old option value.
+ * @param mixed $newValue New option value.
+ *
+ * @return bool
+ */
public function onUpdateOption( $option, $oldValue, $newValue ) {
-
// No need to process if nothing was updated
if ( $oldValue === $newValue ) {
return false;
@@ -298,13 +312,12 @@ public function onUpdateOption( $option, $oldValue, $newValue ) {
$this->purgeAll();
return true;
-
}
/**
* Checks if a taxonomy is public.
*
- * @param string $taxonomy Taxonomy name.
+ * @param string $taxonomy Taxonomy name.
*
* @return boolean
*/
@@ -317,5 +330,4 @@ protected function isPublicTaxonomy( $taxonomy ) {
return $public;
}
-
}
diff --git a/includes/CacheTypes/Browser.php b/includes/CacheTypes/Browser.php
index c90899a..9bdf0c0 100644
--- a/includes/CacheTypes/Browser.php
+++ b/includes/CacheTypes/Browser.php
@@ -12,7 +12,7 @@
use function WP_Forge\WP_Htaccess_Manager\removeMarkers;
/**
- * Browser cache class
+ * Browser cache type.
*/
class Browser extends CacheBase {
/**
@@ -25,7 +25,7 @@ class Browser extends CacheBase {
/**
* Whether or not the code for this cache type should be loaded.
*
- * @param Container $container the container.
+ * @param Container $container Dependency injection container.
*
* @return bool
*/
diff --git a/includes/CacheTypes/CacheBase.php b/includes/CacheTypes/CacheBase.php
index 89602dd..90c04c2 100644
--- a/includes/CacheTypes/CacheBase.php
+++ b/includes/CacheTypes/CacheBase.php
@@ -4,6 +4,9 @@
use NewfoldLabs\WP\ModuleLoader\Container;
+/**
+ * Base class for cache types.
+ */
abstract class CacheBase {
/**
@@ -16,9 +19,11 @@ abstract class CacheBase {
/**
* Whether or not the code for this cache type should be loaded.
*
- * @return bool
+ * @param Container $container Dependency injection container.
+ *
+ * @return bool True if the cache type should be enabled, false otherwise.
*/
- public static function shouldEnable( Container $container ) {
+ public static function shouldEnable( Container $container ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
return true;
}
@@ -41,5 +46,4 @@ public function setContainer( Container $container ) {
public function getContainer() {
return $this->container;
}
-
}
diff --git a/includes/CacheTypes/Cloudflare.php b/includes/CacheTypes/Cloudflare.php
index 16db66b..34e044d 100644
--- a/includes/CacheTypes/Cloudflare.php
+++ b/includes/CacheTypes/Cloudflare.php
@@ -5,21 +5,24 @@
use NewfoldLabs\WP\Module\Performance\Concerns\Purgeable;
use NewfoldLabs\WP\ModuleLoader\Container;
+/**
+ * Cloudflare cache type.
+ */
class Cloudflare extends CacheBase implements Purgeable {
/**
* Whether or not the code for this cache type should be loaded.
*
- * @return bool
+ * @return bool True if the cache type should be enabled, false otherwise.
*/
- public static function shouldEnable( Container $container ) {
+ public static function shouldEnable() {
return (bool) \get_option( 'endurance_cloudflare_enabled', false );
}
/**
* Check if Cloudflare is enabled.
*
- * @return bool
+ * @return bool True if Cloudflare is enabled, false otherwise.
*/
public function isCoudflareEnabled() {
return $this->getCloudflareTier() !== 0;
@@ -28,7 +31,7 @@ public function isCoudflareEnabled() {
/**
* Get the Cloudflare tier.
*
- * @return int|string
+ * @return int|string The Cloudflare tier.
*/
public function getCloudflareTier() {
$tier = \get_option( 'endurance_cloudflare_enabled', false );
@@ -51,8 +54,6 @@ public function getCloudflareTier() {
/**
* Purge all Cloudflare cache.
- *
- * @return void
*/
public function purgeAll() {
if ( $this->isCoudflareEnabled() ) {
@@ -63,13 +64,11 @@ public function purgeAll() {
/**
* Purge a URL from Cloudflare cache.
*
- * @param string $url
- *
- * @return void
+ * @param string $url URL to purge.
*/
public function purgeUrl( $url ) {
if ( $this->isCoudflareEnabled() ) {
- $this->purgeRequest( [ $url ] );
+ $this->purgeRequest( array( $url ) );
}
}
@@ -78,39 +77,37 @@ public function purgeUrl( $url ) {
*
* @link https://confluence.newfold.com/pages/viewpage.action?spaceKey=UDEV&title=Cache+Purge+API
*
- * @param array $urls
- *
- * @return void
+ * @param array $urls URLs to purge.
*/
- protected function purgeRequest( $urls = [] ) {
+ protected function purgeRequest( $urls = array() ) {
global $wp_version;
- $queryString = http_build_query( [ 'cf' => $this->getCloudflareTier() ], '', '&' );
+ $queryString = http_build_query( array( 'cf' => $this->getCloudflareTier() ), '', '&' );
- $host = wp_parse_url( \home_url(), PHP_URL_HOST );
- $pluginBrand = $this->getContainer()->plugin()->get( 'id' );
- $pluginVersion = $this->getContainer()->plugin()->version;
+ $host = wp_parse_url( \home_url(), PHP_URL_HOST );
+ $plugin_brand = $this->getContainer()->plugin()->get( 'id' );
+ $plugin_version = $this->getContainer()->plugin()->version;
- $headerName = 'X-' . strtoupper( $pluginBrand ) . '-PLUGIN-PURGE';
+ $headerName = 'X-' . strtoupper( $plugin_brand ) . '-PLUGIN-PURGE';
- $body = [
- 'hosts' => [ $host ],
- ];
+ $body = array(
+ 'hosts' => array( $host ),
+ );
if ( $urls ) {
$body['assets'] = $urls;
}
- $args = [
+ $args = array(
'body' => wp_json_encode( $body ),
'compress' => true,
- 'headers' => [
+ 'headers' => array(
$headerName => 1,
'Content-Type' => 'application/json',
- ],
+ ),
'sslverify' => false,
- 'user-agent' => "WordPress/{$wp_version}; {$host}; {$pluginBrand}/v{$pluginVersion}",
- ];
+ 'user-agent' => "WordPress/{$wp_version}; {$host}; {$plugin_brand}/v{$plugin_version}",
+ );
// If WP_DEBUG is enabled, we want to wait for a response.
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
@@ -120,5 +117,4 @@ protected function purgeRequest( $urls = [] ) {
wp_remote_post( 'https://cachepurge.bluehost.com/v0/purge?' . $queryString, $args );
}
-
}
diff --git a/includes/CacheTypes/File.php b/includes/CacheTypes/File.php
index 60d9ef9..f13cbad 100644
--- a/includes/CacheTypes/File.php
+++ b/includes/CacheTypes/File.php
@@ -16,7 +16,7 @@
use function WP_Forge\WP_Htaccess_Manager\removeMarkers;
/**
- * Page cache class
+ * File cache type.
*/
class File extends CacheBase implements Purgeable {
/**
@@ -36,7 +36,7 @@ class File extends CacheBase implements Purgeable {
/**
* Whether or not the code for this cache type should be loaded.
*
- * @param Container $container the container.
+ * @param Container $container Dependency injection container.
*
* @return bool
*/
@@ -85,7 +85,6 @@ public static function maybeAddRules( $cacheLevel ) {
* @return bool
*/
public static function addRules() {
-
$base = wp_parse_url( home_url( '/' ), PHP_URL_PATH );
$path = str_replace( get_home_path(), '/', self::CACHE_DIR );
diff --git a/includes/CacheTypes/Nginx.php b/includes/CacheTypes/Nginx.php
index f7c48f0..ec3daf5 100644
--- a/includes/CacheTypes/Nginx.php
+++ b/includes/CacheTypes/Nginx.php
@@ -3,15 +3,15 @@
namespace NewfoldLabs\WP\Module\Performance\CacheTypes;
use NewfoldLabs\WP\Module\Performance\Concerns\Purgeable;
-
use wpscholar\Url;
+/**
+ * Nginx cache type.
+ */
class Nginx extends CacheBase implements Purgeable {
/**
* Purge all assets from the Nginx cache.
- *
- * @return void
*/
public function purgeAll() {
$this->purgeRequest();
@@ -20,9 +20,7 @@ public function purgeAll() {
/**
* Purge the Nginx cache for a specific URL.
*
- * @param string $url
- *
- * @return void
+ * @param string $url The URL to purge.
*/
public function purgeUrl( $url ) {
$this->purgeRequest( $url );
@@ -31,24 +29,22 @@ public function purgeUrl( $url ) {
/**
* Purge the cache.
*
- * @param string $url
- *
- * @return void
+ * @param string $url The URL to purge.
*/
protected function purgeRequest( $url = '' ) {
global $wp_version;
- $URL = $url ? new Url( $url ) : new Url( \home_url() );
+ $url = $url ? new Url( $url ) : new Url( \home_url() );
- $pluginBrand = $this->getContainer()->plugin()->get( 'id' );
- $pluginVersion = $this->getContainer()->plugin()->version;
+ $plugin_brand = $this->getContainer()->plugin()->get( 'id' );
+ $plugin_version = $this->getContainer()->plugin()->version;
$args = array(
'method' => 'PURGE',
'headers' => array(
- 'host' => $URL->host,
+ 'host' => $url->host,
),
- 'user-agent' => "WordPress/{$wp_version}; {$URL->host}; {$pluginBrand}/v{$pluginVersion}",
+ 'user-agent' => "WordPress/{$wp_version}; {$url->host}; {$plugin_brand}/v{$plugin_version}",
'sslverify' => false,
);
@@ -58,32 +54,31 @@ protected function purgeRequest( $url = '' ) {
$args['timeout'] = 0.01;
}
- $path = '/' . ltrim( $URL->path, '/' ) . '.*';
+ $path = '/' . ltrim( $url->path, '/' ) . '.*';
- $httpUrl = $URL::buildUrl(
+ $http_url = $url::buildUrl(
array_merge(
- $URL->toArray(),
- [
+ $url->toArray(),
+ array(
'scheme' => 'http',
'host' => '127.0.0.1:8080',
'path' => $path,
- ]
+ )
)
);
- $httpsUrl = $URL::buildUrl(
+ $https_url = $url::buildUrl(
array_merge(
- $URL->toArray(),
- [
+ $url->toArray(),
+ array(
'scheme' => 'https',
'host' => '127.0.0.1:8443',
'path' => $path,
- ]
+ )
)
);
- wp_remote_request( $httpUrl, $args );
- wp_remote_request( $httpsUrl, $args );
+ wp_remote_request( $http_url, $args );
+ wp_remote_request( $https_url, $args );
}
-
}
diff --git a/includes/CacheTypes/Sitelock.php b/includes/CacheTypes/Sitelock.php
index f7fddbb..fc2a68a 100644
--- a/includes/CacheTypes/Sitelock.php
+++ b/includes/CacheTypes/Sitelock.php
@@ -5,14 +5,17 @@
use NewfoldLabs\WP\Module\Performance\Concerns\Purgeable;
use NewfoldLabs\WP\ModuleLoader\Container;
+/**
+ * Sitelock cache type.
+ */
class Sitelock extends CacheBase implements Purgeable {
/**
* Whether the code for this cache type should be loaded.
*
- * @param Container $container
+ * @param Container $container The dependency injection container.
*
- * @return bool
+ * @return bool True if the code should be loaded, false otherwise.
*/
public static function shouldEnable( Container $container ) {
return (bool) \get_option( 'endurance_sitelock_enabled', false );
@@ -20,8 +23,6 @@ public static function shouldEnable( Container $container ) {
/**
* Purge all content from the Sitelock CDN cache.
- *
- * @return void
*/
public function purgeAll() {
@@ -57,15 +58,12 @@ public function purgeAll() {
}
wp_remote_get( $query, $args );
-
}
/**
* Purge a specific URL from the Sitelock CDN cache.
*
- * @param $url
- *
- * @return void
+ * @param string $url The URL to purge.
*/
public function purgeUrl( $url ) {
@@ -79,12 +77,12 @@ public function purgeUrl( $url ) {
$pattern = rawurlencode( $path . '$' );
$domain = wp_parse_url( \home_url(), PHP_URL_HOST );
- $args = [
+ $args = array(
'method' => 'PUT',
- 'headers' => [
+ 'headers' => array(
'X-MOJO-TOKEN' => $refreshToken,
- ],
- ];
+ ),
+ );
// If WP_DEBUG is enabled, we want to wait for a response.
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
@@ -94,5 +92,4 @@ public function purgeUrl( $url ) {
wp_remote_post( "https://my.bluehost.com/api/domains/{$domain}/caches/sitelock/{$pattern}", $args );
}
-
}
diff --git a/includes/CacheTypes/Skip404.php b/includes/CacheTypes/Skip404.php
index de9a5e1..b69d3db 100644
--- a/includes/CacheTypes/Skip404.php
+++ b/includes/CacheTypes/Skip404.php
@@ -11,7 +11,7 @@
use function WP_Forge\WP_Htaccess_Manager\removeMarkers;
/**
- * Skip404 Class
+ * Skip 404 cache type.
*/
class Skip404 extends CacheBase {
@@ -23,7 +23,7 @@ class Skip404 extends CacheBase {
/**
* Whether or not the code for this cache type should be loaded.
*
- * @param Container $container the container.
+ * @param Container $container Dependency injection container.
*
* @return bool
*/
diff --git a/includes/Concerns/Purgeable.php b/includes/Concerns/Purgeable.php
index 9e9e5f4..8538d3c 100644
--- a/includes/Concerns/Purgeable.php
+++ b/includes/Concerns/Purgeable.php
@@ -2,6 +2,9 @@
namespace NewfoldLabs\WP\Module\Performance\Concerns;
+/**
+ * Interface for cache types that can be purged.
+ */
interface Purgeable {
/**
@@ -14,10 +17,9 @@ public function purgeAll();
/**
* Purge a specific URL for the given cache type.
*
- * @param string $url
+ * @param string $url The URL to purge.
*
* @return void
*/
public function purgeUrl( $url );
-
}
diff --git a/includes/OptionListener.php b/includes/OptionListener.php
index 0486d61..33f27c5 100644
--- a/includes/OptionListener.php
+++ b/includes/OptionListener.php
@@ -2,6 +2,9 @@
namespace NewfoldLabs\WP\Module\Performance;
+/**
+ * Class to monitor changes to an option.
+ */
class OptionListener {
/**
@@ -21,18 +24,17 @@ class OptionListener {
/**
* Constructor
*
- * @param string $optionName The name of the option to monitor.
- * @param callable $callable The callback function to be called on change.
+ * @param string $option_name The name of the option to monitor.
+ * @param callable $callback The callback function to be called on change.
*/
- public function __construct( string $optionName, callable $callable ) {
+ public function __construct( string $option_name, callable $callback ) {
- $this->callable = $callable;
- $this->option = $optionName;
-
- add_action( "add_option_{$optionName}", [ $this, 'onAdd' ], 10, 2 );
- add_action( "update_option_{$optionName}", [ $this, 'onUpdate' ], 10, 2 );
- add_action( "delete_option_{$optionName}", [ $this, 'onDelete' ] );
+ $this->callable = $callback;
+ $this->option = $option_name;
+ add_action( "add_option_{$option_name}", array( $this, 'onAdd' ), 10, 2 );
+ add_action( "update_option_{$option_name}", array( $this, 'onUpdate' ), 10, 2 );
+ add_action( "delete_option_{$option_name}", array( $this, 'onDelete' ) );
}
/**
@@ -48,12 +50,12 @@ public function onAdd( $option, $value ) {
/**
* Call function when an option value is updated.
*
- * @param mixed $oldValue The old option value.
- * @param mixed $newValue The new option value.
+ * @param mixed $old_value The old option value.
+ * @param mixed $new_value The new option value.
*/
- public function onUpdate( $oldValue, $newValue ) {
- if ( $oldValue !== $newValue ) {
- call_user_func( $this->callable, $newValue, $this->option );
+ public function onUpdate( $old_value, $new_value ) {
+ if ( $old_value !== $new_value ) {
+ call_user_func( $this->callable, $new_value, $this->option );
}
}
@@ -63,5 +65,4 @@ public function onUpdate( $oldValue, $newValue ) {
public function onDelete() {
call_user_func( $this->callable, null, $this->option );
}
-
}
diff --git a/includes/Performance.php b/includes/Performance.php
index e414143..23e9570 100644
--- a/includes/Performance.php
+++ b/includes/Performance.php
@@ -17,7 +17,7 @@
use Automattic\Jetpack\Current_Plan;
/**
- * Performance Class
+ * Main class for the performance module.
*/
class Performance {
diff --git a/includes/PerformanceFeature.php b/includes/PerformanceFeature.php
index 624856d..7f23857 100644
--- a/includes/PerformanceFeature.php
+++ b/includes/PerformanceFeature.php
@@ -7,10 +7,7 @@
use function NewfoldLabs\WP\ModuleLoader\container as getContainer;
/**
- * Child class for a feature
- *
- * Child classes should define a name property as the feature name for all API calls. This name will be used in the registry.
- * Child class naming convention is {FeatureName}Feature.
+ * Set up the performance feature.
*/
class PerformanceFeature extends \NewfoldLabs\WP\Module\Features\Feature {
diff --git a/includes/PerformanceFeatureHooks.php b/includes/PerformanceFeatureHooks.php
index 6372a73..0b6ef42 100644
--- a/includes/PerformanceFeatureHooks.php
+++ b/includes/PerformanceFeatureHooks.php
@@ -1,4 +1,5 @@
htaccess->readContent();
$lines = array_map( 'trim', convertContentToLines( $content ) );
@@ -60,7 +68,7 @@ public function addHeader( string $name, string $value ) {
$this->setHeaders(
array_merge(
$this->parseHeaders(),
- [ $name => $value ]
+ array( $name => $value )
)
);
}
@@ -68,7 +76,7 @@ public function addHeader( string $name, string $value ) {
/**
* Add multiple headers at once.
*
- * @param string[] $headers
+ * @param string[] $headers Headers to add.
*/
public function addHeaders( array $headers ) {
$headers = array_merge( $this->parseHeaders(), $headers );
@@ -90,13 +98,13 @@ public function removeHeader( $name ) {
* Remove all headers.
*/
public function removeAllHeaders() {
- $this->setHeaders( [] );
+ $this->setHeaders( array() );
}
/**
* Set headers.
*
- * @param array $headers
+ * @param array $headers Headers to set.
*/
public function setHeaders( array $headers ) {
@@ -108,11 +116,10 @@ public function setHeaders( array $headers ) {
$content = '' . PHP_EOL;
foreach ( $headers as $key => $value ) {
- $content .= "\t" . "Header set {$key} \"{$value}\"" . PHP_EOL;
+ $content .= "\tHeader set {$key} \"{$value}\"" . PHP_EOL;
}
$content .= '';
$this->htaccess->addContent( $content );
}
-
}
diff --git a/includes/functions.php b/includes/functions.php
index 7b76a38..63bb25e 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -14,18 +14,18 @@ function get_default_cache_exclusions() {
/**
* Get the current cache level.
*
- * @return int
+ * @return int Cache level.
*/
-function getCacheLevel() {
+function getCacheLevel() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return absint( get_option( Performance::OPTION_CACHE_LEVEL, 2 ) );
}
/**
* Get available cache levels.
*
- * @return string[]
+ * @return string[] Cache levels.
*/
-function getCacheLevels() {
+function getCacheLevels() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return array(
0 => 'Off', // Disable caching
1 => 'Assets Only', // Cache assets only
@@ -37,7 +37,7 @@ function getCacheLevels() {
/**
* Output the cache level select field.
*/
-function getCacheLevelDropdown() {
+function getCacheLevelDropdown() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
$cacheLevels = getCacheLevels();
$currentCacheLevel = getCacheLevel();
@@ -58,16 +58,16 @@ function getCacheLevelDropdown() {
/**
* Get the "Skip WordPress 404 Handling for Static Files" option.
*
- * @return bool
+ * @return bool Whether to skip 404 handling for static files.
*/
-function getSkip404Option() {
+function getSkip404Option() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return (bool) get_option( Performance::OPTION_SKIP_404, true );
}
/**
* Output the "Skip WordPress 404 Handling for Static Files" input field.
*/
-function getSkip404InputField() {
+function getSkip404InputField() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
$name = Performance::OPTION_SKIP_404;
$value = getSkip404Option();
$label = __( 'Skip WordPress 404 Handling for Static Files', 'newfold-performance-module' );
@@ -87,7 +87,7 @@ function getSkip404InputField() {
*
* @return bool
*/
-function shouldCachePages() {
+function shouldCachePages() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return getCacheLevel() > 1;
}
@@ -96,22 +96,22 @@ function shouldCachePages() {
*
* @return bool
*/
-function shouldCacheAssets() {
+function shouldCacheAssets() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return getCacheLevel() > 0;
}
/**
* Remove a directory.
*
- * @param string $path
+ * @param string $path Path to the directory.
*/
-function removeDirectory( $path ) {
+function removeDirectory( $path ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! is_dir( $path ) ) {
return;
}
$files = glob( $path . '/*' );
foreach ( $files as $file ) {
- is_dir( $file ) ? removeDirectory( $file ) : unlink( $file );
+ is_dir( $file ) ? removeDirectory( $file ) : wp_delete_file( $file );
}
rmdir( $path );
}
@@ -124,7 +124,7 @@ function removeDirectory( $path ) {
*
* @return string
*/
-function toSnakeCase( string $value, string $delimiter = '_' ) {
+function toSnakeCase( string $value, string $delimiter = '_' ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! ctype_lower( $value ) ) {
$value = preg_replace( '/(\s+)/u', '', ucwords( $value ) );
$value = trim( mb_strtolower( preg_replace( '/([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)/u', '$1' . $delimiter, $value ), 'UTF-8' ), $delimiter );
@@ -140,7 +140,7 @@ function toSnakeCase( string $value, string $delimiter = '_' ) {
*
* @return string
*/
-function toStudlyCase( $value ) {
+function toStudlyCase( $value ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return str_replace( ' ', '', ucwords( str_replace( array( '-', '_' ), ' ', $value ) ) );
}
@@ -166,4 +166,4 @@ function get_scripts_path( $script_name = '' ) {
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
return "vendor/newfold-labs/wp-module-performance/scripts/$script_name$suffix.js";
-}
\ No newline at end of file
+}