diff --git a/Generic_WidgetBoldGrid.php b/Generic_WidgetBoldGrid.php
index 43e331a5b..f05c81055 100644
--- a/Generic_WidgetBoldGrid.php
+++ b/Generic_WidgetBoldGrid.php
@@ -73,7 +73,7 @@ private static function should_show_widget() {
 		);
 
 		foreach ( $plugins as $plugin ) {
-			if ( in_array( $plugin, $backup_plugins ) ) {
+			if ( in_array( $plugin, $backup_plugins, true ) ) {
 				return false;
 			}
 		}
diff --git a/Licensing_AdminActions.php b/Licensing_AdminActions.php
index 37523e215..4d1f67eef 100644
--- a/Licensing_AdminActions.php
+++ b/Licensing_AdminActions.php
@@ -1,53 +1,80 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: Licensing_AdminActions.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class Licensing_AdminActions
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ */
 class Licensing_AdminActions {
-
+	/**
+	 * Config
+	 *
+	 * @var Config
+	 */
 	private $_config = null;
 
-	function __construct() {
+	/**
+	 * Initializes the Licensing_AdminActions class.
+	 *
+	 * @return void
+	 */
+	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
-
-
 	/**
-	 *  test action
+	 * Handles the purchase of a plugin license.
+	 *
+	 * @return void
 	 */
-	function w3tc_licensing_buy_plugin() {
-		$data_src = $this->param( 'data_src' );
+	public function w3tc_licensing_buy_plugin() {
+		$data_src  = $this->param( 'data_src' );
 		$renew_key = $this->param( 'renew_key' );
 		$client_id = $this->param( 'client_id' );
 
-		$iframe_url = Licensing_Core::purchase_url( $data_src, $renew_key,
-			$client_id );
+		$iframe_url = Licensing_Core::purchase_url( $data_src, $renew_key, $client_id );
 
 		include W3TC_INC_DIR . '/lightbox/purchase.php';
 	}
 
-
-
+	/**
+	 * Retrieves and sanitizes a request parameter.
+	 *
+	 * @param string $name The name of the parameter to retrieve.
+	 *
+	 * @return string The sanitized parameter value.
+	 */
 	private function param( $name ) {
 		$param = Util_Request::get_string( $name );
 		return preg_replace( '/[^0-9a-zA-Z._\-]/', '', isset( $param ) ? $param : '' );
 	}
 
 	/**
-	 * Self test action
+	 * Handles the upgrade of a plugin license.
+	 *
+	 * @return void
 	 */
-	function w3tc_licensing_upgrade() {
-		$data_src = $this->param( 'data_src' );
+	public function w3tc_licensing_upgrade() {
+		$data_src  = $this->param( 'data_src' );
 		$renew_key = $this->param( 'renew_key' );
 		$client_id = $this->param( 'client_id' );
 
 		include W3TC_INC_DIR . '/lightbox/upgrade.php';
 	}
 
-
-
-	function w3tc_licensing_check_key() {
+	/**
+	 * Checks and activates the license key.
+	 *
+	 * @return void
+	 */
+	public function w3tc_licensing_check_key() {
 		$state = Dispatcher::config_state();
 		$state->set( 'license.next_check', 0 );
 		$state->save();
@@ -56,9 +83,12 @@ function w3tc_licensing_check_key() {
 		Util_Admin::redirect( array(), true );
 	}
 
-
-
-	function w3tc_licensing_reset_rooturi() {
+	/**
+	 * Resets the root URI for the license.
+	 *
+	 * @return void
+	 */
+	public function w3tc_licensing_reset_rooturi() {
 		$license_key = $this->_config->get_string( 'plugin.license_key' );
 
 		$state = Dispatcher::config_state();
@@ -70,64 +100,88 @@ function w3tc_licensing_reset_rooturi() {
 		$license = Licensing_Core::check_license( $license_key, W3TC_VERSION );
 		if ( $license ) {
 			$status = $license->license_status;
-			if ( substr( $status . '.', 0, 7 ) == 'active.' ) {
-				Util_Admin::redirect_with_custom_messages2( array(
-						'notes' => array( 'Your license has been reset already. Activated for this website now.' )
-					), true );
+			if ( 'active.' === substr( $status . '.', 0, 7 ) ) {
+				Util_Admin::redirect_with_custom_messages2(
+					array(
+						'notes' => array( 'Your license has been reset already. Activated for this website now.' ),
+					),
+					true
+				);
 			}
 		}
 
-		$r = Licensing_Core::reset_rooturi(
-			$this->_config->get_string( 'plugin.license_key' ), W3TC_VERSION );
+		$r = Licensing_Core::reset_rooturi( $this->_config->get_string( 'plugin.license_key' ), W3TC_VERSION );
 
-		if ( isset( $r->status ) && $r->status == 'done' ) {
-			Util_Admin::redirect_with_custom_messages2( array(
-					'notes' => array( 'Email with a link for license reset was sent to you' )
-				), true );
+		if ( isset( $r->status ) && 'done' === $r->status ) {
+			Util_Admin::redirect_with_custom_messages2(
+				array(
+					'notes' => array( 'Email with a link for license reset was sent to you' ),
+				),
+				true
+			);
 		} else {
-			Util_Admin::redirect_with_custom_messages2( array(
-					'errors' => array( 'Failed to reset license' )
-				), true );
+			Util_Admin::redirect_with_custom_messages2(
+				array(
+					'errors' => array( 'Failed to reset license' ),
+				),
+				true
+			);
 		}
 	}
 
-
-
-	static public function w3tc_licensing_terms_accept() {
+	/**
+	 * Accepts the terms and conditions of the license.
+	 *
+	 * @return void
+	 */
+	public static function w3tc_licensing_terms_accept() {
 		Licensing_Core::terms_accept();
 
-		Util_Admin::redirect_with_custom_messages2( array(
-				'notes' => array( 'Terms have been accepted' )
-			), true );
+		Util_Admin::redirect_with_custom_messages2(
+			array(
+				'notes' => array( 'Terms have been accepted' ),
+			),
+			true
+		);
 	}
 
-
-
-	static public function w3tc_licensing_terms_decline() {
+	/**
+	 * Declines the terms and conditions of the license.
+	 *
+	 * @return void
+	 */
+	public static function w3tc_licensing_terms_decline() {
 		$c = Dispatcher::config();
-		if ( !Util_Environment::is_w3tc_pro( $c ) ) {
+		if ( ! Util_Environment::is_w3tc_pro( $c ) ) {
 			$state_master = Dispatcher::config_state_master();
 			$state_master->set( 'license.community_terms', 'decline' );
 			$state_master->save();
-		} else {
-			// not called in this mode
 		}
 
-		Util_Admin::redirect_with_custom_messages2( array(
-				'notes' => array( 'Terms have been declined' )
-			), true );
+		Util_Admin::redirect_with_custom_messages2(
+			array(
+				'notes' => array( 'Terms have been declined' ),
+			),
+			true
+		);
 	}
 
-
-
-	static public function w3tc_licensing_terms_refresh() {
+	/**
+	 * Refreshes the acceptance or postponement of license terms.
+	 *
+	 * @return void
+	 */
+	public static function w3tc_licensing_terms_refresh() {
 		$state = Dispatcher::config_state();
 		$state->set( 'license.next_check', 0 );
 		$state->set( 'license.terms', 'postpone' );
 		$state->save();
 
-		Util_Admin::redirect_with_custom_messages2( array(
-				'notes' => array( 'Thank you for your reaction' )
-			), true );
+		Util_Admin::redirect_with_custom_messages2(
+			array(
+				'notes' => array( 'Thank you for your reaction' ),
+			),
+			true
+		);
 	}
 }
diff --git a/Licensing_Core.php b/Licensing_Core.php
index 51e1b6278..5cbe26512 100644
--- a/Licensing_Core.php
+++ b/Licensing_Core.php
@@ -1,149 +1,228 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: Licensing_Core.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class Licensing_Core
+ */
 class Licensing_Core {
 	/**
-	 * Activates a license
+	 * Activates a license for the plugin.
+	 *
+	 * @param string $license License key to be activated.
+	 * @param string $version Version of the plugin being licensed.
+	 *
+	 * @return mixed|false Decoded license data on success, false on failure.
 	 */
-	static public function activate_license( $license, $version ) {
+	public static function activate_license( $license, $version ) {
 		$state = Dispatcher::config_state_master();
 
-		// data to send in our API request
+		// data to send in our API request.
 		$api_params = array(
-			'edd_action'=> 'activate_license',
-			'license' => $license,   // legacy
-			'license_key' => $license,
-			'home_url' => network_home_url(),
-			'item_name' => urlencode( W3TC_PURCHASE_PRODUCT_NAME ), // the name of our product in EDD
+			'edd_action'          => 'activate_license',
+			'license'             => $license,   // legacy.
+			'license_key'         => $license,
+			'home_url'            => network_home_url(),
+			'item_name'           => rawurlencode( W3TC_PURCHASE_PRODUCT_NAME ), // the name of our product in EDD.
 			'plugin_install_date' => gmdate( 'Y-m-d\\TH:i:s\\Z', $state->get_integer( 'common.install' ) ),
-			'r' => rand(),
-			'version' => $version
+			'r'                   => wp_rand(),
+			'version'             => $version,
 		);
 
 		// Call the custom API.
-		$response = wp_remote_get( add_query_arg( $api_params, W3TC_LICENSE_API_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
-		if ( is_wp_error( $response ) )
+		$response = wp_remote_get(
+			add_query_arg(
+				$api_params,
+				W3TC_LICENSE_API_URL
+			),
+			array(
+				'timeout'   => 15,
+				'sslverify' => false,
+			)
+		);
+
+		if ( is_wp_error( $response ) ) {
 			return false;
+		}
 
-		// decode the license data
+		// decode the license data.
 		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
+
 		return $license_data;
 	}
 
 	/**
-	 * Deactivates a license
+	 * Deactivates a license for the plugin.
+	 *
+	 * @param string $license License key to be deactivated.
+	 *
+	 * @return bool True if the license was successfully deactivated, false otherwise.
 	 */
-	static public function deactivate_license( $license ) {
-		// data to send in our API request
+	public static function deactivate_license( $license ) {
+		// data to send in our API request.
 		$api_params = array(
-			'edd_action'=> 'deactivate_license',
-			'license' => $license,   // legacy
+			'edd_action'  => 'deactivate_license',
+			'license'     => $license,   // legacy.
 			'license_key' => $license,
-			'home_url' => network_home_url(),
-			'item_name' => urlencode( W3TC_PURCHASE_PRODUCT_NAME ), // the name of our product in EDD,
-			'r' => rand()
+			'home_url'    => network_home_url(),
+			'item_name'   => rawurlencode( W3TC_PURCHASE_PRODUCT_NAME ), // the name of our product in EDD.
+			'r'           => wp_rand(),
 		);
 
 		// Call the custom API.
-		$response = wp_remote_get( add_query_arg( $api_params, W3TC_LICENSE_API_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
+		$response = wp_remote_get(
+			add_query_arg(
+				$api_params,
+				W3TC_LICENSE_API_URL
+			),
+			array(
+				'timeout'   => 15,
+				'sslverify' => false,
+			)
+		);
 
-		// make sure the response came back okay
-		if ( is_wp_error( $response ) )
+		// make sure the response came back okay.
+		if ( is_wp_error( $response ) ) {
 			return false;
+		}
 
-		// decode the license data
+		// decode the license data.
 		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
-		return $license_data;
+
+		// $license_data->license will be either "deactivated" or "failed"
+		return 'deactivated' === $license_data->license;
 	}
 
 	/**
-	 * Checks if a license key is still valid
+	 * Checks the status of a license.
+	 *
+	 * @param string $license License key to be checked.
+	 * @param string $version Version of the plugin being checked.
+	 *
+	 * @return mixed|false Decoded license data on success, false on failure.
 	 */
-	static public function check_license( $license, $version ) {
+	public static function check_license( $license, $version ) {
 		global $wp_version;
 
 		$api_params = array(
-			'edd_action' => 'check_license',
-			'license' => $license,   // legacy
+			'edd_action'  => 'check_license',
+			'license'     => $license,   // legacy.
 			'license_key' => $license,
-			'home_url' => network_home_url(),
-			'item_name' => urlencode( W3TC_PURCHASE_PRODUCT_NAME ),
-			'r' => rand(),
-			'version' => $version
+			'home_url'    => network_home_url(),
+			'item_name'   => rawurlencode( W3TC_PURCHASE_PRODUCT_NAME ),
+			'r'           => wp_rand(),
+			'version'     => $version,
 		);
 
 		// Call the custom API.
-		$response = wp_remote_get( add_query_arg( $api_params, W3TC_LICENSE_API_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
+		$response = wp_remote_get(
+			add_query_arg(
+				$api_params,
+				W3TC_LICENSE_API_URL
+			),
+			array(
+				'timeout'   => 15,
+				'sslverify' => false,
+			)
+		);
 
-		if ( is_wp_error( $response ) )
+		if ( is_wp_error( $response ) ) {
 			return false;
+		}
 
 		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
+
 		return $license_data;
 	}
 
-	static public function reset_rooturi( $license, $version ) {
-		// data to send in our API request
+	/**
+	 * Resets the root URI for a license.
+	 *
+	 * @param string $license License key associated with the reset request.
+	 * @param string $version Version of the plugin associated with the reset request.
+	 *
+	 * @return mixed|false Decoded status data on success, false on failure.
+	 */
+	public static function reset_rooturi( $license, $version ) {
+		// data to send in our API request.
 		$api_params = array(
-			'edd_action'=> 'reset_rooturi',
+			'edd_action'  => 'reset_rooturi',
 			'license_key' => $license,
-			'home_url' => network_home_url(),
-			'item_name' => urlencode( W3TC_PURCHASE_PRODUCT_NAME ), // the name of our product in EDD
-			'r' => rand(),
-			'version' => $version
+			'home_url'    => network_home_url(),
+			'item_name'   => rawurlencode( W3TC_PURCHASE_PRODUCT_NAME ), // the name of our product in EDD.
+			'r'           => wp_rand(),
+			'version'     => $version,
 		);
 
 		// Call the custom API.
-		$response = wp_remote_get( add_query_arg( $api_params, W3TC_LICENSE_API_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
-		if ( is_wp_error( $response ) )
+		$response = wp_remote_get(
+			add_query_arg(
+				$api_params,
+				W3TC_LICENSE_API_URL
+			),
+			array(
+				'timeout'   => 15,
+				'sslverify' => false,
+			)
+		);
+
+		if ( is_wp_error( $response ) ) {
 			return false;
+		}
 
-		// decode the license data
+		// decode the license data.
 		$status = json_decode( wp_remote_retrieve_body( $response ) );
+
 		return $status;
 	}
 
-	static public function terms_accept() {
+	/**
+	 * Accepts the terms of service for the community license.
+	 *
+	 * @return void
+	 */
+	public static function terms_accept() {
 		$c = Dispatcher::config();
-		if ( !Util_Environment::is_w3tc_pro( $c ) ) {
+		if ( ! Util_Environment::is_w3tc_pro( $c ) ) {
 			$state_master = Dispatcher::config_state_master();
 			$state_master->set( 'license.community_terms', 'accept' );
 			$state_master->save();
 
 			$c->set( 'common.track_usage', true );
 			$c->save();
-		} else {
-			// not called in this mode
 		}
 	}
 
-
-
-	static public function purchase_url( $data_src = '', $renew_key = '', $client_id = '' ) {
+	/**
+	 * Generates a purchase URL for the plugin.
+	 *
+	 * @param string $data_src  Optional data source for the URL.
+	 * @param string $renew_key Optional renewal key for the license.
+	 * @param string $client_id Optional client ID associated with the purchase.
+	 *
+	 * @return string URL for purchasing or renewing the plugin.
+	 */
+	public static function purchase_url( $data_src = '', $renew_key = '', $client_id = '' ) {
 		$state = Dispatcher::config_state_master();
 		return W3TC_PURCHASE_URL .
-			( strpos( W3TC_PURCHASE_URL, '?' ) === FALSE ? '?' : '&' ) .
-			'install_date=' . urlencode( $state->get_integer( 'common.install' ) ) .
-			( empty( $data_src ) ? '' : '&data_src=' . urlencode( $data_src ) ) .
-			( empty( $renew_key ) ? '' : '&renew_key=' . urlencode( $renew_key ) ) .
-			( empty( $client_id ) ? '' : '&client_id=' . urlencode( $client_id ) );
+			( strpos( W3TC_PURCHASE_URL, '?' ) === false ? '?' : '&' ) .
+			'install_date=' . rawurlencode( $state->get_integer( 'common.install' ) ) .
+			( empty( $data_src ) ? '' : '&data_src=' . rawurlencode( $data_src ) ) .
+			( empty( $renew_key ) ? '' : '&renew_key=' . rawurlencode( $renew_key ) ) .
+			( empty( $client_id ) ? '' : '&client_id=' . rawurlencode( $client_id ) );
 	}
 
 	/**
-	 * Get the terms of service choice.
+	 * Retrieves the user's terms of service choice.
 	 *
 	 * @since 2.2.2
 	 *
-	 * @static
-	 *
-	 * @see \W3TC\Util_Environment::is_w3tc_pro()
-	 * @see \W3TC\Dispatcher::config_state()
-	 * @see \W3TC\Dispatcher::config_state_master()
-	 * @see \W3TC\ConfigState::get_string()
-	 *
-	 * @return string
+	 * @return string Terms of service choice as stored in the configuration.
 	 */
 	public static function get_tos_choice() {
 		$config = Dispatcher::config();
diff --git a/Licensing_Plugin_Admin.php b/Licensing_Plugin_Admin.php
index b5e878b3c..212bd309d 100644
--- a/Licensing_Plugin_Admin.php
+++ b/Licensing_Plugin_Admin.php
@@ -1,20 +1,46 @@
 <?php
+/**
+ * File: Licensing_Plugin_Admin.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Licensing_Plugin_Admin
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
+ * phpcs:disable Generic.CodeAnalysis.EmptyStatement
+ */
 class Licensing_Plugin_Admin {
 	/**
 	 * Config
+	 *
+	 * @var Config
 	 */
 	private $_config = null;
 
-	function __construct() {
+	/**
+	 * Constructor for the Licensing Plugin Admin class.
+	 *
+	 * Initializes the configuration.
+	 *
+	 * @return void
+	 */
+	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs plugin
+	 * Registers hooks for the plugin's admin functionality.
+	 *
+	 * Adds actions and filters for admin initialization, AJAX, UI updates, and admin bar menu.
+	 *
+	 * @return void
 	 */
-	function run() {
+	public function run() {
 		add_action( 'admin_init', array( $this, 'admin_init' ) );
 		add_action( 'w3tc_config_ui_save-w3tc_general', array( $this, 'possible_state_change' ), 2, 10 );
 
@@ -23,6 +49,13 @@ function run() {
 		add_filter( 'w3tc_admin_bar_menu', array( $this, 'w3tc_admin_bar_menu' ) );
 	}
 
+	/**
+	 * Adds licensing menu items to the admin bar.
+	 *
+	 * @param array $menu_items Existing admin bar menu items.
+	 *
+	 * @return array Modified admin bar menu items.
+	 */
 	public function w3tc_admin_bar_menu( $menu_items ) {
 		if ( ! Util_Environment::is_w3tc_pro( $this->_config ) ) {
 			$menu_items['00020.licensing'] = array(
@@ -60,10 +93,22 @@ public function w3tc_admin_bar_menu( $menu_items ) {
 		return $menu_items;
 	}
 
+	/**
+	 * Handles the licensing upgrade action.
+	 *
+	 * Adds a hook to modify the admin head for licensing upgrades.
+	 *
+	 * @return void
+	 */
 	public function w3tc_message_action_licensing_upgrade() {
 		add_action( 'admin_head', array( $this, 'admin_head_licensing_upgrade' ) );
 	}
 
+	/**
+	 * Outputs JavaScript for the licensing upgrade page.
+	 *
+	 * @return void
+	 */
 	public function admin_head_licensing_upgrade() {
 		?>
 		<script type="text/javascript">
@@ -76,12 +121,14 @@ public function admin_head_licensing_upgrade() {
 	}
 
 	/**
+	 * Handles possible state changes for plugin licensing.
 	 *
+	 * @param object $config     Current configuration object.
+	 * @param object $old_config Previous configuration object.
 	 *
-	 * @param Config  $config
-	 * @param Config  $old_config
+	 * @return void
 	 */
-	function possible_state_change( $config, $old_config ) {
+	public function possible_state_change( $config, $old_config ) {
 		$changed     = false;
 		$new_key     = $config->get_string( 'plugin.license_key' );
 		$new_key_set = ! empty( $new_key );
@@ -180,9 +227,13 @@ function possible_state_change( $config, $old_config ) {
 	}
 
 	/**
-	 * Setup notices actions
+	 * Initializes admin-specific features and hooks.
+	 *
+	 * Adds admin notices, UI filters, and license status checks.
+	 *
+	 * @return void
 	 */
-	function admin_init() {
+	public function admin_init() {
 		$capability = apply_filters( 'w3tc_capability_admin_notices', 'manage_options' );
 
 		$this->maybe_update_license_status();
@@ -204,6 +255,14 @@ function admin_init() {
 		}
 	}
 
+	/**
+	 * Checks if a status starts with a specific prefix.
+	 *
+	 * @param string $s           The status string.
+	 * @param string $starts_with The prefix to check against.
+	 *
+	 * @return bool True if the status starts with the prefix, false otherwise.
+	 */
 	private function _status_is( $s, $starts_with ) {
 		$s           .= '.';
 		$starts_with .= '.';
@@ -211,9 +270,14 @@ private function _status_is( $s, $starts_with ) {
 	}
 
 	/**
-	 * Run license status check and display messages
+	 * Displays admin notices related to licensing.
+	 *
+	 * phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
+	 * phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
+	 *
+	 * @return void
 	 */
-	function admin_notices() {
+	public function admin_notices() {
 		$message = '';
 
 		$state  = Dispatcher::config_state();
@@ -255,7 +319,7 @@ function admin_notices() {
 						),
 						'<a class="w3tc_licensing_reset_rooturi" href="' . Util_Ui::url(
 							array(
-								'page'                         => 'w3tc_general',
+								'page'                         => 'w3tc_general', // phpcs:ignore WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
 								'w3tc_licensing_reset_rooturi' => 'y',
 							)
 						) . '">',
@@ -327,7 +391,14 @@ function admin_notices() {
 		}
 	}
 
-	function w3tc_notes( $notes ) {
+	/**
+	 * Modifies the notes displayed in the W3TC UI.
+	 *
+	 * @param array $notes Existing notes to display.
+	 *
+	 * @return array Modified notes with licensing terms.
+	 */
+	public function w3tc_notes( $notes ) {
 		$terms        = '';
 		$state_master = Dispatcher::config_state_master();
 
@@ -394,9 +465,11 @@ function w3tc_notes( $notes ) {
 	}
 
 	/**
+	 * Updates the license status if needed.
 	 *
+	 * Performs a license check and updates the configuration state accordingly.
 	 *
-	 * @return string
+	 * @return string The updated license status.
 	 */
 	private function maybe_update_license_status() {
 		$state = Dispatcher::config_state();
@@ -433,9 +506,13 @@ private function maybe_update_license_status() {
 		}
 
 		if ( 'no_key' === $status ) {
+			// Do nothing.
 		} elseif ( $this->_status_is( $status, 'invalid' ) ) {
+			// Do nothing.
 		} elseif ( $this->_status_is( $status, 'inactive' ) ) {
+			// Do nothing.
 		} elseif ( $this->_status_is( $status, 'active' ) ) {
+			// Do nothing.
 		} else {
 			$check_timeout = 60;
 		}
@@ -449,14 +526,19 @@ private function maybe_update_license_status() {
 			try {
 				$this->_config->set( 'plugin.type', $plugin_type );
 				$this->_config->save();
-			} catch ( \Exception $ex ) {
+			} catch ( \Exception $ex ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
 				// missing exception handle?
 			}
 		}
 		return $status;
 	}
 
-	function get_license_key() {
+	/**
+	 * Retrieves the license key for the plugin.
+	 *
+	 * @return string The license key.
+	 */
+	public function get_license_key() {
 		$license_key = $this->_config->get_string( 'plugin.license_key', '' );
 		if ( '' === $license_key ) {
 			$license_key = ini_get( 'w3tc.license_key' );
diff --git a/Minify_AutoCss.php b/Minify_AutoCss.php
index 6f1d8f88a..760262d42 100644
--- a/Minify_AutoCss.php
+++ b/Minify_AutoCss.php
@@ -1,8 +1,28 @@
 <?php
+/**
+ * File: Minify_AutoCss.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Minify_AutoCss
+ */
 class Minify_AutoCss {
+	/**
+	 * Config
+	 *
+	 * @var Config
+	 */
 	private $config;
+
+	/**
+	 * Buffer
+	 *
+	 * @var string
+	 */
 	private $buffer;
 
 	/**
@@ -46,43 +66,48 @@ class Minify_AutoCss {
 	 * @var integer
 	 */
 	private $debug = false;
+
+	/**
+	 * Embed to HTML flag
+	 *
+	 * @var bool
+	 */
 	private $embed_to_html;
 
 	/**
-	 * Constructor
+	 * Constructor method for initializing the Minify_AutoCss class.
 	 *
-	 * @param unknown $config
-	 * @param unknown $buffer
-	 * @param unknown $minify_helpers
+	 * @param object $config          Configuration object containing settings.
+	 * @param string $buffer          The content buffer to process.
+	 * @param object $minify_helpers  Helper object for minification operations.
+	 *
+	 * @return void
 	 */
-	function __construct( $config, $buffer, $minify_helpers ) {
-		$this->config = $config;
-		$this->debug = $config->get_boolean( 'minify.debug' );
-		$this->buffer = $buffer;
+	public function __construct( $config, $buffer, $minify_helpers ) {
+		$this->config         = $config;
+		$this->debug          = $config->get_boolean( 'minify.debug' );
+		$this->buffer         = $buffer;
 		$this->minify_helpers = $minify_helpers;
 
-		// ignored files
-		$this->ignore_css_files = $this->config->get_array(
-			'minify.reject.files.css' );
-		$this->ignore_css_files = array_map( array( '\W3TC\Util_Environment',
-			'normalize_file' ), $this->ignore_css_files );
+		// ignored files.
+		$this->ignore_css_files = $this->config->get_array( 'minify.reject.files.css' );
+		$this->ignore_css_files = array_map( array( '\W3TC\Util_Environment', 'normalize_file' ), $this->ignore_css_files );
 
 		$this->embed_to_html = $this->config->get_boolean( 'minify.css.embed' );
 	}
 
 	/**
-	 * Does auto-minification
+	 * Executes the main functionality of the class, processing and minifying CSS styles.
 	 *
-	 * @return string buffer of minified content
+	 * @return string The processed buffer after applying CSS minification.
 	 */
 	public function execute() {
-		// find all style tags
+		// find all style tags.
 		$buffer_nocomments = preg_replace( '~<!--.*?-->\s*~s', '', $this->buffer );
-		$matches = null;
+		$matches           = null;
 
-		// end of <head> means another group of styles, cannt be combined
-		if ( !preg_match_all( '~((<style\s*[^>]*>.*?</style>)|(<link\s+([^>]+)/?>(.*</link>)?))~is',
-				$buffer_nocomments, $matches ) ) {
+		// end of <head> means another group of styles, cannt be combined.
+		if ( ! preg_match_all( '~((<style\s*[^>]*>.*?</style>)|(<link\s+([^>]+)/?>(.*</link>)?))~is', $buffer_nocomments, $matches ) ) {
 			$matches = null;
 		}
 
@@ -91,15 +116,15 @@ public function execute() {
 		}
 
 		$style_tags = $matches[1];
-		$style_tags = apply_filters( 'w3tc_minify_css_style_tags',
-			$style_tags );
+		$style_tags = apply_filters( 'w3tc_minify_css_style_tags', $style_tags );
 
-		// pass styles
-		$this->embed_pos = null;
+		// pass styles.
+		$this->embed_pos       = null;
 		$this->files_to_minify = array();
 
-		for ( $n = 0; $n < count( $style_tags ); $n++ ) {
-			$this->process_style_tag( $style_tags[$n], $n );
+		$count = count( $style_tags );
+		for ( $n = 0; $n < $count; $n++ ) {
+			$this->process_style_tag( $style_tags[ $n ], $n );
 		}
 
 		$this->flush_collected( '' );
@@ -108,18 +133,20 @@ public function execute() {
 	}
 
 	/**
-	 * Returns list of minified styles
+	 * Retrieves the URLs of minified files for debugging purposes.
 	 *
-	 * @return array
+	 * @return array An array of URLs for minified files.
 	 */
 	public function get_debug_minified_urls() {
 		return $this->debug_minified_urls;
 	}
 
 	/**
-	 * Processes style tag
+	 * Processes individual style tags found in the buffer.
+	 *
+	 * @param string $style_tag        The style tag to process.
+	 * @param int    $style_tag_number The position of the style tag in the sequence.
 	 *
-	 * @param unknown $style_tag
 	 * @return void
 	 */
 	private function process_style_tag( $style_tag, $style_tag_number ) {
@@ -128,34 +155,38 @@ private function process_style_tag( $style_tag, $style_tag_number ) {
 		}
 
 		$tag_pos = strpos( $this->buffer, $style_tag );
-		if ( $tag_pos === false ) {
-			// style is external but not found, skip processing it
+		if ( false === $tag_pos ) {
+			// style is external but not found, skip processing it.
 			if ( $this->debug ) {
 				Minify_Core::log( 'style not found:' . $style_tag );
 			}
 			return;
 		}
 
-		$style_href = null;
+		$style_href   = null;
 		$causes_flush = true;
 		if ( preg_match( '~<link\s+([^>]+)/?>(.*</link>)?~Uis', $style_tag, $match ) ) {
-			// all link tags dont cause automatic flush since
-			// its minified or its not style <link> tag
+			// all link tags dont cause automatic flush since its minified or its not style <link> tag.
 			$causes_flush = false;
 
-			$attrs = array();
+			$attrs        = array();
 			$attr_matches = null;
-			if ( preg_match_all( '~(\w+)=["\']([^"\']*)["\']~', $match[1],
-					$attr_matches, PREG_SET_ORDER ) ) {
+			if ( preg_match_all( '~(\w+)=["\']([^"\']*)["\']~', $match[1], $attr_matches, PREG_SET_ORDER ) ) {
 				foreach ( $attr_matches as $attr_match ) {
-					$name = strtolower( $attr_match[1] );
-					$attrs[$name] = trim( $attr_match[2] );
+					$name           = strtolower( $attr_match[1] );
+					$attrs[ $name ] = trim( $attr_match[2] );
 				}
 			}
 
-			if ( isset( $attrs['href'] ) && isset( $attrs['rel'] ) &&
+			if (
+				isset( $attrs['href'] ) &&
+				isset( $attrs['rel'] ) &&
 				stristr( $attrs['rel'], 'stylesheet' ) !== false &&
-				( !isset( $attrs['media'] ) || stristr( $attrs['media'], 'print' ) === false ) ) {
+				(
+					! isset( $attrs['media'] ) ||
+					stristr( $attrs['media'], 'print' ) === false
+				)
+			) {
 				$style_href = $attrs['href'];
 			}
 		}
@@ -163,24 +194,26 @@ private function process_style_tag( $style_tag, $style_tag_number ) {
 		if ( $causes_flush ) {
 			$data = array(
 				'style_tag_original' => $style_tag,
-				'style_tag_new' => $style_tag,
-				'style_tag_number' => $style_tag_number,
-				'style_tag_pos' => $tag_pos,
-				'should_replace' => false,
-				'buffer' => $this->buffer
+				'style_tag_new'      => $style_tag,
+				'style_tag_number'   => $style_tag_number,
+				'style_tag_pos'      => $tag_pos,
+				'should_replace'     => false,
+				'buffer'             => $this->buffer,
 			);
 
-			$data = apply_filters( 'w3tc_minify_css_do_local_style_minification',
-				$data );
+			$data         = apply_filters( 'w3tc_minify_css_do_local_style_minification', $data );
 			$this->buffer = $data['buffer'];
 
 			if ( $data['should_replace'] ) {
-				$this->buffer = substr_replace( $this->buffer,
-					$data['style_tag_new'], $tag_pos,
-					strlen( $style_tag ) );
+				$this->buffer = substr_replace(
+					$this->buffer,
+					$data['style_tag_new'],
+					$tag_pos,
+					strlen( $style_tag )
+				);
 			}
 
-			// it's not external style, have to flush what we have before it
+			// it's not external style, have to flush what we have before it.
 			if ( $this->debug ) {
 				Minify_Core::log( 'its not link tag, flushing' );
 			}
@@ -189,6 +222,7 @@ private function process_style_tag( $style_tag, $style_tag_number ) {
 
 			return;
 		}
+
 		if ( empty( $style_href ) ) {
 			if ( $this->debug ) {
 				Minify_Core::log( 'its not style link tag' );
@@ -197,110 +231,129 @@ private function process_style_tag( $style_tag, $style_tag_number ) {
 		}
 
 		$style_href = Util_Environment::url_relative_to_full( $style_href );
-		$file = Util_Environment::url_to_docroot_filename( $style_href );
+		$file       = Util_Environment::url_to_docroot_filename( $style_href );
 
-		$step1_result = $this->minify_helpers->is_file_for_minification(
-			$style_href, $file );
-		if ( $step1_result == 'url' )
+		$step1_result = $this->minify_helpers->is_file_for_minification( $style_href, $file );
+		if ( 'url' === $step1_result ) {
 			$file = $style_href;
+		}
 
-		$step1 = !empty( $step1_result );
-		$step2 = !in_array( $file, $this->ignore_css_files );
+		$step1 = ! empty( $step1_result );
+		$step2 = ! in_array( $file, $this->ignore_css_files, true );
 
 		$do_tag_minification = $step1 && $step2;
-		$do_tag_minification = apply_filters(
-			'w3tc_minify_css_do_tag_minification',
-			$do_tag_minification, $style_tag, $file );
+		$do_tag_minification = apply_filters( 'w3tc_minify_css_do_tag_minification', $do_tag_minification, $style_tag, $file );
 
-		if ( !$do_tag_minification ) {
+		if ( ! $do_tag_minification ) {
 			if ( $this->debug ) {
-				Minify_Core::log( 'file ' . $file .
+				Minify_Core::log(
+					'file ' . $file .
 					' didnt pass minification check:' .
 					' file_for_min: ' . ( $step1 ? 'true' : 'false' ) .
-					' ignore_css_files: ' . ( $step2 ? 'true' : 'false' ) );
+					' ignore_css_files: ' . ( $step2 ? 'true' : 'false' )
+				);
 			}
 
 			$data = array(
 				'style_tag_original' => $style_tag,
-				'style_tag_new' => $style_tag,
-				'style_tag_number' => $style_tag_number,
-				'style_tag_pos' => $tag_pos,
-				'style_href' => $style_href,
-				'should_replace' => false,
-				'buffer' => $this->buffer
+				'style_tag_new'      => $style_tag,
+				'style_tag_number'   => $style_tag_number,
+				'style_tag_pos'      => $tag_pos,
+				'style_href'         => $style_href,
+				'should_replace'     => false,
+				'buffer'             => $this->buffer,
 			);
 
-			$data = apply_filters( 'w3tc_minify_css_do_excluded_tag_style_minification',
-				$data );
+			$data         = apply_filters( 'w3tc_minify_css_do_excluded_tag_style_minification', $data );
 			$this->buffer = $data['buffer'];
 
 			if ( $data['should_replace'] ) {
-				$this->buffer = substr_replace( $this->buffer,
-					$data['style_tag_new'], $tag_pos,
-					strlen( $style_tag ) );
+				$this->buffer = substr_replace(
+					$this->buffer,
+					$data['style_tag_new'],
+					$tag_pos,
+					strlen( $style_tag )
+				);
 			}
 
 			$this->flush_collected( $style_tag );
+
 			return;
 		}
 
 		$this->debug_minified_urls[] = $file;
-		$this->buffer = substr_replace( $this->buffer, '',
-			$tag_pos, strlen( $style_tag ) );
+		$this->buffer                = substr_replace(
+			$this->buffer,
+			'',
+			$tag_pos,
+			strlen( $style_tag )
+		);
 
-		// put minified file at the place of first tag
-		if ( count( $this->files_to_minify ) <= 0 )
+		// put minified file at the place of first tag.
+		if ( count( $this->files_to_minify ) <= 0 ) {
 			$this->embed_pos = $tag_pos;
+		}
+
 		$this->files_to_minify[] = $file;
 
-		if ( $this->config->get_string( 'minify.css.method' ) == 'minify' )
+		if ( 'minify' === $this->config->get_string( 'minify.css.method' ) ) {
 			$this->flush_collected( '' );
+		}
 	}
 
 	/**
-	 * Minifies collected styles
+	 * Flushes the collected files to be minified and embeds or replaces them in the buffer.
+	 *
+	 * @param string $last_style_tag The last style tag processed, used for determining flushing logic.
+	 *
+	 * @return void
 	 */
 	private function flush_collected( $last_style_tag ) {
-		if ( count( $this->files_to_minify ) <= 0 )
+		if ( count( $this->files_to_minify ) <= 0 ) {
 			return;
-		$do_flush_collected = apply_filters( 'w3tc_minify_css_do_flush_collected',
-			true, $last_style_tag, $this );
-		if ( !$do_flush_collected )
+		}
+
+		$do_flush_collected = apply_filters( 'w3tc_minify_css_do_flush_collected', true, $last_style_tag, $this );
+		if ( ! $do_flush_collected ) {
 			return;
+		}
 
-		// find embed position
+		// find embed position.
 		$embed_pos = $this->embed_pos;
 
-		// build minified style tag
+		// build minified style tag.
 		$data = array(
 			'files_to_minify' => $this->files_to_minify,
-			'embed_pos' => $embed_pos,
-			'buffer' => $this->buffer,
-			'embed_to_html' => $this->embed_to_html
+			'embed_pos'       => $embed_pos,
+			'buffer'          => $this->buffer,
+			'embed_to_html'   => $this->embed_to_html,
 		);
 
-		$data = apply_filters( 'w3tc_minify_css_step', $data );
+		$data         = apply_filters( 'w3tc_minify_css_step', $data );
 		$this->buffer = $data['buffer'];
 
-		if ( !empty( $data['files_to_minify'] ) ) {
+		if ( ! empty( $data['files_to_minify'] ) ) {
 			$style_data = $this->minify_helpers->generate_css_style_tag(
 				$data['files_to_minify'],
-				$data['embed_to_html'] );
+				$data['embed_to_html']
+			);
 
-			$data['style_to_embed_url'] = $style_data['url'];
+			$data['style_to_embed_url']  = $style_data['url'];
 			$data['style_to_embed_body'] = $style_data['body'];
-			$data = apply_filters( 'w3tc_minify_css_step_style_to_embed',
-				$data );
-			$this->buffer = $data['buffer'];
+			$data                        = apply_filters( 'w3tc_minify_css_step_style_to_embed', $data );
+			$this->buffer                = $data['buffer'];
 
 			if ( $this->config->getf_boolean( 'minify.css.http2push' ) ) {
-				$this->minify_helpers->http2_header_add(
-					$data['style_to_embed_url'], 'style' );
+				$this->minify_helpers->http2_header_add( $data['style_to_embed_url'], 'style' );
 			}
 
-			// replace
-			$this->buffer = substr_replace( $this->buffer,
-				$data['style_to_embed_body'], $data['embed_pos'], 0 );
+			// replace.
+			$this->buffer = substr_replace(
+				$this->buffer,
+				$data['style_to_embed_body'],
+				$data['embed_pos'],
+				0
+			);
 		}
 
 		$this->files_to_minify = array();
diff --git a/Minify_AutoJs.php b/Minify_AutoJs.php
index f0316d997..ad70575a5 100644
--- a/Minify_AutoJs.php
+++ b/Minify_AutoJs.php
@@ -1,9 +1,20 @@
 <?php
+/**
+ * File: Minify_AutoJs.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Minify_AutoJs
+ */
 class Minify_AutoJs {
 	/**
 	 * Config
+	 *
+	 * @var Config
 	 */
 	private $config;
 
@@ -44,6 +55,8 @@ class Minify_AutoJs {
 
 	/**
 	 * Current list of script files to minify
+	 *
+	 * @var array
 	 */
 	private $files_to_minify;
 
@@ -54,45 +67,51 @@ class Minify_AutoJs {
 	 */
 	private $group_type = 'head';
 
+	/**
+	 * Debug flag
+	 *
+	 * @var bool
+	 */
 	private $debug = false;
 
 	/**
-	 * Constructor
+	 * Constructor for the Minify_AutoJs class.
+	 *
+	 * @param object $config          Configuration object containing settings.
+	 * @param string $buffer          HTML buffer to process.
+	 * @param object $minify_helpers  Helper class for minification operations.
 	 *
-	 * @param unknown $config
-	 * @param unknown $buffer
-	 * @param unknown $minify_helpers
+	 * @return void
 	 */
-	function __construct( $config, $buffer, $minify_helpers ) {
-		$this->config = $config;
-		$this->debug = $config->get_boolean( 'minify.debug' );
-		$this->buffer = $buffer;
+	public function __construct( $config, $buffer, $minify_helpers ) {
+		$this->config         = $config;
+		$this->debug          = $config->get_boolean( 'minify.debug' );
+		$this->buffer         = $buffer;
 		$this->minify_helpers = $minify_helpers;
 
-		// ignored files
+		// ignored files.
 		$this->ignore_js_files = $this->config->get_array( 'minify.reject.files.js' );
 		$this->ignore_js_files = array_map( array( '\W3TC\Util_Environment', 'normalize_file' ), $this->ignore_js_files );
 
-		// define embed type
+		// define embed type.
 		$this->embed_type = array(
 			'head' => $this->config->get_string( 'minify.js.header.embed_type' ),
-			'body' => $this->config->get_string( 'minify.js.body.embed_type' )
+			'body' => $this->config->get_string( 'minify.js.body.embed_type' ),
 		);
 	}
 
 	/**
-	 * Does auto-minification
+	 * Executes the minification process on the current buffer.
 	 *
-	 * @return string buffer of minified content
+	 * @return string The modified HTML buffer after processing.
 	 */
 	public function execute() {
-		// find all script tags
+		// find all script tags.
 		$buffer_nocomments = preg_replace( '~<!--.*?-->\s*~s', '', $this->buffer );
-		$matches = null;
+		$matches           = null;
 
-		// end of <head> means another group of scripts, cannt be combined
-		if ( !preg_match_all( '~(<script\s*[^>]*>.*?</script>|</head>)~is',
-				$buffer_nocomments, $matches ) ) {
+		// end of <head> means another group of scripts, cannt be combined.
+		if ( ! preg_match_all( '~(<script\s*[^>]*>.*?</script>|</head>)~is', $buffer_nocomments, $matches ) ) {
 			$matches = null;
 		}
 
@@ -101,27 +120,27 @@ public function execute() {
 		}
 
 		$script_tags = $matches[1];
-		$script_tags = apply_filters( 'w3tc_minify_js_script_tags',
-			$script_tags );
+		$script_tags = apply_filters( 'w3tc_minify_js_script_tags', $script_tags );
 
-		// pass scripts
+		// pass scripts.
 		$this->files_to_minify = array(
-			'sync' => array(
+			'sync'  => array(
 				'embed_pos' => 0,
-				'files' => array()
+				'files'     => array(),
 			),
 			'async' => array(
 				'embed_pos' => 0,
-				'files' => array()
+				'files'     => array(),
 			),
 			'defer' => array(
 				'embed_pos' => 0,
-				'files' => array()
-			)
+				'files'     => array(),
+			),
 		);
 
-		for ( $n = 0; $n < count( $script_tags ); $n++ ) {
-			$this->process_script_tag( $script_tags[$n], $n );
+		$count = count( $script_tags );
+		for ( $n = 0; $n < $count; $n++ ) {
+			$this->process_script_tag( $script_tags[ $n ], $n );
 		}
 
 		$this->flush_collected( 'sync', '' );
@@ -132,18 +151,20 @@ public function execute() {
 	}
 
 	/**
-	 * Returns list of minified scripts
+	 * Retrieves the list of debug URLs for the minified files.
 	 *
-	 * @return array
+	 * @return array List of URLs for debug purposes.
 	 */
 	public function get_debug_minified_urls() {
 		return $this->debug_minified_urls;
 	}
 
 	/**
-	 * Processes script tag
+	 * Processes a single script tag in the buffer.
+	 *
+	 * @param string $script_tag       The HTML script tag to process.
+	 * @param int    $script_tag_number The index of the script tag being processed.
 	 *
-	 * @param unknown $script_tag
 	 * @return void
 	 */
 	private function process_script_tag( $script_tag, $script_tag_number ) {
@@ -152,193 +173,213 @@ private function process_script_tag( $script_tag, $script_tag_number ) {
 		}
 
 		$tag_pos = strpos( $this->buffer, $script_tag );
-		if ( $tag_pos === false ) {
-			// script is external but not found, skip processing it
+		if ( false === $tag_pos ) {
+			// script is external but not found, skip processing it.
 			if ( $this->debug ) {
 				Minify_Core::log( 'script not found:' . $script_tag );
 			}
+
 			return;
 		}
 
 		$match = null;
-		if ( !preg_match( '~<script\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is',
-				$script_tag, $match ) ) {
+		if ( ! preg_match( '~<script\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is', $script_tag, $match ) ) {
 			$match = null;
 		}
+
 		if ( is_null( $match ) ) {
 			$data = array(
 				'script_tag_original' => $script_tag,
-				'script_tag_new' => $script_tag,
-				'script_tag_number' => $script_tag_number,
-				'script_tag_pos' => $tag_pos,
-				'should_replace' => false,
-				'buffer' => $this->buffer
+				'script_tag_new'      => $script_tag,
+				'script_tag_number'   => $script_tag_number,
+				'script_tag_pos'      => $tag_pos,
+				'should_replace'      => false,
+				'buffer'              => $this->buffer,
 			);
 
-			$data = apply_filters( 'w3tc_minify_js_do_local_script_minification',
-				$data );
+			$data         = apply_filters( 'w3tc_minify_js_do_local_script_minification', $data );
 			$this->buffer = $data['buffer'];
 
 			if ( $data['should_replace'] ) {
-				$this->buffer = substr_replace( $this->buffer,
-					$data['script_tag_new'], $tag_pos,
-					strlen( $script_tag ) );
+				$this->buffer = substr_replace(
+					$this->buffer,
+					$data['script_tag_new'],
+					$tag_pos,
+					strlen( $script_tag )
+				);
 			}
 
-			// it's not external script, have to flush what we have before it
+			// it's not external script, have to flush what we have before it.
 			if ( $this->debug ) {
 				Minify_Core::log( 'its not src=, flushing' );
 			}
 
 			$this->flush_collected( 'sync', $script_tag );
 
-			if ( preg_match( '~</head>~is', $script_tag, $match ) )
+			if ( preg_match( '~</head>~is', $script_tag, $match ) ) {
 				$this->group_type = 'body';
+			}
 
 			return;
 		}
 
 		$script_src = $match[1];
 		$script_src = Util_Environment::url_relative_to_full( $script_src );
-		$file = Util_Environment::url_to_docroot_filename( $script_src );
+		$file       = Util_Environment::url_to_docroot_filename( $script_src );
 
-		$step1_result = $this->minify_helpers->is_file_for_minification(
-			$script_src, $file );
-		if ( $step1_result == 'url' )
+		$step1_result = $this->minify_helpers->is_file_for_minification( $script_src, $file );
+		if ( 'url' === $step1_result ) {
 			$file = $script_src;
+		}
 
-		$step1 = !empty( $step1_result );
-		$step2 = !in_array( $file, $this->ignore_js_files );
+		$step1 = ! empty( $step1_result );
+		$step2 = ! in_array( $file, $this->ignore_js_files, true );
 
 		$do_tag_minification = $step1 && $step2;
-		$do_tag_minification = apply_filters( 'w3tc_minify_js_do_tag_minification',
-			$do_tag_minification, $script_tag, $file );
+		$do_tag_minification = apply_filters( 'w3tc_minify_js_do_tag_minification', $do_tag_minification, $script_tag, $file );
 
-		if ( !$do_tag_minification ) {
+		if ( ! $do_tag_minification ) {
 			if ( $this->debug ) {
-				Minify_Core::log( 'file ' . $file .
+				Minify_Core::log(
+					'file ' . $file .
 					' didnt pass minification check:' .
 					' file_for_min: ' . ( $step1 ? 'true' : 'false' ) .
-					' ignore_js_files: ' . ( $step2 ? 'true' : 'false' ) );
+					' ignore_js_files: ' . ( $step2 ? 'true' : 'false' )
+				);
 			}
 
 			$data = array(
 				'script_tag_original' => $script_tag,
-				'script_tag_new' => $script_tag,
-				'script_tag_number' => $script_tag_number,
-				'script_tag_pos' => $tag_pos,
-				'script_src' => $script_src,
-				'should_replace' => false,
-				'buffer' => $this->buffer
+				'script_tag_new'      => $script_tag,
+				'script_tag_number'   => $script_tag_number,
+				'script_tag_pos'      => $tag_pos,
+				'script_src'          => $script_src,
+				'should_replace'      => false,
+				'buffer'              => $this->buffer,
 			);
 
-			$data = apply_filters( 'w3tc_minify_js_do_excluded_tag_script_minification',
-				$data );
+			$data         = apply_filters( 'w3tc_minify_js_do_excluded_tag_script_minification', $data );
 			$this->buffer = $data['buffer'];
 
 			if ( $data['should_replace'] ) {
-				$this->buffer = substr_replace( $this->buffer,
-					$data['script_tag_new'], $tag_pos,
-					strlen( $script_tag ) );
+				$this->buffer = substr_replace(
+					$this->buffer,
+					$data['script_tag_new'],
+					$tag_pos,
+					strlen( $script_tag )
+				);
 			}
 
 			$this->flush_collected( 'sync', $script_tag );
+
 			return;
 		}
 
 		$this->debug_minified_urls[] = $file;
-		$this->buffer = substr_replace( $this->buffer, '',
-			$tag_pos, strlen( $script_tag ) );
+		$this->buffer                = substr_replace(
+			$this->buffer,
+			'',
+			$tag_pos,
+			strlen( $script_tag )
+		);
 
 		$m = null;
-		if ( !preg_match( '~\s+(async|defer)[> ]~is', $script_tag, $m ) ) {
+		if ( ! preg_match( '~\s+(async|defer)[> ]~is', $script_tag, $m ) ) {
 			$sync_type = 'sync';
 
 			// for head group - put minified file at the place of first script
 			// for body - put at the place of last script, to make as more DOM
-			// objects available as possible
-			if ( count( $this->files_to_minify[$sync_type]['files'] ) <= 0 ||
-					$this->group_type == 'body' ) {
-				$this->files_to_minify[$sync_type]['embed_pos'] = $tag_pos;
+			// objects available as possible.
+			if (
+				count( $this->files_to_minify[ $sync_type ]['files'] ) <= 0 ||
+				'body' === $this->group_type
+			) {
+				$this->files_to_minify[ $sync_type ]['embed_pos'] = $tag_pos;
 			}
 		} else {
-			$sync_type = strtolower( $m[1] );
-			$this->files_to_minify[$sync_type]['embed_pos'] = $tag_pos;
+			$sync_type                                        = strtolower( $m[1] );
+			$this->files_to_minify[ $sync_type ]['embed_pos'] = $tag_pos;
 		}
 
-		$this->files_to_minify[$sync_type]['files'][] = $file;
+		$this->files_to_minify[ $sync_type ]['files'][] = $file;
 
-		if ( $this->config->get_string( 'minify.js.method' ) == 'minify' )
+		if ( 'minify' === $this->config->get_string( 'minify.js.method' ) ) {
 			$this->flush_collected( $sync_type, '' );
+		}
 	}
 
 	/**
-	 * Minifies collected scripts
+	 * Flushes the collected scripts for a given synchronization type.
+	 *
+	 * @param string $sync_type        The synchronization type ('sync', 'async', 'defer').
+	 * @param string $last_script_tag  The last script tag in the group being processed.
+	 *
+	 * @return void
 	 */
 	private function flush_collected( $sync_type, $last_script_tag ) {
-		if ( count( $this->files_to_minify[$sync_type]['files'] ) <= 0 ) {
+		if ( count( $this->files_to_minify[ $sync_type ]['files'] ) <= 0 ) {
 			return;
 		}
-		$do_flush_collected = apply_filters( 'w3tc_minify_js_do_flush_collected',
-			true, $last_script_tag, $this, $sync_type );
-		if ( !$do_flush_collected ) {
+
+		$do_flush_collected = apply_filters( 'w3tc_minify_js_do_flush_collected', true, $last_script_tag, $this, $sync_type );
+		if ( ! $do_flush_collected ) {
 			return;
 		}
 
-		// build minified script tag
-		if ( $sync_type == 'sync' ) {
-			$embed_type = $this->embed_type[$this->group_type];
-		} elseif ( $sync_type == 'async' ) {
+		// build minified script tag.
+		if ( 'sync' === $sync_type ) {
+			$embed_type = $this->embed_type[ $this->group_type ];
+		} elseif ( 'async' === $sync_type ) {
 			$embed_type = 'nb-async';
-		} elseif ( $sync_type == 'defer' ) {
+		} elseif ( 'defer' === $sync_type ) {
 			$embed_type = 'nb-defer';
 		}
 
 		$data = array(
-			'files_to_minify' => $this->files_to_minify[$sync_type]['files'],
-			'embed_pos' => $this->files_to_minify[$sync_type]['embed_pos'],
-			'embed_type' => $embed_type,
-			'buffer' => $this->buffer
+			'files_to_minify' => $this->files_to_minify[ $sync_type ]['files'],
+			'embed_pos'       => $this->files_to_minify[ $sync_type ]['embed_pos'],
+			'embed_type'      => $embed_type,
+			'buffer'          => $this->buffer,
 		);
 
-		$data = apply_filters( 'w3tc_minify_js_step', $data );
+		$data         = apply_filters( 'w3tc_minify_js_step', $data );
 		$this->buffer = $data['buffer'];
 
-		if ( !empty( $data['files_to_minify'] ) ) {
-			$url = $this->minify_helpers->get_minify_url_for_files(
-				$data['files_to_minify'], 'js' );
+		if ( ! empty( $data['files_to_minify'] ) ) {
+			$url = $this->minify_helpers->get_minify_url_for_files( $data['files_to_minify'], 'js' );
 
 			$script = '';
-			if ( !is_null( $url ) ) {
-				$script .= $this->minify_helpers->generate_script_tag( $url,
-					$data['embed_type'] );
+			if ( ! is_null( $url ) ) {
+				$script .= $this->minify_helpers->generate_script_tag( $url, $data['embed_type'] );
 			}
 
-			$data['script_to_embed_url'] = $url;
+			$data['script_to_embed_url']  = $url;
 			$data['script_to_embed_body'] = $script;
-			$data = apply_filters( 'w3tc_minify_js_step_script_to_embed',
-				$data );
-			$this->buffer = $data['buffer'];
+			$data                         = apply_filters( 'w3tc_minify_js_step_script_to_embed', $data );
+			$this->buffer                 = $data['buffer'];
 
 			if ( $this->config->getf_boolean( 'minify.js.http2push' ) ) {
-				$this->minify_helpers->http2_header_add(
-					$data['script_to_embed_url'], 'script' );
+				$this->minify_helpers->http2_header_add( $data['script_to_embed_url'], 'script' );
 			}
 
-			// replace
-			$this->buffer = substr_replace( $this->buffer,
-				$data['script_to_embed_body'], $data['embed_pos'], 0 );
+			// replace.
+			$this->buffer = substr_replace(
+				$this->buffer,
+				$data['script_to_embed_body'],
+				$data['embed_pos'],
+				0
+			);
 
 			foreach ( $this->files_to_minify as $key => $i ) {
-				if ( $key != $sync_type && $i['embed_pos'] >= $data['embed_pos'] ) {
-					$this->files_to_minify[$key]['embed_pos'] += strlen( $data['script_to_embed_body'] );
+				if ( $key !== $sync_type && $i['embed_pos'] >= $data['embed_pos'] ) {
+					$this->files_to_minify[ $key ]['embed_pos'] += strlen( $data['script_to_embed_body'] );
 				}
 			}
 		}
 
-		$this->files_to_minify[$sync_type] = array(
+		$this->files_to_minify[ $sync_type ] = array(
 			'embed_pos' => 0,
-			'files' => array()
+			'files'     => array(),
 		);
 	}
 }
diff --git a/Minify_ConfigLabels.php b/Minify_ConfigLabels.php
index 39136f88f..89f495f83 100644
--- a/Minify_ConfigLabels.php
+++ b/Minify_ConfigLabels.php
@@ -1,86 +1,108 @@
 <?php
+/**
+ * File: Minify_ConfigLabels.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Minify_ConfigLabels
+ *
+ * phpcs:disable WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
+ * phpcs:disable WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
+ */
 class Minify_ConfigLabels {
+	/**
+	 * Merges additional configuration labels for the Minify module.
+	 *
+	 * @param array $config_labels Existing configuration labels.
+	 *
+	 * @return array Merged configuration labels including Minify-specific options.
+	 */
 	public function config_labels( $config_labels ) {
-		return array_merge( $config_labels, array(
-				'minify.engine' => __( 'Minify Cache Method:', 'w3-total-cache' ),
-				'minify.enabled' => __( 'Minify:', 'w3-total-cache' ),
-				'minify.debug' =>  __( 'Minify', 'w3-total-cache' ),
-				'minify.html.engine' => __( '<acronym title="Hypertext Markup Language">HTML</acronym> minifier:', 'w3-total-cache' ),
-				'minify.js.engine' =>  __( '<acronym title="JavaScript">JS</acronym> minifier:', 'w3-total-cache' ),
-				'minify.css.engine'=>  __( '<acronym title="Cascading Style Sheets">CSS</acronym> minifier:', 'w3-total-cache' ),
-				'minify.auto' => __( 'Minify mode:', 'w3-total-cache' ),
-				'minify.rewrite' => __( 'Rewrite <acronym title="Uniform Resource Locator">URL</acronym> structure', 'w3-total-cache' ),
-				'minify.reject.logged' => __( 'Disable minify for logged in users', 'w3-total-cache' ),
-				'minify.error.notification' => __( 'Minify error notification:', 'w3-total-cache' ),
-				'minify.html.enable' => __( 'Enable', 'w3-total-cache' ),
-				'minify.html.inline.css' => __( 'Inline <acronym title="Cascading Style Sheet">CSS</acronym> minification', 'w3-total-cache' ),
-				'minify.html.inline.js' => __( 'Inline <acronym title="JavaScript">JS</acronym> minification', 'w3-total-cache' ),
-				'minify.html.reject.feed' => __( 'Don\'t minify feeds', 'w3-total-cache' ),
-				'minify.html.comments.ignore' => __( 'Ignored comment stems:', 'w3-total-cache' ),
-				'minify.js.enable' => __( 'Enable', 'w3-total-cache' ),
-				'minify.js.header.embed_type' => __( 'Embed type:', 'w3-total-cache' ),
-				'minify.js.combine.header' =>  __( 'Combine only', 'w3-total-cache' ),
-				'minify.js.body.embed_type' => __( 'After <span class="html-tag">&lt;body&gt;</span>', 'w3-total-cache' ),
-				'minify.js.combine.body' => __( 'Combine only', 'w3-total-cache' ),
-				'minify.js.footer.embed_type' => __( 'Before <span class="html-tag">&lt;/body&gt;</span>', 'w3-total-cache' ),
-				'minify.js.combine.footer' => __( 'Combine only', 'w3-total-cache' ),
-				'minify.css.enable' => __( 'Enable', 'w3-total-cache' ),
-				'minify.css.imports' => __( '@import handling:', 'w3-total-cache' ),
-				'minify.lifetime' => __( 'Update external files every:', 'w3-total-cache' ),
-				'minify.file.gc' => __( 'Garbage collection interval:', 'w3-total-cache' ),
-				'minify.reject.uri' => __( 'Never minify the following pages:', 'w3-total-cache' ),
-				'minify.reject.files.js' => __( 'Never minify the following <acronym title="JavaScript">JS</acronym> files:', 'w3-total-cache' ),
-				'minify.reject.files.css' => __( 'Never minify the following <acronym title="Cascading Style Sheet">CSS</acronym> files:', 'w3-total-cache' ),
-				'minify.reject.ua' => __( 'Rejected user agents:', 'w3-total-cache' ),
-				'minify.cache.files' => __( 'Include external files/libraries:', 'w3-total-cache' ),
-				// options->minify->ccjs
-				'minify.ccjs.options.formatting' => __( 'Pretty print', 'w3-total-cache' ),
-				// options->minify->ccjs2
-				'minify.ccjs.path.java' => __( 'Path to JAVA executable:', 'w3-total-cache' ),
-				'minify.ccjs.path.jar' => __( 'Path to JAR file:', 'w3-total-cache' ),
-				'minify.ccjs.options.compilation_level' => __( 'Compilation level:', 'w3-total-cache' ),
-				// options->minify->css
-				'minify.css.strip.comments' => __( 'Preserved comment removal (not applied when combine only is active)', 'w3-total-cache' ),
-				'minify.css.strip.crlf' => __( 'Line break removal (not applied when combine only is active)', 'w3-total-cache' ),
-				// options->minify->csstidy
-				'minify.csstidy.options.remove_bslash' => __( 'Remove unnecessary backslashes', 'w3-total-cache' ),
-				'minify.csstidy.options.compress_colors' => __( 'Compress colors', 'w3-total-cache' ),
-				'minify.csstidy.options.compress_font-weight' => __( 'Compress font-weight', 'w3-total-cache' ),
-				'minify.csstidy.options.lowercase_s' => __( 'Lowercase selectors', 'w3-total-cache' ),
-				'minify.csstidy.options.remove_last_;' => __( 'Remove last ;', 'w3-total-cache' ),
+		return array_merge(
+			$config_labels,
+			array(
+				'minify.engine'                                        => __( 'Minify Cache Method:', 'w3-total-cache' ),
+				'minify.enabled'                                       => __( 'Minify:', 'w3-total-cache' ),
+				'minify.debug'                                         => __( 'Minify', 'w3-total-cache' ),
+				'minify.html.engine'                                   => __( '<acronym title="Hypertext Markup Language">HTML</acronym> minifier:', 'w3-total-cache' ),
+				'minify.js.engine'                                     => __( '<acronym title="JavaScript">JS</acronym> minifier:', 'w3-total-cache' ),
+				'minify.css.engine'                                    => __( '<acronym title="Cascading Style Sheets">CSS</acronym> minifier:', 'w3-total-cache' ),
+				'minify.auto'                                          => __( 'Minify mode:', 'w3-total-cache' ),
+				'minify.rewrite'                                       => __( 'Rewrite <acronym title="Uniform Resource Locator">URL</acronym> structure', 'w3-total-cache' ),
+				'minify.reject.logged'                                 => __( 'Disable minify for logged in users', 'w3-total-cache' ),
+				'minify.error.notification'                            => __( 'Minify error notification:', 'w3-total-cache' ),
+				'minify.html.enable'                                   => __( 'Enable', 'w3-total-cache' ),
+				'minify.html.inline.css'                               => __( 'Inline <acronym title="Cascading Style Sheet">CSS</acronym> minification', 'w3-total-cache' ),
+				'minify.html.inline.js'                                => __( 'Inline <acronym title="JavaScript">JS</acronym> minification', 'w3-total-cache' ),
+				'minify.html.reject.feed'                              => __( 'Don\'t minify feeds', 'w3-total-cache' ),
+				'minify.html.comments.ignore'                          => __( 'Ignored comment stems:', 'w3-total-cache' ),
+				'minify.js.enable'                                     => __( 'Enable', 'w3-total-cache' ),
+				'minify.js.header.embed_type'                          => __( 'Embed type:', 'w3-total-cache' ),
+				'minify.js.combine.header'                             => __( 'Combine only', 'w3-total-cache' ),
+				'minify.js.body.embed_type'                            => __( 'After <span class="html-tag">&lt;body&gt;</span>', 'w3-total-cache' ),
+				'minify.js.combine.body'                               => __( 'Combine only', 'w3-total-cache' ),
+				'minify.js.footer.embed_type'                          => __( 'Before <span class="html-tag">&lt;/body&gt;</span>', 'w3-total-cache' ),
+				'minify.js.combine.footer'                             => __( 'Combine only', 'w3-total-cache' ),
+				'minify.css.enable'                                    => __( 'Enable', 'w3-total-cache' ),
+				'minify.css.imports'                                   => __( '@import handling:', 'w3-total-cache' ),
+				'minify.lifetime'                                      => __( 'Update external files every:', 'w3-total-cache' ),
+				'minify.file.gc'                                       => __( 'Garbage collection interval:', 'w3-total-cache' ),
+				'minify.reject.uri'                                    => __( 'Never minify the following pages:', 'w3-total-cache' ),
+				'minify.reject.files.js'                               => __( 'Never minify the following <acronym title="JavaScript">JS</acronym> files:', 'w3-total-cache' ),
+				'minify.reject.files.css'                              => __( 'Never minify the following <acronym title="Cascading Style Sheet">CSS</acronym> files:', 'w3-total-cache' ),
+				'minify.reject.ua'                                     => __( 'Rejected user agents:', 'w3-total-cache' ),
+				'minify.cache.files'                                   => __( 'Include external files/libraries:', 'w3-total-cache' ),
+				// options->minify->ccjs.
+				'minify.ccjs.options.formatting'                       => __( 'Pretty print', 'w3-total-cache' ),
+				// options->minify->ccjs2.
+				'minify.ccjs.path.java'                                => __( 'Path to JAVA executable:', 'w3-total-cache' ),
+				'minify.ccjs.path.jar'                                 => __( 'Path to JAR file:', 'w3-total-cache' ),
+				'minify.ccjs.options.compilation_level'                => __( 'Compilation level:', 'w3-total-cache' ),
+				// options->minify->css.
+				'minify.css.strip.comments'                            => __( 'Preserved comment removal (not applied when combine only is active)', 'w3-total-cache' ),
+				'minify.css.strip.crlf'                                => __( 'Line break removal (not applied when combine only is active)', 'w3-total-cache' ),
+				// options->minify->csstidy.
+				'minify.csstidy.options.remove_bslash'                 => __( 'Remove unnecessary backslashes', 'w3-total-cache' ),
+				'minify.csstidy.options.compress_colors'               => __( 'Compress colors', 'w3-total-cache' ),
+				'minify.csstidy.options.compress_font-weight'          => __( 'Compress font-weight', 'w3-total-cache' ),
+				'minify.csstidy.options.lowercase_s'                   => __( 'Lowercase selectors', 'w3-total-cache' ),
+				'minify.csstidy.options.remove_last_;'                 => __( 'Remove last ;', 'w3-total-cache' ),
 				'minify.csstidy.options.remove_space_before_important' => __( 'Remove space before !important', 'w3-total-cache' ),
-				'minify.csstidy.options.sort_properties' => __( 'Sort Properties', 'w3-total-cache' ),
-				'minify.csstidy.options.sort_selectors' => __( 'Sort Selectors (caution)', 'w3-total-cache' ),
-				'minify.csstidy.options.discard_invalid_selectors' => __( 'Discard invalid selectors', 'w3-total-cache' ),
-				'minify.csstidy.options.discard_invalid_properties' => __( 'Discard invalid properties', 'w3-total-cache' ),
-				'minify.csstidy.options.preserve_css' => __( 'Preserve CSS', 'w3-total-cache' ),
-				'minify.csstidy.options.timestamp' => __( 'Add timestamp', 'w3-total-cache' ),
-				// options->minify->csstidy2
-				'minify.csstidy.options.template' => __( 'Compression:', 'w3-total-cache' ),
-				'minify.csstidy.options.optimise_shorthands' => __( 'Optimize shorthands:', 'w3-total-cache' ),
-				'minify.csstidy.options.case_properties' => __( 'Case for properties:', 'w3-total-cache' ),
-				'minify.csstidy.options.merge_selectors' => __( 'Regroup selectors:', 'w3-total-cache' ),
-				// options->minify->html
-				'minify.html.strip.crlf' => __( 'Line break removal', 'w3-total-cache' ),
-				// options->minify_>htmltidy
-				'minify.htmltidy.options.clean' => __( 'Clean', 'w3-total-cache' ),
-				'minify.htmltidy.options.hide-comments' => __( 'Hide comments', 'w3-total-cache' ),
-				// options->minify->htmltidy2
-				'minify.htmltidy.options.wrap' => __( 'Wrap after:', 'w3-total-cache' ),
-				// options->minify->js
-				'minify.js.strip.comments' => __( 'Preserved comment removal (not applied when combine only is active)', 'w3-total-cache' ),
-				'minify.js.strip.crlf' => __( 'Line break removal (not safe, not applied when combine only is active)', 'w3-total-cache' ),
-				// options->minify->yuicss2
-				'minify.yuicss.path.java' => __( 'Path to JAVA executable:', 'w3-total-cache' ),
-				'minify.yuicss.path.jar' => __( 'Path to JAR file:', 'w3-total-cache' ),
-				'minify.yuicss.options.line-break' => __( 'Line break after:', 'w3-total-cache' ),
-				// options->minify->yuijs
-				'minify.yuijs.options.nomunge' => __( 'Minify only, do not obfuscate local symbols', 'w3-total-cache' ),
-				'minify.yuijs.options.preserve-semi' => __( 'Preserve unnecessary semicolons', 'w3-total-cache' ),
-				'minify.yuijs.options.disable-optimizations' => __( 'Disable all the built-in micro optimizations', 'w3-total-cache' ),
-				'minify.yuijs.options.line-break' => __( 'Line break after:', 'w3-total-cache' )
-			) );
+				'minify.csstidy.options.sort_properties'               => __( 'Sort Properties', 'w3-total-cache' ),
+				'minify.csstidy.options.sort_selectors'                => __( 'Sort Selectors (caution)', 'w3-total-cache' ),
+				'minify.csstidy.options.discard_invalid_selectors'     => __( 'Discard invalid selectors', 'w3-total-cache' ),
+				'minify.csstidy.options.discard_invalid_properties'    => __( 'Discard invalid properties', 'w3-total-cache' ),
+				'minify.csstidy.options.preserve_css'                  => __( 'Preserve CSS', 'w3-total-cache' ),
+				'minify.csstidy.options.timestamp'                     => __( 'Add timestamp', 'w3-total-cache' ),
+				// options->minify->csstidy2.
+				'minify.csstidy.options.template'                      => __( 'Compression:', 'w3-total-cache' ),
+				'minify.csstidy.options.optimise_shorthands'           => __( 'Optimize shorthands:', 'w3-total-cache' ),
+				'minify.csstidy.options.case_properties'               => __( 'Case for properties:', 'w3-total-cache' ),
+				'minify.csstidy.options.merge_selectors'               => __( 'Regroup selectors:', 'w3-total-cache' ),
+				// options->minify->html.
+				'minify.html.strip.crlf'                               => __( 'Line break removal', 'w3-total-cache' ),
+				// options->minify_>htmltidy.
+				'minify.htmltidy.options.clean'                        => __( 'Clean', 'w3-total-cache' ),
+				'minify.htmltidy.options.hide-comments'                => __( 'Hide comments', 'w3-total-cache' ),
+				// options->minify->htmltidy2.
+				'minify.htmltidy.options.wrap'                         => __( 'Wrap after:', 'w3-total-cache' ),
+				// options->minify->js.
+				'minify.js.strip.comments'                             => __( 'Preserved comment removal (not applied when combine only is active)', 'w3-total-cache' ),
+				'minify.js.strip.crlf'                                 => __( 'Line break removal (not safe, not applied when combine only is active)', 'w3-total-cache' ),
+				// options->minify->yuicss2.
+				'minify.yuicss.path.java'                              => __( 'Path to JAVA executable:', 'w3-total-cache' ),
+				'minify.yuicss.path.jar'                               => __( 'Path to JAR file:', 'w3-total-cache' ),
+				'minify.yuicss.options.line-break'                     => __( 'Line break after:', 'w3-total-cache' ),
+				// options->minify->yuijs.
+				'minify.yuijs.options.nomunge'                         => __( 'Minify only, do not obfuscate local symbols', 'w3-total-cache' ),
+				'minify.yuijs.options.preserve-semi'                   => __( 'Preserve unnecessary semicolons', 'w3-total-cache' ),
+				'minify.yuijs.options.disable-optimizations'           => __( 'Disable all the built-in micro optimizations', 'w3-total-cache' ),
+				'minify.yuijs.options.line-break'                      => __( 'Line break after:', 'w3-total-cache' ),
+			)
+		);
 	}
 }
diff --git a/Minify_ContentMinifier.php b/Minify_ContentMinifier.php
index 89c4c18ee..ea1fdb116 100644
--- a/Minify_ContentMinifier.php
+++ b/Minify_ContentMinifier.php
@@ -1,259 +1,283 @@
 <?php
-namespace W3TC;
-
 /**
- * Minifiers object
+ * File: Minify_ConfigLabels.php
+ *
+ * @package W3TC
  */
 
+namespace W3TC;
+
 /**
- * class Minifier
+ * Class Minify_ContentMinifier
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
  */
 class Minify_ContentMinifier {
 	/**
-	 * Config instance
+	 * Config
+	 *
+	 * @var Config
 	 */
-	var $_config = null;
+	public $_config = null;
 
 	/**
 	 * Minifiers array
 	 *
 	 * @var array
 	 */
-	var $_minifiers = array(
-		'combinejs' => array( '\W3TCL\Minify\Minify_CombineOnly', 'minify' ),
-		'combinecss' => array( '\W3TCL\Minify\Minify_CombineOnly', 'minify' ),
-
-		'js' => array( '\W3TCL\Minify\JSMin', 'minify' ),
-		'yuijs' => array( '\W3TCL\Minify\Minify_YUICompressor', 'minifyJs' ),
-		'ccjs' => array( '\W3TCL\Minify\Minify_ClosureCompiler', 'minify' ),
-		'jsminplus' => array( '\W3TCL\Minify\JSMinPlus', 'minify' ),
-		'googleccjs' => array( '\W3TCL\Minify\Minify_JS_ClosureCompiler', 'minify' ),
-
-		'css' => array( '\W3TCL\Minify\Minify_CSS', 'minify' ),
-		'yuicss' => array( '\W3TCL\Minify\Minify_YUICompressor', 'minifyCss' ),
-		'cssmin' => array( '\W3TCL\YuiCssMin\Minifier', 'minify_static' ),
-		'csstidy' => array( '\W3TCL\Minify\Minify_CSSTidy', 'minify' ),
-
-		'html' => array( '\W3TCL\Minify\Minify_HTML', 'minify' ),
-		'htmlxml' => array( '\W3TCL\Minify\Minify_HTML', 'minify' ),
-
-		'htmltidy' => array( '\W3TCL\Minify\Minify_HTMLTidy', 'minifyXhtml' ),
-		'htmltidyxml' => array( '\W3TCL\Minify\Minify_HTMLTidy', 'minifyXml' )
+	public $_minifiers = array(
+		'combinejs'   => array( '\W3TCL\Minify\Minify_CombineOnly', 'minify' ),
+		'combinecss'  => array( '\W3TCL\Minify\Minify_CombineOnly', 'minify' ),
+		'js'          => array( '\W3TCL\Minify\JSMin', 'minify' ),
+		'yuijs'       => array( '\W3TCL\Minify\Minify_YUICompressor', 'minifyJs' ),
+		'ccjs'        => array( '\W3TCL\Minify\Minify_ClosureCompiler', 'minify' ),
+		'jsminplus'   => array( '\W3TCL\Minify\JSMinPlus', 'minify' ),
+		'googleccjs'  => array( '\W3TCL\Minify\Minify_JS_ClosureCompiler', 'minify' ),
+		'css'         => array( '\W3TCL\Minify\Minify_CSS', 'minify' ),
+		'yuicss'      => array( '\W3TCL\Minify\Minify_YUICompressor', 'minifyCss' ),
+		'cssmin'      => array( '\W3TCL\YuiCssMin\Minifier', 'minify_static' ),
+		'csstidy'     => array( '\W3TCL\Minify\Minify_CSSTidy', 'minify' ),
+		'html'        => array( '\W3TCL\Minify\Minify_HTML', 'minify' ),
+		'htmlxml'     => array( '\W3TCL\Minify\Minify_HTML', 'minify' ),
+		'htmltidy'    => array( '\W3TCL\Minify\Minify_HTMLTidy', 'minifyXhtml' ),
+		'htmltidyxml' => array( '\W3TCL\Minify\Minify_HTMLTidy', 'minifyXml' ),
 	);
 
 	/**
-	 * PHP5-style constructor
+	 * Constructor for initializing the Minify Content Minifier class.
+	 *
+	 * @return void
 	 */
-	function __construct() {
+	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
+
 	/**
-	 * Returns true if minifier exists
+	 * Checks if a minifier engine is available.
 	 *
-	 * @param string  $engine
-	 * @return boolean
+	 * @param string $engine The minifier engine to check.
+	 *
+	 * @return bool True if the engine exists, false otherwise.
 	 */
-	function exists( $engine ) {
-		return isset( $this->_minifiers[$engine] );
+	public function exists( $engine ) {
+		return isset( $this->_minifiers[ $engine ] );
 	}
 
 	/**
-	 * Returns true if minifier available
+	 * Checks if the given minifier engine is available with the required files.
+	 *
+	 * @param string $engine The minifier engine to check.
 	 *
-	 * @param string  $engine
-	 * @return boolean
+	 * @return bool True if the engine is available, false otherwise.
 	 */
-	function available( $engine ) {
+	public function available( $engine ) {
 		switch ( $engine ) {
-		case 'yuijs':
-			$path_java = $this->_config->get_string( 'minify.yuijs.path.java' );
-			$path_jar = $this->_config->get_string( 'minify.yuijs.path.jar' );
+			case 'yuijs':
+				$path_java = $this->_config->get_string( 'minify.yuijs.path.java' );
+				$path_jar  = $this->_config->get_string( 'minify.yuijs.path.jar' );
 
-			return file_exists( $path_java ) && file_exists( $path_jar );
+				return file_exists( $path_java ) && file_exists( $path_jar );
 
-		case 'yuicss':
-			$path_java = $this->_config->get_string( 'minify.yuicss.path.java' );
-			$path_jar = $this->_config->get_string( 'minify.yuicss.path.jar' );
+			case 'yuicss':
+				$path_java = $this->_config->get_string( 'minify.yuicss.path.java' );
+				$path_jar  = $this->_config->get_string( 'minify.yuicss.path.jar' );
 
-			return file_exists( $path_java ) && file_exists( $path_jar );
+				return file_exists( $path_java ) && file_exists( $path_jar );
 
-		case 'ccjs':
-			$path_java = $this->_config->get_string( 'minify.ccjs.path.java' );
-			$path_jar = $this->_config->get_string( 'minify.ccjs.path.jar' );
+			case 'ccjs':
+				$path_java = $this->_config->get_string( 'minify.ccjs.path.java' );
+				$path_jar  = $this->_config->get_string( 'minify.ccjs.path.jar' );
 
-			return file_exists( $path_java ) && file_exists( $path_jar );
+				return file_exists( $path_java ) && file_exists( $path_jar );
 
-		case 'htmltidy':
-		case 'htmltidyxml':
-			return class_exists( 'tidy' );
+			case 'htmltidy':
+			case 'htmltidyxml':
+				return class_exists( 'tidy' );
 		}
 
 		return $this->exists( $engine );
 	}
 
 	/**
-	 * Returns minifier
+	 * Retrieves the specified minifier engine.
 	 *
-	 * @param string  $engine
-	 * @return array
+	 * @param string $engine The minifier engine to retrieve.
+	 *
+	 * @return mixed|null The minifier engine or null if not found.
 	 */
-	function get_minifier( $engine ) {
-		if ( isset( $this->_minifiers[$engine] ) ) {
-			return $this->_minifiers[$engine];
+	public function get_minifier( $engine ) {
+		if ( isset( $this->_minifiers[ $engine ] ) ) {
+			return $this->_minifiers[ $engine ];
 		}
 
 		return null;
 	}
 
 	/**
-	 * Initializes minifier
+	 * Initializes the given minifier engine.
+	 *
+	 * @param string $engine The minifier engine to initialize.
 	 *
-	 * @param string  $engine
 	 * @return void
 	 */
-	function init( $engine ) {
+	public function init( $engine ) {
 		switch ( $engine ) {
-		case 'yuijs':
-			\W3TCL\Minify\Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
-			\W3TCL\Minify\Minify_YUICompressor::$javaExecutable = $this->_config->get_string( 'minify.yuijs.path.java' );
-			\W3TCL\Minify\Minify_YUICompressor::$jarFile = $this->_config->get_string( 'minify.yuijs.path.jar' );
-			break;
-
-		case 'yuicss':
-			\W3TCL\Minify\Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
-			\W3TCL\Minify\Minify_YUICompressor::$javaExecutable = $this->_config->get_string( 'minify.yuicss.path.java' );
-			\W3TCL\Minify\Minify_YUICompressor::$jarFile = $this->_config->get_string( 'minify.yuicss.path.jar' );
-			break;
-
-		case 'ccjs':
-			\W3TCL\Minify\Minify_ClosureCompiler::$tempDir = Util_File::create_tmp_dir();
-			\W3TCL\Minify\Minify_ClosureCompiler::$javaExecutable = $this->_config->get_string( 'minify.ccjs.path.java' );
-			\W3TCL\Minify\Minify_ClosureCompiler::$jarFile = $this->_config->get_string( 'minify.ccjs.path.jar' );
-			break;
+			case 'yuijs':
+				\W3TCL\Minify\Minify_YUICompressor::$tempDir        = Util_File::create_tmp_dir();
+				\W3TCL\Minify\Minify_YUICompressor::$javaExecutable = $this->_config->get_string( 'minify.yuijs.path.java' );
+				\W3TCL\Minify\Minify_YUICompressor::$jarFile        = $this->_config->get_string( 'minify.yuijs.path.jar' );
+				break;
+
+			case 'yuicss':
+				\W3TCL\Minify\Minify_YUICompressor::$tempDir        = Util_File::create_tmp_dir();
+				\W3TCL\Minify\Minify_YUICompressor::$javaExecutable = $this->_config->get_string( 'minify.yuicss.path.java' );
+				\W3TCL\Minify\Minify_YUICompressor::$jarFile        = $this->_config->get_string( 'minify.yuicss.path.jar' );
+				break;
+
+			case 'ccjs':
+				\W3TCL\Minify\Minify_ClosureCompiler::$tempDir        = Util_File::create_tmp_dir();
+				\W3TCL\Minify\Minify_ClosureCompiler::$javaExecutable = $this->_config->get_string( 'minify.ccjs.path.java' );
+				\W3TCL\Minify\Minify_ClosureCompiler::$jarFile        = $this->_config->get_string( 'minify.ccjs.path.jar' );
+				break;
 		}
 	}
 
 	/**
-	 * Returns minifier options
+	 * Retrieves the options for a specific minifier engine.
 	 *
-	 * @param string  $engine
-	 * @return array
+	 * @param string $engine The minifier engine to retrieve options for.
+	 *
+	 * @return array The options for the given engine.
 	 */
-	function get_options( $engine ) {
+	public function get_options( $engine ) {
 		$options = array();
 
 		switch ( $engine ) {
-		case 'js':
-			$options = array(
-				'preserveComments' => !$this->_config->get_boolean( 'minify.js.strip.comments' ),
-				'stripCrlf' => $this->_config->get_boolean( 'minify.js.strip.crlf' )
-			);
-			break;
-
-		case 'css':
-			$options = array(
-				'preserveComments' => !$this->_config->get_boolean( 'minify.css.strip.comments' ),
-				'stripCrlf' => $this->_config->get_boolean( 'minify.css.strip.crlf' )
-			);
-
-			$symlinks = $this->_config->get_array( 'minify.symlinks' );
-			$docroot  = Util_Environment::document_root();
-
-			foreach ( $symlinks as $link => $target ) {
-				$link = str_replace( '//', realpath( $docroot ), $link );
-				$link = strtr( $link, '/', DIRECTORY_SEPARATOR );
-				$options['symlinks'][$link] = realpath( $target );
-			}
-			break;
-
-		case 'yuijs':
-			$options = array(
-				'line-break' => $this->_config->get_integer( 'minify.yuijs.options.line-break' ),
-				'nomunge' => $this->_config->get_boolean( 'minify.yuijs.options.nomunge' ),
-				'preserve-semi' => $this->_config->get_boolean( 'minify.yuijs.options.preserve-semi' ),
-				'disable-optimizations' => $this->_config->get_boolean( 'minify.yuijs.options.disable-optimizations' )
-			);
-			break;
-
-		case 'yuicss':
-			$options = array(
-				'line-break' => $this->_config->get_integer( 'minify.yuicss.options.line-break' )
-			);
-			break;
-
-		case 'ccjs':
-			$options = array(
-				'compilation_level' => $this->_config->get_string( 'minify.ccjs.options.compilation_level' ),
-				'formatting' => $this->_config->get_string( 'minify.ccjs.options.formatting' )
-			);
-			break;
-
-		case 'googleccjs':
-			$options = array(
-				'compilation_level' => $this->_config->get_string( 'minify.ccjs.options.compilation_level' ),
-				'formatting' => $this->_config->get_string( 'minify.ccjs.options.formatting' )
-			);
-			break;
-
-		case 'csstidy':
-			$options = array(
-				'remove_bslash' => $this->_config->get_boolean( 'minify.csstidy.options.remove_bslash' ),
-				'compress_colors' => $this->_config->get_boolean( 'minify.csstidy.options.compress_colors' ),
-				'compress_font-weight' => $this->_config->get_boolean( 'minify.csstidy.options.compress_font-weight' ),
-				'lowercase_s' => $this->_config->get_boolean( 'minify.csstidy.options.lowercase_s' ),
-				'optimise_shorthands' => $this->_config->get_integer( 'minify.csstidy.options.optimise_shorthands' ),
-				'remove_last_;' => $this->_config->get_boolean( 'minify.csstidy.options.remove_last_;' ),
-				'space_before_important' => !$this->_config->get_boolean( 'minify.csstidy.options.remove_space_before_important' ),
-				'case_properties' => $this->_config->get_integer( 'minify.csstidy.options.case_properties' ),
-				'sort_properties' => $this->_config->get_boolean( 'minify.csstidy.options.sort_properties' ),
-				'sort_selectors' => $this->_config->get_boolean( 'minify.csstidy.options.sort_selectors' ),
-				'merge_selectors' => $this->_config->get_integer( 'minify.csstidy.options.merge_selectors' ),
-				'discard_invalid_selectors' => $this->_config->get_boolean( 'minify.csstidy.options.discard_invalid_selectors' ),
-				'discard_invalid_properties' => $this->_config->get_boolean( 'minify.csstidy.options.discard_invalid_properties' ),
-				'css_level' => $this->_config->get_string( 'minify.csstidy.options.css_level' ),
-				'preserve_css' => $this->_config->get_boolean( 'minify.csstidy.options.preserve_css' ),
-				'timestamp' => $this->_config->get_boolean( 'minify.csstidy.options.timestamp' ),
-				'template' => $this->_config->get_string( 'minify.csstidy.options.template' )
-			);
-			break;
-
-		case 'html':
-		case 'htmlxml':
-			$options = array(
-				'xhtml' => true,
-				'stripCrlf' => $this->_config->get_boolean( 'minify.html.strip.crlf' ),
-				'ignoredComments' => $this->_config->get_array( 'minify.html.comments.ignore' )
-			);
-			break;
-
-		case 'htmltidy':
-		case 'htmltidyxml':
-			$options = array(
-				'clean' => $this->_config->get_boolean( 'minify.htmltidy.options.clean' ),
-				'hide-comments' => $this->_config->get_boolean( 'minify.htmltidy.options.hide-comments' ),
-				'wrap' => $this->_config->get_integer( 'minify.htmltidy.options.wrap' )
-			);
-			break;
+			case 'js':
+				$options = array(
+					'preserveComments' => ! $this->_config->get_boolean( 'minify.js.strip.comments' ),
+					'stripCrlf'        => $this->_config->get_boolean( 'minify.js.strip.crlf' ),
+				);
+				break;
+
+			case 'css':
+				$options = array(
+					'preserveComments' => ! $this->_config->get_boolean( 'minify.css.strip.comments' ),
+					'stripCrlf'        => $this->_config->get_boolean( 'minify.css.strip.crlf' ),
+				);
+
+				$symlinks = $this->_config->get_array( 'minify.symlinks' );
+				$docroot  = Util_Environment::document_root();
+
+				foreach ( $symlinks as $link => $target ) {
+					$link                         = str_replace( '//', realpath( $docroot ), $link );
+					$link                         = strtr( $link, '/', DIRECTORY_SEPARATOR );
+					$options['symlinks'][ $link ] = realpath( $target );
+				}
+				break;
+
+			case 'yuijs':
+				$options = array(
+					'line-break'            => $this->_config->get_integer( 'minify.yuijs.options.line-break' ),
+					'nomunge'               => $this->_config->get_boolean( 'minify.yuijs.options.nomunge' ),
+					'preserve-semi'         => $this->_config->get_boolean( 'minify.yuijs.options.preserve-semi' ),
+					'disable-optimizations' => $this->_config->get_boolean( 'minify.yuijs.options.disable-optimizations' ),
+				);
+				break;
+
+			case 'yuicss':
+				$options = array(
+					'line-break' => $this->_config->get_integer( 'minify.yuicss.options.line-break' ),
+				);
+				break;
+
+			case 'ccjs':
+				$options = array(
+					'compilation_level' => $this->_config->get_string( 'minify.ccjs.options.compilation_level' ),
+					'formatting'        => $this->_config->get_string( 'minify.ccjs.options.formatting' ),
+				);
+				break;
+
+			case 'googleccjs':
+				$options = array(
+					'compilation_level' => $this->_config->get_string( 'minify.ccjs.options.compilation_level' ),
+					'formatting'        => $this->_config->get_string( 'minify.ccjs.options.formatting' ),
+				);
+				break;
+
+			case 'csstidy':
+				$options = array(
+					'remove_bslash'              => $this->_config->get_boolean( 'minify.csstidy.options.remove_bslash' ),
+					'compress_colors'            => $this->_config->get_boolean( 'minify.csstidy.options.compress_colors' ),
+					'compress_font-weight'       => $this->_config->get_boolean( 'minify.csstidy.options.compress_font-weight' ),
+					'lowercase_s'                => $this->_config->get_boolean( 'minify.csstidy.options.lowercase_s' ),
+					'optimise_shorthands'        => $this->_config->get_integer( 'minify.csstidy.options.optimise_shorthands' ),
+					'remove_last_;'              => $this->_config->get_boolean( 'minify.csstidy.options.remove_last_;' ),
+					'space_before_important'     => ! $this->_config->get_boolean( 'minify.csstidy.options.remove_space_before_important' ),
+					'case_properties'            => $this->_config->get_integer( 'minify.csstidy.options.case_properties' ),
+					'sort_properties'            => $this->_config->get_boolean( 'minify.csstidy.options.sort_properties' ),
+					'sort_selectors'             => $this->_config->get_boolean( 'minify.csstidy.options.sort_selectors' ),
+					'merge_selectors'            => $this->_config->get_integer( 'minify.csstidy.options.merge_selectors' ),
+					'discard_invalid_selectors'  => $this->_config->get_boolean( 'minify.csstidy.options.discard_invalid_selectors' ),
+					'discard_invalid_properties' => $this->_config->get_boolean( 'minify.csstidy.options.discard_invalid_properties' ),
+					'css_level'                  => $this->_config->get_string( 'minify.csstidy.options.css_level' ),
+					'preserve_css'               => $this->_config->get_boolean( 'minify.csstidy.options.preserve_css' ),
+					'timestamp'                  => $this->_config->get_boolean( 'minify.csstidy.options.timestamp' ),
+					'template'                   => $this->_config->get_string( 'minify.csstidy.options.template' ),
+				);
+				break;
+
+			case 'html':
+			case 'htmlxml':
+				$options = array(
+					'xhtml'           => true,
+					'stripCrlf'       => $this->_config->get_boolean( 'minify.html.strip.crlf' ),
+					'ignoredComments' => $this->_config->get_array( 'minify.html.comments.ignore' ),
+				);
+				break;
+
+			case 'htmltidy':
+			case 'htmltidyxml':
+				$options = array(
+					'clean'         => $this->_config->get_boolean( 'minify.htmltidy.options.clean' ),
+					'hide-comments' => $this->_config->get_boolean( 'minify.htmltidy.options.hide-comments' ),
+					'wrap'          => $this->_config->get_integer( 'minify.htmltidy.options.wrap' ),
+				);
+				break;
 		}
 
-		if ( $this->_config->get_boolean( 'browsercache.enabled' ) && ( $this->_config->get_boolean( 'browsercache.cssjs.replace' ) || $this->_config->get_boolean( 'browsercache.html.replace' ) || $this->_config->get_boolean( 'browsercache.other.replace' ) ) ) {
+		if (
+			$this->_config->get_boolean( 'browsercache.enabled' ) &&
+			(
+				$this->_config->get_boolean( 'browsercache.cssjs.replace' ) ||
+				$this->_config->get_boolean( 'browsercache.html.replace' ) ||
+				$this->_config->get_boolean( 'browsercache.other.replace' )
+			)
+		) {
 			$w3_plugin_browsercache = Dispatcher::component( 'BrowserCache_Plugin' );
-			$browsercache_core = Dispatcher::component( 'BrowserCache_Core' );
-
-			$options = array_merge( $options, array(
-					'browserCacheId' => $w3_plugin_browsercache->get_filename_uniqualizator(),
-					'browserCacheExtensions' => $browsercache_core->get_replace_extensions( $this->_config )
-				) );
+			$browsercache_core      = Dispatcher::component( 'BrowserCache_Core' );
+
+			$options = array_merge(
+				$options,
+				array(
+					'browserCacheId'         => $w3_plugin_browsercache->get_filename_uniqualizator(),
+					'browserCacheExtensions' => $browsercache_core->get_replace_extensions( $this->_config ),
+				)
+			);
 		}
 
 		if ( $this->_config->get_boolean( 'cdn.enabled' ) ) {
 			$common = Dispatcher::component( 'Cdn_Core' );
-			$cdn = $common->get_cdn();
+			$cdn    = $common->get_cdn();
 
-			$options = array_merge( $options, array(
+			$options = array_merge(
+				$options,
+				array(
 					'prependAbsolutePathCallback' => array( &$cdn, 'get_prepend_path' ),
-				) );
+				)
+			);
 		}
 
 		return $options;
diff --git a/Minify_Core.php b/Minify_Core.php
index 0ff891249..649ae92a9 100644
--- a/Minify_Core.php
+++ b/Minify_Core.php
@@ -1,24 +1,38 @@
 <?php
+/**
+ * File: Minify_ConfigLabels.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * component of shared code used by minify
+ * Class Minify_Core
+ *
+ * Component of shared code used by minify
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 class Minify_Core {
 	/**
-	 * Encode an array of files into a filename containing all files.
+	 * Generates the minified filename for a set of files.
+	 *
+	 * @param array  $files Array of files to be minified.
+	 * @param string $type  The type of the minification (e.g., 'css', 'js').
+	 *
+	 * @return string|null The minified filename or null if a collision occurs.
 	 */
-	static public function urls_for_minification_to_minify_filename( $files, $type ) {
-		$files_string = json_encode( $files );
+	public static function urls_for_minification_to_minify_filename( $files, $type ) {
+		$files_string = wp_json_encode( $files );
 
-		$key = self::urls_for_minification_to_minify_key( $files_string,
-			substr( md5( $files_string ), 0, 5 ) );
+		$key = self::urls_for_minification_to_minify_key( $files_string, substr( md5( $files_string ), 0, 5 ) );
 		if ( is_null( $key ) ) {
-			// key collision (rare case), try full md5
-			$key = self::urls_for_minification_to_minify_key( $files_string,
-				md5( $files_string ) );
+			// key collision (rare case), try full md5.
+			$key = self::urls_for_minification_to_minify_key( $files_string, md5( $files_string ) );
 			if ( is_null( $key ) ) {
-				// collision of full md5 - unprobable
+				// collision of full md5 - unprobable.
 				return null;
 			}
 		}
@@ -39,12 +53,17 @@ static public function urls_for_minification_to_minify_filename( $files, $type )
 	}
 
 	/**
-	 * Tries key for minified array of files
+	 * Retrieves the minification key based on the files string.
+	 *
+	 * @param string $files_string JSON encoded string of files.
+	 * @param string $key          The base key to check.
+	 *
+	 * @return string|null The key if found, or null if not.
 	 */
-	static private function urls_for_minification_to_minify_key( $files_string, $key ) {
-		$v = get_option( 'w3tc_minify_' . $key );
+	private static function urls_for_minification_to_minify_key( $files_string, $key ) {
+		$v                = get_option( 'w3tc_minify_' . $key );
 		$minify_filenames = @json_decode( $v, true );
-		if ( empty( $minify_filenames ) || !is_array( $minify_filenames ) ) {
+		if ( empty( $minify_filenames ) || ! is_array( $minify_filenames ) ) {
 			update_option( 'w3tc_minify_' . $key, $files_string, false );
 			return $key;
 		}
@@ -57,19 +76,21 @@ static private function urls_for_minification_to_minify_key( $files_string, $key
 	}
 
 	/**
-	 * Decode a minify auto filename into an array of files.
+	 * Retrieves the URLs associated with a minified filename.
+	 *
+	 * @param string $filename The minified filename.
+	 * @param string $type     The type of the minified file (e.g., 'css', 'js').
 	 *
-	 * @param unknown $compressed
-	 * @param unknown $type
-	 * @return array
+	 * @return array An array of verified URLs.
 	 */
-	static public function minify_filename_to_urls_for_minification( $filename, $type ) {
+	public static function minify_filename_to_urls_for_minification( $filename, $type ) {
 		$hash = has_filter( 'w3tc_minify_urls_for_minification_to_minify_filename' ) ?
-			get_option( 'w3tc_minify_filter_' . hash( 'crc32b', $filename . '.' . $type ) ) : $filename;
+			get_option( 'w3tc_minify_filter_' . hash( 'crc32b', $filename . '.' . $type ) ) :
+			$filename;
 		$v    = get_option( 'w3tc_minify_' . $hash );
 
 		$urls_unverified = @json_decode( $v, true );
-		if ( !is_array( $urls_unverified ) ) {
+		if ( ! is_array( $urls_unverified ) ) {
 			return array();
 		}
 
@@ -78,53 +99,73 @@ static public function minify_filename_to_urls_for_minification( $filename, $typ
 		foreach ( $urls_unverified as $file ) {
 			$verified = false;
 			if ( Util_Environment::is_url( $file ) ) {
-				$c = Dispatcher::config();
-				$external = $c->get_array( 'minify.cache.files' );
+				$c               = Dispatcher::config();
+				$external        = $c->get_array( 'minify.cache.files' );
 				$external_regexp = $c->get_boolean( 'minify.cache.files_regexp' );
 
 				foreach ( $external as $ext ) {
-					if ( empty( $ext ) )
+					if ( empty( $ext ) ) {
 						continue;
+					}
 
-					if ( !$external_regexp &&
+					if (
+						! $external_regexp &&
 						preg_match( '~^' . Util_Environment::get_url_regexp( $ext ) . '~', $file ) &&
-						!$verified ) {
+						! $verified
+					) {
 						$verified = true;
 					}
-					if ( $external_regexp &&
-						preg_match( '~' . $ext . '~', $file ) && !$verified ) {
+
+					if (
+						$external_regexp &&
+						preg_match( '~' . $ext . '~', $file ) &&
+						! $verified
+					) {
 						$verified = true;
 					}
 				}
-				if ( !$verified ) {
-					Minify_Core::debug_error( sprintf( 'Remote file not in external files/libraries list: "%s"', $file ) );
+
+				if ( ! $verified ) {
+					self::debug_error( sprintf( 'Remote file not in external files/libraries list: "%s"', $file ) );
 				}
-			} elseif (  /* no .. */  strpos( $file, '..' ) != false
-				// no "//"
-				|| strpos( $file, '//' ) !== false
-				// no "\"
-				|| ( strpos( $file, '\\' ) !== false && strtoupper( substr( PHP_OS, 0, 3 ) ) != 'WIN' )
-				// no "./"
-				|| preg_match( '/(?:^|[^\\.])\\.\\//', $file )
-				/* no unwanted chars */ ||
-				!preg_match( '/^[a-zA-Z0-9_.\\/-]|[\\\\]+$/', $file ) ) {
+			} elseif (
+				/* no ".." */
+				strpos( $file, '..' ) !== false ||
+				/* no "//" */
+				strpos( $file, '//' ) !== false ||
+				/* no "\" */
+				(
+					strpos( $file, '\\' ) !== false &&
+					'WIN' !== strtoupper( substr( PHP_OS, 0, 3 ) )
+				) ||
+				/* no "./" */
+				preg_match( '/(?:^|[^\\.])\\.\\//', $file ) ||
+				/* no unwanted chars */
+				! preg_match( '/^[a-zA-Z0-9_.\\/-]|[\\\\]+$/', $file )
+			) {
 				$verified = false;
-				Minify_Core::debug_error( sprintf( 'File path invalid: "%s"', $file ) );
+				self::debug_error( sprintf( 'File path invalid: "%s"', $file ) );
 			} else {
 				$verified = true;
 			}
 
-			if ( $verified )
+			if ( $verified ) {
 				$urls[] = $file;
+			}
 		}
 
 		return $urls;
 	}
 
-
-
-	static public function minified_url( $minify_filename ) {
-		$path = Util_Environment::cache_blog_minify_dir();
+	/**
+	 * Retrieves the URL for a minified file.
+	 *
+	 * @param string $minify_filename The filename of the minified file.
+	 *
+	 * @return string The URL of the minified file.
+	 */
+	public static function minified_url( $minify_filename ) {
+		$path     = Util_Environment::cache_blog_minify_dir();
 		$filename = $path . '/' . $minify_filename;
 
 		$c = Dispatcher::config();
@@ -135,38 +176,34 @@ static public function minified_url( $minify_filename ) {
 		return home_url( '?w3tc_minify=' . $minify_filename );
 	}
 
-
-
 	/**
-	 * Sends error response
+	 * Logs an error message for debugging.
+	 *
+	 * @param string $error The error message to log.
 	 *
-	 * @param string  $error
-	 * @param boolean $handle
-	 * @param integer $status
 	 * @return void
 	 */
-	static public function debug_error( $error ) {
-		$c = Dispatcher::config();
+	public static function debug_error( $error ) {
+		$c     = Dispatcher::config();
 		$debug = $c->get_boolean( 'minify.debug' );
 
 		if ( $debug ) {
-			Minify_Core::log( $error );
+			self::log( $error );
 			echo "\r\n/* " . esc_html( $error ) . " */\r\n";
 		}
 	}
 
-
-
 	/**
-	 * Log
+	 * Logs a message to the minify log file.
 	 *
-	 * @param string  $msg
-	 * @return bool
+	 * @param string $msg The message to log.
+	 *
+	 * @return bool True if the message was successfully written, false otherwise.
 	 */
-	static public function log( $msg ) {
+	public static function log( $msg ) {
 		$data = sprintf(
 			"[%s] [%s] [%s] %s\n",
-			date( 'r' ),
+			gmdate( 'r' ),
 			isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '',
 			! empty( $_SERVER['HTTP_REFERER'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '-',
 			$msg
@@ -175,45 +212,51 @@ static public function log( $msg ) {
 		$data = strtr( $data, '<>', '..' );
 
 		$filename = Util_Debug::log_filename( 'minify' );
+
 		return @file_put_contents( $filename, $data, FILE_APPEND );
 	}
 
-
-
+	/**
+	 * Retrieves the cache configuration for usage statistics based on the minify engine.
+	 *
+	 * phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
+	 *
+	 * @return array The cache configuration for the minify engine.
+	 */
 	public function get_usage_statistics_cache_config() {
-		$c = Dispatcher::config();
+		$c      = Dispatcher::config();
 		$engine = $c->get_string( 'minify.engine' );
 
 		switch ( $engine ) {
-		case 'memcached':
-			$engineConfig = array(
-				'servers' => $c->get_array( 'minify.memcached.servers' ),
-				'persistent' => $c->get_boolean( 'minify.memcached.persistent' ),
-				'aws_autodiscovery' =>
-				$c->get_boolean( 'minify.memcached.aws_autodiscovery' ),
-				'username' => $c->get_string( 'minify.memcached.username' ),
-				'password' => $c->get_string( 'minify.memcached.password' )
-			);
-			break;
-
-		case 'redis':
-			$engineConfig = array(
-				'servers' => $c->get_array( 'minify.redis.servers' ),
-				'verify_tls_certificates' => $c->get_boolean( 'minify.redis.verify_tls_certificates' ),
-				'persistent' => $c->get_boolean( 'minify.redis.persistent' ),
-				'timeout' => $c->get_integer( 'minify.redis.timeout' ),
-				'retry_interval' => $c->get_integer( 'minify.redis.retry_interval' ),
-				'read_timeout' => $c->get_integer( 'minify.redis.read_timeout' ),
-				'dbid' => $c->get_integer( 'minify.redis.dbid' ),
-				'password' => $c->get_string( 'minify.redis.password' )
-			);
-			break;
-
-		default:
-			$engineConfig = array();
+			case 'memcached':
+				$engineConfig = array(
+					'servers'           => $c->get_array( 'minify.memcached.servers' ),
+					'persistent'        => $c->get_boolean( 'minify.memcached.persistent' ),
+					'aws_autodiscovery' => $c->get_boolean( 'minify.memcached.aws_autodiscovery' ),
+					'username'          => $c->get_string( 'minify.memcached.username' ),
+					'password'          => $c->get_string( 'minify.memcached.password' ),
+				);
+				break;
+
+			case 'redis':
+				$engineConfig = array(
+					'servers'                 => $c->get_array( 'minify.redis.servers' ),
+					'verify_tls_certificates' => $c->get_boolean( 'minify.redis.verify_tls_certificates' ),
+					'persistent'              => $c->get_boolean( 'minify.redis.persistent' ),
+					'timeout'                 => $c->get_integer( 'minify.redis.timeout' ),
+					'retry_interval'          => $c->get_integer( 'minify.redis.retry_interval' ),
+					'read_timeout'            => $c->get_integer( 'minify.redis.read_timeout' ),
+					'dbid'                    => $c->get_integer( 'minify.redis.dbid' ),
+					'password'                => $c->get_string( 'minify.redis.password' ),
+				);
+				break;
+
+			default:
+				$engineConfig = array();
 		}
 
 		$engineConfig['engine'] = $engine;
+
 		return $engineConfig;
 	}
 }
diff --git a/Minify_Environment.php b/Minify_Environment.php
index 7a4b5fdda..972b99795 100644
--- a/Minify_Environment.php
+++ b/Minify_Environment.php
@@ -1,27 +1,38 @@
 <?php
-namespace W3TC;
-
-
-
+/**
+ * File: Minify_Environment_LiteSpeed.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
- * class Minify_Environment
+ * Class Minify_Environment
+ *
+ * phpcs:disable Squiz.Strings.DoubleQuoteUsage.NotRequired
  */
 class Minify_Environment {
+	/**
+	 * Constructor for the Minify_Environment class.
+	 *
+	 * Adds necessary filters during initialization.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
-		add_filter( 'w3tc_browsercache_rules_section',
-			array( $this, 'w3tc_browsercache_rules_section' ),
-			10, 3 );
+		add_filter( 'w3tc_browsercache_rules_section', array( $this, 'w3tc_browsercache_rules_section' ), 10, 3 );
 	}
 
 	/**
-	 * Fixes environment in each wp-admin request
+	 * Fixes issues related to the WordPress admin area requests.
+	 *
+	 * @param object $config           Configuration object for Minify settings.
+	 * @param bool   $force_all_checks Whether to force all checks regardless of configuration state.
 	 *
-	 * @param Config $config           Config.
-	 * @param bool   $force_all_checks Force checks flag.
+	 * @return void
 	 *
-	 * @throws Util_Environment_Exceptions Exceptions.
+	 * @throws \Util_Environment_Exceptions If configuration or folder-related errors occur.
 	 */
 	public function fix_on_wpadmin_request( $config, $force_all_checks ) {
 		$exs            = new Util_Environment_Exceptions();
@@ -66,13 +77,13 @@ public function fix_on_wpadmin_request( $config, $force_all_checks ) {
 	}
 
 	/**
-	 * Fixes environment once event occurs
+	 * Handles configuration adjustments triggered by events.
 	 *
-	 * @param Config      $config     Config.
-	 * @param string      $event      Event.
-	 * @param null|Config $old_config Old Config.
+	 * @param object $config     Configuration object for Minify settings.
+	 * @param string $event      The event that triggered this function.
+	 * @param object $old_config Optional previous configuration object for comparison.
 	 *
-	 * @throws Util_Environment_Exceptions Exceptions.
+	 * @return void
 	 */
 	public function fix_on_event( $config, $event, $old_config = null ) {
 		$minify_enabled = $config->get_boolean( 'minify.enabled' );
@@ -96,11 +107,11 @@ public function fix_on_event( $config, $event, $old_config = null ) {
 	}
 
 	/**
-	 * Fixes environment after plugin deactivation
-	 *
-	 * @throws Util_Environment_Exceptions Exception.
+	 * Executes necessary clean-up actions after the plugin is deactivated.
 	 *
 	 * @return void
+	 *
+	 * @throws \Util_Environment_Exceptions If removal of rules or unscheduling fails.
 	 */
 	public function fix_after_deactivation() {
 		$exs = new Util_Environment_Exceptions();
@@ -117,50 +128,57 @@ public function fix_after_deactivation() {
 	}
 
 	/**
+	 * Retrieves the required rewrite rules based on the current configuration.
 	 *
+	 * @param object $config Configuration object for Minify settings.
 	 *
-	 * @param Config  $config
-	 * @return array
+	 * @return array|null Array of rewrite rules or null if Minify is disabled.
 	 */
-	function get_required_rules( $config ) {
-		if ( !$config->get_boolean( 'minify.enabled' ) )
+	public function get_required_rules( $config ) {
+		if ( ! $config->get_boolean( 'minify.enabled' ) ) {
 			return null;
+		}
 
 		$rewrite_rules = array();
-		if ( $config->get_string( 'minify.engine' ) == 'file' ) {
+		if ( 'file' === $config->get_string( 'minify.engine' ) ) {
 			$minify_rules_cache_path = Util_Rule::get_minify_rules_cache_path();
-			$rewrite_rules[] = array(
+			$rewrite_rules[]         = array(
 				'filename' => $minify_rules_cache_path,
-				'content'  => $this->rules_cache_generate( $config )
+				'content'  => $this->rules_cache_generate( $config ),
 			);
 		}
+
 		$minify_rules_core_path = Util_Rule::get_minify_rules_core_path();
-		$rewrite_rules[] = array(
+		$rewrite_rules[]        = array(
 			'filename' => $minify_rules_core_path,
 			'content'  => $this->rules_core_generate( $config ),
-			'priority' => 1000
+			'priority' => 1000,
 		);
 
 		return $rewrite_rules;
 	}
 
-
-
 	/**
-	 * Fixes folders
+	 * Fixes folder-related issues for the Minify engine.
+	 *
+	 * @param object $config Configuration object for Minify settings.
+	 * @param object $exs    Collection of exceptions encountered during the process.
 	 *
-	 * @param Config  $config
-	 * @param Util_Environment_Exceptions $exs
+	 * @return void
 	 */
 	private function fix_folders( $config, $exs ) {
-		// folder that we delete if exists and not writeable
-		if ( $config->get_boolean( 'minify.enabled' ) &&
-			$config->get_string( 'minify.engine' ) == 'file' ) {
+		// folder that we delete if exists and not writeable.
+		if ( $config->get_boolean( 'minify.enabled' ) && 'file' === $config->get_string( 'minify.engine' ) ) {
 			$dir = W3TC_CACHE_MINIFY_DIR;
 
-			try{
-				if ( file_exists( $dir ) && !is_writeable( $dir ) )
-					Util_WpFile::delete_folder( $dir, '', isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '' );
+			try {
+				if ( file_exists( $dir ) && ! is_writeable( $dir ) ) {
+					Util_WpFile::delete_folder(
+						$dir,
+						'',
+						isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''
+					);
+				}
 			} catch ( Util_WpFile_FilesystemRmdirException $ex ) {
 				$exs->push( $ex );
 			}
@@ -168,43 +186,45 @@ private function fix_folders( $config, $exs ) {
 	}
 
 	/**
-	 * Minifiers availability error handling
+	 * Verifies that the Minify engine is working correctly.
 	 *
-	 * @param Config  $config
-	 * @param Util_Environment_Exceptions $exs
+	 * @param object $config Configuration object for Minify settings.
+	 * @param object $exs    Collection of exceptions encountered during the process.
+	 *
+	 * @return void
 	 */
 	private function verify_engine_working( $config, $exs ) {
 		$minifiers_errors = array();
 
-		if ( $config->get_string( 'minify.js.engine' ) == 'yuijs' ) {
+		if ( 'yuijs' === $config->get_string( 'minify.js.engine' ) ) {
 			$path_java = $config->get_string( 'minify.yuijs.path.java' );
-			$path_jar = $config->get_string( 'minify.yuijs.path.jar' );
+			$path_jar  = $config->get_string( 'minify.yuijs.path.jar' );
 
-			if ( !file_exists( $path_java ) ) {
+			if ( ! file_exists( $path_java ) ) {
 				$minifiers_errors[] = sprintf( 'YUI Compressor (JS): JAVA executable path was not found. The default minifier JSMin will be used instead.' );
-			} elseif ( !file_exists( $path_jar ) ) {
+			} elseif ( ! file_exists( $path_jar ) ) {
 				$minifiers_errors[] = sprintf( 'YUI Compressor (JS): JAR file path was not found. The default minifier JSMin will be used instead.' );
 			}
 		}
 
-		if ( $config->get_string( 'minify.css.engine' ) == 'yuicss' ) {
+		if ( 'yuicss' === $config->get_string( 'minify.css.engine' ) ) {
 			$path_java = $config->get_string( 'minify.yuicss.path.java' );
-			$path_jar = $config->get_string( 'minify.yuicss.path.jar' );
+			$path_jar  = $config->get_string( 'minify.yuicss.path.jar' );
 
-			if ( !file_exists( $path_java ) ) {
+			if ( ! file_exists( $path_java ) ) {
 				$minifiers_errors[] = sprintf( 'YUI Compressor (CSS): JAVA executable path was not found. The default CSS minifier will be used instead.' );
-			} elseif ( !file_exists( $path_jar ) ) {
+			} elseif ( ! file_exists( $path_jar ) ) {
 				$minifiers_errors[] = sprintf( 'YUI Compressor (CSS): JAR file path was not found. The default CSS minifier will be used instead.' );
 			}
 		}
 
-		if ( $config->get_string( 'minify.js.engine' ) == 'ccjs' ) {
+		if ( 'ccjs' === $config->get_string( 'minify.js.engine' ) ) {
 			$path_java = $config->get_string( 'minify.ccjs.path.java' );
-			$path_jar = $config->get_string( 'minify.ccjs.path.jar' );
+			$path_jar  = $config->get_string( 'minify.ccjs.path.jar' );
 
-			if ( !file_exists( $path_java ) ) {
+			if ( ! file_exists( $path_java ) ) {
 				$minifiers_errors[] = sprintf( 'Closure Compiler: JAVA executable path was not found. The default minifier JSMin will be used instead.' );
-			} elseif ( !file_exists( $path_jar ) ) {
+			} elseif ( ! file_exists( $path_jar ) ) {
 				$minifiers_errors[] = sprintf( 'Closure Compiler: JAR file path was not found. The default minifier JSMin will be used instead.' );
 			}
 		}
@@ -223,77 +243,70 @@ private function verify_engine_working( $config, $exs ) {
 	}
 
 	/**
-	 * Checks rewrite
+	 * Verifies that URL rewriting functionality for Minify is working.
 	 *
-	 * @throws Util_Environment_Exceptions
+	 * @return void
+	 *
+	 * @throws \Util_Environment_Exception If URL rewriting fails.
 	 */
 	private function verify_rewrite_working() {
-		$url = Minify_Core::minified_url( rand() . 'w3tc_rewrite_test.css' );
+		$url = Minify_Core::minified_url( wp_rand() . 'w3tc_rewrite_test.css' );
 
 		$result = $this->test_rewrite( $url );
-		if ( $result != 'ok' ) {
+		if ( 'ok' !== $result ) {
 			$home_url = get_home_url();
 
 			$tech_message =
 				( Util_Environment::is_nginx() ? 'nginx configuration file' : '.htaccess file' ) .
-				' contains rules to rewrite url ' .
-				$url . '. If handled by ' .
-				'plugin, it returns "Minify OK" message.<br/>';
-			$tech_message .= 'The plugin made a request to ' .
-				$url . ' but received: <br />' .
-				$result . '<br />';
-			$tech_message .= 'instead of "Minify OK" response. <br />';
+				' contains rules to rewrite url ' . $url . '. If handled by plugin, it returns "Minify OK"' .
+				' message.<br/>The plugin made a request to ' . $url . ' but received: <br />' . $result .
+				'<br />instead of "Minify OK" response. <br />';
 
 			$error = '<strong>W3 Total Cache error:</strong>It appears Minify ' .
-				'<acronym title="Uniform Resource Locator">URL</acronym> ' .
-				'rewriting is not working. ';
+				'<acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. ';
 
 			if ( Util_Environment::is_nginx() ) {
-				$error .= 'Please verify that all configuration files are ' .
-					'included in the configuration file ' .
+				$error .= 'Please verify that all configuration files are included in the configuration file ' .
 					'(and that you have reloaded / restarted nginx).';
 			} else {
-				$error .= 'Please verify that the server configuration ' .
-					'allows .htaccess';
+				$error .= 'Please verify that the server configuration allows .htaccess';
 			}
 
-			$error .= '<br />Unfortunately minification will ' .
-				'not function without custom rewrite rules. ' .
-				'Please ask your server administrator for assistance. ' .
-				'Also refer to <a href="' .
-				admin_url( 'admin.php?page=w3tc_install' ) .
-				'">the install page</a>  for the rules for your server.';
+			$error .= '<br />Unfortunately minification will not function without custom rewrite rules. ' .
+				'Please ask your server administrator for assistance. Also refer to <a href="' .
+				admin_url( 'admin.php?page=w3tc_install' ) . '">the install page</a>  for the rules for your server.';
 
 			throw new Util_Environment_Exception( $error, $tech_message );
 		}
 	}
 
 	/**
-	 * Perform rewrite test
+	 * Tests the rewrite rules by sending a request to a test Minify URL.
+	 *
+	 * @param string $url The URL to test for rewriting functionality.
 	 *
-	 * @param string  $url
-	 * @return boolean
+	 * @return string 'ok' if successful, or an error message otherwise.
 	 */
 	private function test_rewrite( $url ) {
-		$key = sprintf( 'w3tc_rewrite_test_%s', substr( md5( $url ), 0, 16 ) );
+		$key    = sprintf( 'w3tc_rewrite_test_%s', substr( md5( $url ), 0, 16 ) );
 		$result = get_site_transient( $key );
 
-		if ( $result != 'ok' ) {
+		if ( 'ok' !== $result ) {
 			$response = Util_Http::get( $url );
 
-			$is_ok = ( !is_wp_error( $response ) &&
-				$response['response']['code'] == 200 &&
-				trim( $response['body'] ) == 'Minify OK' );
+			$is_ok = (
+				! is_wp_error( $response ) &&
+				200 === $response['response']['code'] &&
+				'Minify OK' === trim( $response['body'] )
+			);
 
-			if ( $is_ok )
+			if ( $is_ok ) {
 				$result = 'ok';
-			else {
-				if ( is_wp_error( $response ) )
+			} else {
+				if ( is_wp_error( $response ) ) {
 					$result = $response->get_error_message();
-				else {
-					$result = '<pre>' .
-						print_r( $response['response'], true ) .
-						'</pre>';
+				} else {
+					$result = '<pre>' . print_r( $response['response'], true ) . '</pre>'; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
 				}
 			}
 
@@ -303,10 +316,8 @@ private function test_rewrite( $url ) {
 		return $result;
 	}
 
-
-
 	/**
-	 * Remove Garbage collection cron job.
+	 * Unschedules the garbage collection event for Minify files.
 	 *
 	 * @return void
 	 */
@@ -317,7 +328,7 @@ private function unschedule_gc() {
 	}
 
 	/**
-	 * Remove cron job for minify purge.
+	 * Unschedules the WordPress cron event for purging Minify cache.
 	 *
 	 * @since 2.8.0
 	 *
@@ -329,133 +340,146 @@ private function unschedule_purge_wpcron() {
 		}
 	}
 
-
-	/**
-	 * rules core modification
-	 */
-
 	/**
-	 * Writes directives to WP .htaccess
+	 * Adds core rewrite rules for Minify.
+	 *
+	 * @param object $config Configuration object for Minify settings.
+	 * @param object $exs    Collection of exceptions encountered during the process.
 	 *
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @return void
 	 */
 	private function rules_core_add( $config, $exs ) {
-
-		Util_Rule::add_rules( $exs, Util_Rule::get_minify_rules_core_path(),
+		Util_Rule::add_rules(
+			$exs,
+			Util_Rule::get_minify_rules_core_path(),
 			$this->rules_core_generate( $config ),
 			W3TC_MARKER_BEGIN_MINIFY_CORE,
 			W3TC_MARKER_END_MINIFY_CORE,
 			array(
-				W3TC_MARKER_BEGIN_PGCACHE_CORE => 0,
-				W3TC_MARKER_BEGIN_WORDPRESS => 0,
+				W3TC_MARKER_BEGIN_PGCACHE_CORE     => 0,
+				W3TC_MARKER_BEGIN_WORDPRESS        => 0,
 				W3TC_MARKER_END_BROWSERCACHE_CACHE => strlen( W3TC_MARKER_END_BROWSERCACHE_CACHE ) + 1,
-				W3TC_MARKER_END_PGCACHE_CACHE => strlen( W3TC_MARKER_END_PGCACHE_CACHE ) + 1,
-				W3TC_MARKER_END_MINIFY_CACHE => strlen( W3TC_MARKER_END_MINIFY_CACHE ) + 1
+				W3TC_MARKER_END_PGCACHE_CACHE      => strlen( W3TC_MARKER_END_PGCACHE_CACHE ) + 1,
+				W3TC_MARKER_END_MINIFY_CACHE       => strlen( W3TC_MARKER_END_MINIFY_CACHE ) + 1,
 			)
 		);
 	}
 
 	/**
-	 * Removes Page Cache core directives
+	 * Removes core rewrite rules for Minify.
 	 *
-	 * @param Util_Environment_Exceptions $exs
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @param object $exs Collection of exceptions encountered during the process.
+	 *
+	 * @return void
 	 */
 	private function rules_core_remove( $exs ) {
-		// no need to remove rules for apache - its in cache .htaccess file
-		if ( !Util_Environment::is_nginx() )
+		// no need to remove rules for apache - its in cache .htaccess file.
+		if ( ! Util_Environment::is_nginx() ) {
 			return;
+		}
 
-		Util_Rule::remove_rules( $exs,
+		Util_Rule::remove_rules(
+			$exs,
 			Util_Rule::get_minify_rules_core_path(),
-			W3TC_MARKER_BEGIN_MINIFY_CORE ,
-			W3TC_MARKER_END_MINIFY_CORE );
+			W3TC_MARKER_BEGIN_MINIFY_CORE,
+			W3TC_MARKER_END_MINIFY_CORE
+		);
 	}
 
 	/**
-	 * Generates rules for WP dir
+	 * Generates the core rewrite rules for Minify based on the server environment.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @param object $config Configuration object for Minify settings.
+	 *
+	 * @return string The generated rules.
 	 */
 	public function rules_core_generate( $config ) {
 		switch ( true ) {
-		case Util_Environment::is_apache():
-		case Util_Environment::is_litespeed():
-			return $this->rules_core_generate_apache( $config );
+			case Util_Environment::is_apache():
+			case Util_Environment::is_litespeed():
+				return $this->rules_core_generate_apache( $config );
 
-		case Util_Environment::is_nginx():
-			return $this->rules_core_generate_nginx( $config );
+			case Util_Environment::is_nginx():
+				return $this->rules_core_generate_nginx( $config );
 		}
 
 		return '';
 	}
 
+	/**
+	 * Retrieves the site URI for the current WordPress installation.
+	 *
+	 * @return string The relative site URI.
+	 */
 	private function site_uri() {
 		$site_uri = rtrim( network_site_url( '', 'relative' ), '/' ) . '/';
 
-		/* There is a bug in WP where network_home_url can return
-		 * a non-relative URI even though scheme is set to relative.
-		 */
+		// There is a bug in WP where network_home_url can return a non-relative URI even though scheme is set to relative.
 		if ( Util_Environment::is_url( $site_uri ) ) {
-			$site_uri = parse_url( $site_uri, PHP_URL_PATH );
+			$site_uri = wp_parse_url( $site_uri, PHP_URL_PATH );
 		}
 
 		return $site_uri;
 	}
 
 	/**
-	 * Generates rules
+	 * Generates Apache rewrite rules for core minification functionality.
+	 *
+	 * @param object $config Configuration object containing relevant settings.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string Generated Apache rewrite rules.
 	 */
-	function rules_core_generate_apache( $config ) {
-		$cache_uri = Util_Environment::url_to_uri(
-			Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR ) ) . '/';
-		$site_uri = $this->site_uri();
-
-		/* There is a bug in WP where network_home_url can return
-		 * a non-relative URI even though scheme is set to relative.
-		 */
+	public function rules_core_generate_apache( $config ) {
+		$cache_uri = Util_Environment::url_to_uri( Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR ) ) . '/';
+		$site_uri  = $this->site_uri();
+
+		// There is a bug in WP where network_home_url can return a non-relative URI even though scheme is set to relative.
 		if ( Util_Environment::is_url( $site_uri ) ) {
-			$site_uri = parse_url( $site_uri, PHP_URL_PATH );
+			$site_uri = wp_parse_url( $site_uri, PHP_URL_PATH );
 		}
 
-		$engine = $config->get_string( 'minify.engine' );
+		$engine       = $config->get_string( 'minify.engine' );
 		$browsercache = $config->get_boolean( 'browsercache.enabled' );
-		$brotli = ( $browsercache &&
+
+		$brotli = (
+			$browsercache &&
 			$config->get_boolean( 'browsercache.cssjs.brotli' ) &&
-			!defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) );
-		$compression = ( $browsercache &&
+			! defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' )
+		);
+
+		$compression = (
+			$browsercache &&
 			$config->get_boolean( 'browsercache.cssjs.compression' ) &&
-			!defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) );
+			! defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' )
+		);
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_MINIFY_CORE . "\n";
 		$rules .= "<IfModule mod_rewrite.c>\n";
 		$rules .= "    RewriteEngine On\n";
 		$rules .= "    RewriteBase " . $cache_uri . "\n";
 
-		if ( $engine == 'file' ) {
+		if ( 'file' === $engine ) {
 			if ( $brotli ) {
 				$rules .= "    RewriteCond %{HTTP:Accept-Encoding} br\n";
 				$rules .= "    RewriteRule .* - [E=APPEND_EXT:_br]\n";
 				$rules .= "    RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -" . ( $config->get_boolean( 'minify.file.nfs' ) ? 'F' : 'f' ) . "\n";
 				$rules .= "    RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]\n";
 			}
+
 			if ( $compression ) {
 				$rules .= "    RewriteCond %{HTTP:Accept-Encoding} gzip\n";
 				$rules .= "    RewriteRule .* - [E=APPEND_EXT:_gzip]\n";
 				$rules .= "    RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -" . ( $config->get_boolean( 'minify.file.nfs' ) ? 'F' : 'f' ) . "\n";
 				$rules .= "    RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]\n";
 			}
-			if ( !$brotli && !$compression ) {
+
+			if ( ! $brotli && ! $compression ) {
 				$rules .= "    RewriteCond %{REQUEST_FILENAME} !-f\n";
 			}
 		}
-		$rules .= "    RewriteRule ^(.+\\.(css|js))$ {$site_uri}index.php [L]\n";
 
+		$rules .= "    RewriteRule ^(.+\\.(css|js))$ {$site_uri}index.php [L]\n";
 		$rules .= "</IfModule>\n";
 		$rules .= W3TC_MARKER_END_MINIFY_CORE . "\n";
 
@@ -463,44 +487,50 @@ function rules_core_generate_apache( $config ) {
 	}
 
 	/**
-	 * Generates rules
+	 * Generates NGINX rewrite rules for core minification functionality.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @param object $config Configuration object containing relevant settings.
+	 *
+	 * @return string Generated NGINX rewrite rules.
 	 */
-	function rules_core_generate_nginx( $config ) {
-		$cache_uri = Util_Environment::url_to_uri(
-			Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR ) ) . '/';
+	public function rules_core_generate_nginx( $config ) {
+		$cache_uri       = Util_Environment::url_to_uri( Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR ) ) . '/';
 		$first_regex_var = '$1';
 
-		// for subdir - need to count subdir in url
-		if ( Util_Environment::is_wpmu() && !Util_Environment::is_wpmu_subdomain() ) {
-			// take into accont case when whole subdir wpmu is installed in subdir
+		// for subdir - need to count subdir in url.
+		if ( Util_Environment::is_wpmu() && ! Util_Environment::is_wpmu_subdomain() ) {
+			// take into accont case when whole subdir wpmu is installed in subdir.
 			$home_uri = network_home_url( '', 'relative' );
-			if ( substr( $cache_uri, 0, strlen( $home_uri ) ) == $home_uri )
-				$cache_uri = $home_uri . '([a-z0-9]+/)?' .
-					substr( $cache_uri, strlen( $home_uri ) );
-			else
+			if ( substr( $cache_uri, 0, strlen( $home_uri ) ) === $home_uri ) {
+				$cache_uri = $home_uri . '([a-z0-9]+/)?' . substr( $cache_uri, strlen( $home_uri ) );
+			} else {
 				$cache_uri = '(/[a-z0-9]+)?' . $cache_uri;
+			}
 
 			$first_regex_var = '$2';
 		}
 
 		$minify_uri = $this->site_uri();
 
-		$engine = $config->get_string( 'minify.engine' );
+		$engine       = $config->get_string( 'minify.engine' );
 		$browsercache = $config->get_boolean( 'browsercache.enabled' );
-		$brotli = ( $browsercache &&
+
+		$brotli = (
+			$browsercache &&
 			$config->get_boolean( 'browsercache.cssjs.brotli' ) &&
-			!defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) );
-		$compression = ( $browsercache &&
+			! defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' )
+		);
+
+		$compression = (
+			$browsercache &&
 			$config->get_boolean( 'browsercache.cssjs.compression' ) &&
-			!defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) );
+			! defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' )
+		);
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_MINIFY_CORE . "\n";
 
-		if ( $engine == 'file' ) {
+		if ( 'file' === $engine ) {
 			$rules .= "set \$w3tc_enc \"\";\n";
 
 			if ( $brotli ) {
@@ -519,99 +549,101 @@ function rules_core_generate_nginx( $config ) {
 			$rules .= "    rewrite (.*) $1\$w3tc_enc break;\n";
 			$rules .= "}\n";
 		}
+
 		$rules .= "rewrite ^$cache_uri {$minify_uri}index.php last;\n";
 		$rules .= W3TC_MARKER_END_MINIFY_CORE . "\n";
 
 		return $rules;
 	}
 
-
-
-	/*
-	 * cache rules
-	 */
-
 	/**
-	 * Writes directives to file cache .htaccess
-	 * Throws exception on error
+	 * Adds cache rules for minification.
+	 *
+	 * @param object $config Configuration object containing relevant settings.
+	 * @param array  $exs    Array of existing rules to be modified or added to.
 	 *
-	 * @param Config  $config
-	 * @param Util_Environment_Exceptions $exs
+	 * @return void
 	 */
 	private function rules_cache_add( $config, $exs ) {
-		Util_Rule::add_rules( $exs,
+		Util_Rule::add_rules(
+			$exs,
 			Util_Rule::get_minify_rules_cache_path(),
 			$this->rules_cache_generate( $config ),
 			W3TC_MARKER_BEGIN_MINIFY_CACHE,
 			W3TC_MARKER_END_MINIFY_CACHE,
 			array(
-				W3TC_MARKER_BEGIN_PGCACHE_CACHE => 0,
+				W3TC_MARKER_BEGIN_PGCACHE_CACHE      => 0,
 				W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE => 0,
-				W3TC_MARKER_BEGIN_MINIFY_CORE => 0,
-				W3TC_MARKER_BEGIN_PGCACHE_CORE => 0,
-				W3TC_MARKER_BEGIN_WORDPRESS => 0
+				W3TC_MARKER_BEGIN_MINIFY_CORE        => 0,
+				W3TC_MARKER_BEGIN_PGCACHE_CORE       => 0,
+				W3TC_MARKER_BEGIN_WORDPRESS          => 0,
 			)
 		);
 	}
 
 	/**
-	 * Removes Page Cache core directives
+	 * Removes cache rules for minification.
 	 *
-	 * @param Util_Environment_Exceptions $exs
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @param array $exs Array of existing rules to be modified or removed.
+	 *
+	 * @return void
 	 */
 	private function rules_cache_remove( $exs ) {
-		// apache's cache files are not used when core rules disabled
-		if ( !Util_Environment::is_nginx() )
+		// apache's cache files are not used when core rules disabled.
+		if ( ! Util_Environment::is_nginx() ) {
 			return;
+		}
 
-		Util_Rule::remove_rules( $exs,
+		Util_Rule::remove_rules(
+			$exs,
 			Util_Rule::get_minify_rules_cache_path(),
 			W3TC_MARKER_BEGIN_MINIFY_CACHE,
-			W3TC_MARKER_END_MINIFY_CACHE );
+			W3TC_MARKER_END_MINIFY_CACHE
+		);
 
 	}
 
 	/**
-	 * Generates directives for file cache dir
+	 * Generates cache rules based on the server environment.
+	 *
+	 * @param object $config Configuration object containing relevant settings.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string Generated cache rules.
 	 */
 	private function rules_cache_generate( $config ) {
 		switch ( true ) {
-		case Util_Environment::is_apache():
-		case Util_Environment::is_litespeed():
-			return $this->rules_cache_generate_apache( $config );
+			case Util_Environment::is_apache():
+			case Util_Environment::is_litespeed():
+				return $this->rules_cache_generate_apache( $config );
 
-		case Util_Environment::is_nginx():
-			return $this->rules_cache_generate_nginx( $config );
+			case Util_Environment::is_nginx():
+				return $this->rules_cache_generate_nginx( $config );
 		}
 
 		return '';
 	}
 
-
 	/**
-	 * Generates directives for file cache dir
+	 * Generates Apache cache rules for minification.
+	 *
+	 * @param object $config Configuration object containing relevant settings.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string Generated Apache cache rules.
 	 */
 	private function rules_cache_generate_apache( $config ) {
-		$browsercache = $config->get_boolean( 'browsercache.enabled' );
-		$brotli = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.brotli' ) );
-		$compression = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.compression' ) );
-		$expires = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.expires' ) );
-		$lifetime = ( $browsercache ? $config->get_integer( 'browsercache.cssjs.lifetime' ) : 0 );
+		$browsercache  = $config->get_boolean( 'browsercache.enabled' );
+		$brotli        = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.brotli' ) );
+		$compression   = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.compression' ) );
+		$expires       = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.expires' ) );
+		$lifetime      = ( $browsercache ? $config->get_integer( 'browsercache.cssjs.lifetime' ) : 0 );
 		$cache_control = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.cache.control' ) );
-		$etag = ( $browsercache && $config->get_integer( 'browsercache.html.etag' ) );
-		$w3tc = ( $browsercache && $config->get_integer( 'browsercache.cssjs.w3tc' ) );
+		$etag          = ( $browsercache && $config->get_integer( 'browsercache.html.etag' ) );
+		$w3tc          = ( $browsercache && $config->get_integer( 'browsercache.cssjs.w3tc' ) );
 		$compatibility = $config->get_boolean( 'pgcache.compatibility' );
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_MINIFY_CACHE . "\n";
-		// workaround for .gzip
+		// workaround for .gzip.
 		if ( $compatibility ) {
 			$rules .= "Options -MultiViews\n";
 		}
@@ -662,8 +694,7 @@ private function rules_cache_generate_apache( $config ) {
 			$rules .= "<IfModule mod_headers.c>\n";
 
 			if ( $w3tc ) {
-				$rules .= "    Header set X-Powered-By \"" .
-					Util_Environment::w3tc_header() . "\"\n";
+				$rules .= "    Header set X-Powered-By \"" . Util_Environment::w3tc_header() . "\"\n";
 			}
 
 			if ( $brotli || $compression ) {
@@ -740,24 +771,23 @@ private function rules_cache_generate_apache( $config ) {
 	}
 
 	/**
-	 * Generates directives for file cache dir
+	 * Generates NGINX cache rules for minification.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @param object $config Configuration object containing relevant settings.
+	 *
+	 * @return string Generated NGINX cache rules.
 	 */
 	private function rules_cache_generate_nginx( $config ) {
-		$cache_uri = Util_Environment::url_to_uri(
-			Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR ) ) . '/';
+		$cache_uri = Util_Environment::url_to_uri( Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR ) ) . '/';
 
 		$browsercache = $config->get_boolean( 'browsercache.enabled' );
-		$brotli = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.brotli' ) );
-		$gzip = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.compression' ) );
+		$brotli       = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.brotli' ) );
+		$gzip         = ( $browsercache && $config->get_boolean( 'browsercache.cssjs.compression' ) );
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_MINIFY_CACHE . "\n";
 
-		$common_rules_a = Dispatcher::nginx_rules_for_browsercache_section(
-			$config, 'cssjs', true );
+		$common_rules_a   = Dispatcher::nginx_rules_for_browsercache_section( $config, 'cssjs', true );
 		$common_rules_a[] = 'add_header Vary "Accept-Encoding";';
 
 		$common_rules = '    ' . implode( "\n    ", $common_rules_a ) . "\n";
@@ -803,11 +833,19 @@ private function rules_cache_generate_nginx( $config ) {
 		return $rules;
 	}
 
+	/**
+	 * Modifies or generates LiteSpeed browser cache rules for a specific section.
+	 *
+	 * @param string $section_rules Existing rules for the specified section.
+	 * @param object $config        Configuration object containing relevant settings.
+	 * @param string $section       Section name to modify or generate rules for.
+	 *
+	 * @return string Modified or generated rules for the specified section.
+	 */
 	public function w3tc_browsercache_rules_section( $section_rules, $config, $section ) {
 		if ( Util_Environment::is_litespeed() ) {
-			$o = new Minify_Environment_LiteSpeed( $config );
-			$section_rules = $o->w3tc_browsercache_rules_section(
-				$section_rules, $section );
+			$o             = new Minify_Environment_LiteSpeed( $config );
+			$section_rules = $o->w3tc_browsercache_rules_section( $section_rules, $section );
 		}
 		return $section_rules;
 	}
diff --git a/Minify_Environment_LiteSpeed.php b/Minify_Environment_LiteSpeed.php
index 3f2d6b0d9..4111d7d6c 100644
--- a/Minify_Environment_LiteSpeed.php
+++ b/Minify_Environment_LiteSpeed.php
@@ -1,23 +1,46 @@
 <?php
+/**
+ * File: Minify_Environment_LiteSpeed.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
+ * Class Minify_Environment_LiteSpeed
+ *
  * Minify rules generation for LiteSpeed
  */
 class Minify_Environment_LiteSpeed {
+	/**
+	 * Config
+	 *
+	 * @var Config
+	 */
 	private $c;
 
-
-
+	/**
+	 * Constructor for the Minify_Environment_LiteSpeed class.
+	 *
+	 * @param array $config Configuration array for initializing the class.
+	 *
+	 * @return void
+	 */
 	public function __construct( $config ) {
 		$this->c = $config;
 	}
 
-
-
-	// force rewrites to work in order to get minify a chance to generate content
+	/**
+	 * Modifies the browser cache rules based on the section.
+	 *
+	 * @param array  $section_rules Array of the current cache rules for the section.
+	 * @param string $section       The section type (e.g., 'cssjs').
+	 *
+	 * @return array Modified array of the section rules.
+	 */
 	public function w3tc_browsercache_rules_section( $section_rules, $section ) {
-		if ( $section == 'cssjs' ) {
+		if ( 'cssjs' === $section ) {
 			$section_rules['rewrite'] = true;
 		}
 
diff --git a/Minify_Extract.php b/Minify_Extract.php
index 8d9cf80a2..314137ce6 100644
--- a/Minify_Extract.php
+++ b/Minify_Extract.php
@@ -1,25 +1,38 @@
 <?php
+/**
+ * File: Minify_Extract.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Minify_Extract
+ */
 class Minify_Extract {
 	/**
-	 * Extracts JS files from content
+	 * Extracts JavaScript file URLs from the given HTML content.
+	 *
+	 * Removes HTML comments from the content and identifies all JavaScript file URLs
+	 * by analyzing `<script>` tags with a `src` attribute.
+	 *
 	 * w3tc-url-escaping: When rendered, URLs need to be escaped via
 	 * htmlspecialchars instead of esc_attr to not change the way it is encoded
 	 * in source html. E.g. html contains a&amp;b Using esc_attr that will not
 	 * double escape it as a result config value will be a&b.
 	 *
-	 * @param string  $content
-	 * @return array
+	 * @param string $content The HTML content to analyze for JavaScript file URLs.
+	 *
+	 * @return array An array of unique JavaScript file URLs extracted from the content.
 	 */
-	static public function extract_js( $content ) {
+	public static function extract_js( $content ) {
 		$matches = null;
-		$files = array();
+		$files   = array();
 
 		$content = preg_replace( '~<!--.*?-->~s', '', $content );
 
-		if ( preg_match_all( '~<script\s+[^<>]*src=["\']?([^"\']+)["\']?[^<>]*>\s*</script>~is',
-				$content, $matches ) ) {
+		if ( preg_match_all( '~<script\s+[^<>]*src=["\']?([^"\']+)["\']?[^<>]*>\s*</script>~is', $content, $matches ) ) {
 			$files = $matches[1];
 		}
 
@@ -29,42 +42,50 @@ static public function extract_js( $content ) {
 	}
 
 	/**
-	 * Extract CSS files from content
+	 * Extracts CSS file URLs and associated tag information from the given HTML content.
+	 *
+	 * Removes HTML comments and identifies all CSS file URLs by analyzing `<link>` tags
+	 * with a `rel` attribute containing 'stylesheet' and avoiding those with 'print' media.
+	 * Also includes CSS files from `@import` statements in the content.
 	 *
-	 * @param string  $content
-	 * @return array
+	 * @param string $content The HTML content to analyze for CSS file URLs and tags.
+	 *
+	 * @return array An array of arrays where each sub-array contains the matched tag and the CSS file URL.
 	 */
-	static public function extract_css( $content ) {
+	public static function extract_css( $content ) {
 		$content = preg_replace( '~<!--.*?-->~s', '', $content );
 
 		$tags_files = array();
 
 		$matches = null;
-		if ( preg_match_all( '~<link\s+([^>]+)/?>(.*</link>)?~Uis', $content,
-				$matches, PREG_SET_ORDER ) ) {
+		if ( preg_match_all( '~<link\s+([^>]+)/?>(.*</link>)?~Uis', $content, $matches, PREG_SET_ORDER ) ) {
 			foreach ( $matches as $match ) {
-				$attrs = array();
+				$attrs        = array();
 				$attr_matches = null;
-				if ( preg_match_all( '~(\w+)=["\']([^"\']*)["\']~', $match[1],
-						$attr_matches, PREG_SET_ORDER ) ) {
+				if ( preg_match_all( '~(\w+)=["\']([^"\']*)["\']~', $match[1], $attr_matches, PREG_SET_ORDER ) ) {
 					foreach ( $attr_matches as $attr_match ) {
-						$attrs[$attr_match[1]] = trim( $attr_match[2] );
+						$attrs[ $attr_match[1] ] = trim( $attr_match[2] );
 					}
 				}
 
-				if ( isset( $attrs['href'] ) && isset( $attrs['rel'] ) &&
+				if (
+					isset( $attrs['href'] ) &&
+					isset( $attrs['rel'] ) &&
 					stristr( $attrs['rel'], 'stylesheet' ) !== false &&
-					( !isset( $attrs['media'] ) || stristr( $attrs['media'], 'print' ) === false ) ) {
+					(
+						! isset( $attrs['media'] ) ||
+						stristr( $attrs['media'], 'print' ) === false
+					)
+				) {
 					$tags_files[] = array( $match[0], $attrs['href'] );
 				}
 			}
-
 		}
 
-		if ( preg_match_all( '~@import\s+(url\s*)?\(?["\']?\s*([^"\'\)\s]+)\s*["\']?\)?[^;]*;?~is',
-				$content, $matches, PREG_SET_ORDER ) ) {
-			foreach ( $matches as $match )
+		if ( preg_match_all( '~@import\s+(url\s*)?\(?["\']?\s*([^"\'\)\s]+)\s*["\']?\)?[^;]*;?~is', $content, $matches, PREG_SET_ORDER ) ) {
+			foreach ( $matches as $match ) {
 				$tags_files[] = array( $match[0], $match[2] );
+			}
 		}
 
 		return $tags_files;
diff --git a/Minify_HelpPopup_View.php b/Minify_HelpPopup_View.php
index 7764a89dc..5bd05142e 100644
--- a/Minify_HelpPopup_View.php
+++ b/Minify_HelpPopup_View.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: Minify_HelpPopup_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/Minify_MinifiedFileRequestHandler.php b/Minify_MinifiedFileRequestHandler.php
index db301a1c4..504651402 100644
--- a/Minify_MinifiedFileRequestHandler.php
+++ b/Minify_MinifiedFileRequestHandler.php
@@ -1,111 +1,139 @@
 <?php
+/**
+ * File: Minify_MinifiedFileRequestHandler.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
-// Define repeated regex to simplify changes
+// Define repeated regex to simplify changes.
 define( 'MINIFY_AUTO_FILENAME_REGEX', '([a-zA-Z0-9-_]+)\\.(css|js)([?].*)?' );
 define( 'MINIFY_MANUAL_FILENAME_REGEX', '([a-f0-9]+)\\.(.+)\\.(include(\\-(footer|body))?)\\.[a-f0-9]+\\.(css|js)' );
+
 /**
- * class Minify_MinifiedFileRequestHandler
+ * Class Minify_MinifiedFileRequestHandler
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.PHP.DiscouragedPHPFunctions
+ * phpcs:disable WordPress.WP.AlternativeFunctions
+ * phpcs:disable WordPress.DB.DirectDatabaseQuery
+ * phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
  */
 class Minify_MinifiedFileRequestHandler {
 	/**
 	 * Config
+	 *
+	 * @var Config
 	 */
-	var $_config = null;
+	public $_config = null;
 
 	/**
 	 * Tracks if an error has occurred.
 	 *
 	 * @var bool
 	 */
-	var $_error_occurred = false;
+	public $_error_occurred = false;
 
 	/**
-	 * PHP5 constructor
+	 * Constructor for the Minify_MinifiedFileRequestHandler class.
+	 *
+	 * Initializes the configuration object.
+	 *
+	 * @return void
 	 */
-	function __construct() {
+	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs minify
+	 * Processes the given file request and serves minified content.
 	 *
-	 * @param string|null $file
+	 * @param string|null $file  The requested file for minification. Defaults to null.
+	 * @param bool        $quiet Whether to suppress errors and output debugging information.
 	 *
-	 * @return void
+	 * @return array|void An array of minification results, or void in certain cases.
+	 *
+	 * @throws \Exception If a recoverable error occurs during the minification process.
 	 */
-	function process( $file = NULL, $quiet = false ) {
-		/**
-		 * Check for rewrite test request
-		 */
+	public function process( $file = null, $quiet = false ) {
+		// Check for rewrite test request.
 		$rewrite_marker = 'rewrite_test.css';
-		if ( substr( $file, strlen( $file ) - strlen( $rewrite_marker ) ) ==
-			$rewrite_marker ) {
+		if ( substr( $file, strlen( $file ) - strlen( $rewrite_marker ) ) === $rewrite_marker ) {
 			echo 'Minify OK';
 			exit();
 		}
 
 		$filelength_test_marker = 'XXX.css';
-		if ( substr( $file, strlen( $file ) - strlen( $filelength_test_marker ) ) ==
-			$filelength_test_marker ) {
+		if ( substr( $file, strlen( $file ) - strlen( $filelength_test_marker ) ) === $filelength_test_marker ) {
 			$cache = $this->_get_cache();
 			header( 'Content-type: text/css' );
 
 			if ( ! $cache->store( basename( $file ), array( 'content' => 'content ok' ) ) ) {
 				echo 'error storing';
 			} else {
-				if ( ( function_exists( 'brotli_compress' ) &&
-					   $this->_config->get_boolean( 'browsercache.enabled' ) &&
-					   $this->_config->get_boolean( 'browsercache.cssjs.brotli' ) ) )
-					if ( !$cache->store( basename( $file ) . '_br',
-						array( 'content' => brotli_compress( 'content ok' ) ) ) ) {
+				if (
+					function_exists( 'brotli_compress' ) &&
+					$this->_config->get_boolean( 'browsercache.enabled' ) &&
+					$this->_config->get_boolean( 'browsercache.cssjs.brotli' )
+				) {
+					if ( ! $cache->store( basename( $file ) . '_br', array( 'content' => brotli_compress( 'content ok' ) ) ) ) {
 						echo 'error storing';
 						exit();
 					}
+				}
 
-				if ( ( function_exists( 'gzencode' ) &&
-						$this->_config->get_boolean( 'browsercache.enabled' ) &&
-						$this->_config->get_boolean( 'browsercache.cssjs.compression' ) ) )
-					if ( !$cache->store( basename( $file ) . '_gzip',
-							array( 'content' => gzencode( 'content ok' ) ) ) ) {
+				if (
+					function_exists( 'gzencode' ) &&
+					$this->_config->get_boolean( 'browsercache.enabled' ) &&
+					$this->_config->get_boolean( 'browsercache.cssjs.compression' )
+				) {
+					if ( ! $cache->store( basename( $file ) . '_gzip', array( 'content' => gzencode( 'content ok' ) ) ) ) {
 						echo 'error storing';
 						exit();
 					}
+				}
 
 				$v = $cache->fetch( basename( $file ) );
-				if ( $v['content'] == 'content ok' )
+				if ( 'content ok' === $v['content'] ) {
 					echo 'content ok';
-				else
+				} else {
 					echo 'error storing';
+				}
 			}
 
 			exit();
 		}
 
-		// remove querystring
-		if ( preg_match( '~(.+)(\?x[0-9]{5})$~', $file, $m ) )
+		// remove querystring.
+		if ( preg_match( '~(.+)(\?x[0-9]{5})$~', $file, $m ) ) {
 			$file = $m[1];
+		}
 
-		// remove blog_id
+		// remove blog_id.
 		$levels = '';
 		if ( defined( 'W3TC_BLOG_LEVELS' ) ) {
-			for ( $n = 0; $n < W3TC_BLOG_LEVELS; $n++ )
+			for ( $n = 0; $n < W3TC_BLOG_LEVELS; $n++ ) {
 				$levels .= '[0-9]+\/';
+			}
 		}
 
-		if ( preg_match( '~^(' . $levels . '[0-9]+)\/(.+)$~', $file, $matches ) )
+		if ( preg_match( '~^(' . $levels . '[0-9]+)\/(.+)$~', $file, $matches ) ) {
 			$file = $matches[2];
+		}
 
-		// normalize according to browsercache
+		// normalize according to browsercache.
 		$file = Dispatcher::requested_minify_filename( $this->_config, $file );
 
-		// parse file
-		$hash = '';
-		$matches = null;
+		// parse file.
+		$hash     = '';
+		$matches  = null;
 		$location = '';
-		$type = '';
+		$type     = '';
 
-		if ( preg_match( '~^' . MINIFY_AUTO_FILENAME_REGEX .'$~', $file, $matches ) ) {
+		if ( preg_match( '~^' . MINIFY_AUTO_FILENAME_REGEX . '$~', $file, $matches ) ) {
 			list( , $hash, $type ) = $matches;
 		} elseif ( preg_match( '~^' . MINIFY_MANUAL_FILENAME_REGEX . '$~', $file, $matches ) ) {
 			list( , $theme, $template, $location, , , $type ) = $matches;
@@ -113,112 +141,104 @@ function process( $file = NULL, $quiet = false ) {
 			return $this->finish_with_error( sprintf( 'Bad file param format: "%s"', $file ), $quiet, false );
 		}
 
-		/**
-		 * Set cache engine
-		 */
+		// Set cache engine.
 		$cache = $this->_get_cache();
 		\W3TCL\Minify\Minify::setCache( $cache );
 
-		/**
-		 * Set cache ID
-		 */
+		// Set cache ID.
 		$cache_id = $this->get_cache_id( $file );
 		\W3TCL\Minify\Minify::setCacheId( $file );
 
-		/**
-		 * Set logger
-		 */
-		\W3TCL\Minify\Minify_Logger::setLogger( array(
+		// Set logger.
+		\W3TCL\Minify\Minify_Logger::setLogger(
+			array(
 				$this,
-				'debug_error' ) );
+				'debug_error',
+			)
+		);
 
-		/**
-		 * Set options
-		 */
+		// Set options.
 		$browsercache = $this->_config->get_boolean( 'browsercache.enabled' );
 
-		$serve_options = array_merge( $this->_config->get_array( 'minify.options' ), array(
-				'debug' => $this->_config->get_boolean( 'minify.debug' ),
-				'maxAge' => $this->_config->get_integer( 'browsercache.cssjs.lifetime' ),
-				'encodeOutput' => ( $browsercache &&
-					!defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) &&
-					!$quiet &&
-					( $this->_config->get_boolean( 'browsercache.cssjs.compression' ) ||
-					$this->_config->get_boolean( 'browsercache.cssjs.brotli' ) ) ),
-				'bubbleCssImports' => ( $this->_config->get_string( 'minify.css.imports' ) == 'bubble' ),
-				'processCssImports' => ( $this->_config->get_string( 'minify.css.imports' ) == 'process' ),
-				'cacheHeaders' => array(
-					'use_etag' => ( $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.etag' ) ),
-					'expires_enabled' => ( $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.expires' ) ),
+		$serve_options = array_merge(
+			$this->_config->get_array( 'minify.options' ),
+			array(
+				'debug'             => $this->_config->get_boolean( 'minify.debug' ),
+				'maxAge'            => $this->_config->get_integer( 'browsercache.cssjs.lifetime' ),
+				'encodeOutput'      => (
+					$browsercache &&
+					! defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) &&
+					! $quiet &&
+					(
+						$this->_config->get_boolean( 'browsercache.cssjs.compression' ) ||
+						$this->_config->get_boolean( 'browsercache.cssjs.brotli' )
+					)
+				),
+				'bubbleCssImports'  => ( $this->_config->get_string( 'minify.css.imports' ) === 'bubble' ),
+				'processCssImports' => ( $this->_config->get_string( 'minify.css.imports' ) === 'process' ),
+				'cacheHeaders'      => array(
+					'use_etag'             => ( $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.etag' ) ),
+					'expires_enabled'      => ( $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.expires' ) ),
 					'cacheheaders_enabled' => ( $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.cache.control' ) ),
-					'cacheheaders' => $this->_config->get_string( 'browsercache.cssjs.cache.policy' )
+					'cacheheaders'         => $this->_config->get_string( 'browsercache.cssjs.cache.policy' ),
 				),
-				'disable_304' => $quiet,   // when requested for service needs - need content instead of 304
-				'quiet' => $quiet
-			) );
+				'disable_304'       => $quiet,   // when requested for service needs - need content instead of 304.
+				'quiet'             => $quiet,
+			)
+		);
 
-		/**
-		 * Set sources
-		 */
+		// Set sources.
 		if ( $hash ) {
 			$_GET['f_array'] = $this->minify_filename_to_filenames_for_minification( $hash, $type );
-			$_GET['ext'] = $type;
+			$_GET['ext']     = $type;
 		} else {
-			$_GET['g'] = $location;
+			$_GET['g']                         = $location;
 			$serve_options['minApp']['groups'] = $this->get_groups( $theme, $template, $type );
 		}
 
-		/**
-		 * Set minifier
-		 */
+		// Set minifier.
 		$w3_minifier = Dispatcher::component( 'Minify_ContentMinifier' );
 
-		if ( $type == 'js' ) {
+		if ( 'js' === $type ) {
 			$minifier_type = 'application/x-javascript';
 
 			switch ( true ) {
-			case ( $hash && $this->_config->get_string( 'minify.js.method' ) == 'combine' ):
-			case ( $location == 'include' && $this->_config->get_boolean( 'minify.js.combine.header' ) ):
-			case ( $location == 'include-body' && $this->_config->get_boolean( 'minify.js.combine.body' ) ):
-			case ( $location == 'include-footer' && $this->_config->get_boolean( 'minify.js.combine.footer' ) ):
-				$engine = 'combinejs';
-				break;
-
-			default:
-				$engine = $this->_config->get_string( 'minify.js.engine' );
+				case ( 'combine' === $hash && $this->_config->get_string( 'minify.js.method' ) ):
+				case ( 'include' === $location && $this->_config->get_boolean( 'minify.js.combine.header' ) ):
+				case ( 'include-body' === $location && $this->_config->get_boolean( 'minify.js.combine.body' ) ):
+				case ( 'include-footer' === $location && $this->_config->get_boolean( 'minify.js.combine.footer' ) ):
+					$engine = 'combinejs';
+					break;
+
+				default:
+					$engine = $this->_config->get_string( 'minify.js.engine' );
+					if ( ! $w3_minifier->exists( $engine ) || ! $w3_minifier->available( $engine ) ) {
+						$engine = 'js';
+					}
 
-				if ( !$w3_minifier->exists( $engine ) || !$w3_minifier->available( $engine ) ) {
-					$engine = 'js';
-				}
-				break;
+					break;
 			}
-
-		} elseif ( $type == 'css' ) {
+		} elseif ( 'css' === $type ) {
 			$minifier_type = 'text/css';
 
-			if ( ( $hash || $location == 'include' ) && $this->_config->get_string( 'minify.css.method' ) == 'combine' ) {
+			if ( ( $hash || 'include' === $location ) && 'combine' === $this->_config->get_string( 'minify.css.method' ) ) {
 				$engine = 'combinecss';
 			} else {
 				$engine = $this->_config->get_string( 'minify.css.engine' );
-
-				if ( !$w3_minifier->exists( $engine ) || !$w3_minifier->available( $engine ) ) {
+				if ( ! $w3_minifier->exists( $engine ) || ! $w3_minifier->available( $engine ) ) {
 					$engine = 'css';
 				}
 			}
 		}
 
-		/**
-		 * Initialize minifier
-		 */
+		// Initialize minifier.
 		$w3_minifier->init( $engine );
 
-		$serve_options['minifiers'][$minifier_type] = $w3_minifier->get_minifier( $engine );
-		$serve_options['minifierOptions'][$minifier_type] = $w3_minifier->get_options( $engine );
+		$serve_options['minifiers'][ $minifier_type ]       = $w3_minifier->get_minifier( $engine );
+		$serve_options['minifierOptions'][ $minifier_type ] = $w3_minifier->get_options( $engine );
 
-		/**
-		 * Send X-Powered-By header
-		 */
-		if ( !$quiet && $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.w3tc' ) ) {
+		// Send X-Powered-By header.
+		if ( ! $quiet && $browsercache && $this->_config->get_boolean( 'browsercache.cssjs.w3tc' ) ) {
 			@header( 'X-Powered-By: ' . Util_Environment::w3tc_header() );
 		}
 
@@ -226,10 +246,8 @@ function process( $file = NULL, $quiet = false ) {
 			return $this->finish_with_error( 'Nothing to minify', $quiet, false );
 		}
 
-		// Minify
-		$serve_options = apply_filters(
-			'w3tc_minify_file_handler_minify_options',
-			$serve_options );
+		// Minify.
+		$serve_options = apply_filters( 'w3tc_minify_file_handler_minify_options', $serve_options );
 
 		$return = array();
 		try {
@@ -238,13 +256,14 @@ function process( $file = NULL, $quiet = false ) {
 			return $this->finish_with_error( $exception->getMessage(), $quiet );
 		}
 
-		if ( !is_null( \W3TCL\Minify\Minify::$recoverableError ) )
+		if ( ! is_null( \W3TCL\Minify\Minify::$recoverableError ) ) {
 			$this->_handle_error( \W3TCL\Minify\Minify::$recoverableError );
+		}
 
 		$state = Dispatcher::config_state_master();
-		if ( !$this->_error_occurred && $state->get_boolean( 'minify.show_note_minify_error' ) ) {
+		if ( ! $this->_error_occurred && $state->get_boolean( 'minify.show_note_minify_error' ) ) {
 			$error_file = $state->get_string( 'minify.error.file' );
-			if ( $error_file == $file ) {
+			if ( $error_file === $file ) {
 				$state->set( 'minify.show_note_minify_error', false );
 				$state->save();
 			}
@@ -253,45 +272,51 @@ function process( $file = NULL, $quiet = false ) {
 		return $return;
 	}
 
-
-
+	/**
+	 * Records usage statistics for the current minify request.
+	 *
+	 * @param object $storage The storage object for recording statistics.
+	 *
+	 * @return void
+	 */
 	public function w3tc_usage_statistics_of_request( $storage ) {
 		$stats = \W3TCL\Minify\Minify::getUsageStatistics();
 		if ( count( $stats ) > 0 ) {
 			$storage->counter_add( 'minify_requests_total', 1 );
-			if ( $stats['content_type'] == 'text/css' ) {
-				$storage->counter_add( 'minify_original_length_css',
-					(int)( $stats['content_original_length'] / 102.4 ) );
-				$storage->counter_add( 'minify_output_length_css',
-					(int)( $stats['content_output_length'] / 102.4 ) );
+			if ( 'text/css' === $stats['content_type'] ) {
+				$storage->counter_add( 'minify_original_length_css', (int) ( $stats['content_original_length'] / 102.4 ) );
+				$storage->counter_add( 'minify_output_length_css', (int) ( $stats['content_output_length'] / 102.4 ) );
 			} else {
-				$storage->counter_add( 'minify_original_length_js',
-					(int)( $stats['content_original_length'] / 102.4 ) );
-				$storage->counter_add( 'minify_output_length_js',
-					(int)( $stats['content_output_length'] / 102.4 ) );
+				$storage->counter_add( 'minify_original_length_js', (int) ( $stats['content_original_length'] / 102.4 ) );
+				$storage->counter_add( 'minify_output_length_js', (int) ( $stats['content_output_length'] / 102.4 ) );
 			}
 		}
 	}
 
-
-
 	/**
-	 * Returns size statistics about cache files
+	 * Retrieves the size statistics of the cache.
+	 *
+	 * @param int $timeout_time The timeout duration for the statistics retrieval operation.
+	 *
+	 * @return array An array containing the size statistics of the cache.
 	 */
 	public function get_stats_size( $timeout_time ) {
 		$cache = $this->_get_cache();
-		if ( method_exists( $cache, 'get_stats_size' ) )
+		if ( method_exists( $cache, 'get_stats_size' ) ) {
 			return $cache->get_stats_size( $timeout_time );
+		}
 
 		return array();
 	}
 
-
-
 	/**
-	 * Flushes cache.
+	 * Flushes the cache and optionally handles UI-specific actions.
 	 *
-	 * @return bool
+	 * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
+	 *
+	 * @param array $extras Optional associative array of extra parameters for the flush operation.
+	 *
+	 * @return bool True if the cache flush was successful, false otherwise.
 	 */
 	public function flush( $extras = array() ) {
 		$cache = $this->_get_cache();
@@ -314,13 +339,14 @@ public function flush( $extras = array() ) {
 	}
 
 	/**
-	 * Returns custom data storage for minify file, based on url
+	 * Retrieves custom data associated with a specific URL.
+	 *
+	 * @param string $url The URL for which custom data is being retrieved.
 	 *
-	 * @param string  $url
-	 * @return mixed
+	 * @return mixed|null Custom data associated with the URL, or null if none exists.
 	 */
-	function get_url_custom_data( $url ) {
-		if ( preg_match( '~/' . MINIFY_AUTO_FILENAME_REGEX .'$~', $url, $matches ) ) {
+	public function get_url_custom_data( $url ) {
+		if ( preg_match( '~/' . MINIFY_AUTO_FILENAME_REGEX . '$~', $url, $matches ) ) {
 			list( , $hash, $type ) = $matches;
 
 			$key = $this->get_custom_data_key( $hash, $type );
@@ -331,13 +357,15 @@ function get_url_custom_data( $url ) {
 	}
 
 	/**
-	 * Returns custom data storage for minify file
+	 * Associates custom data with a specified file.
 	 *
-	 * @param string  $file
-	 * @param mixed   $data
+	 * @param string $file The file to associate the custom data with.
+	 * @param mixed  $data The custom data to store.
+	 *
+	 * @return void
 	 */
-	function set_file_custom_data( $file, $data ) {
-		if ( preg_match( '~' . MINIFY_AUTO_FILENAME_REGEX .'$~', $file, $matches ) ) {
+	public function set_file_custom_data( $file, $data ) {
+		if ( preg_match( '~' . MINIFY_AUTO_FILENAME_REGEX . '$~', $file, $matches ) ) {
 			list( , $hash, $type ) = $matches;
 
 			$key = $this->get_custom_data_key( $hash, $type );
@@ -346,54 +374,55 @@ function set_file_custom_data( $file, $data ) {
 	}
 
 	/**
-	 * Returns minify groups
+	 * Retrieves the groups of minification sources for a given theme, template, and type.
 	 *
-	 * @param string  $theme
-	 * @param string  $template
-	 * @param string  $type
-	 * @return array
+	 * @param string $theme    The theme for which groups are retrieved.
+	 * @param string $template The template for which groups are retrieved.
+	 * @param string $type     The type of content (e.g., 'css', 'js').
+	 *
+	 * @return array An array of groups for the specified parameters.
 	 */
-	function get_groups( $theme, $template, $type ) {
+	public function get_groups( $theme, $template, $type ) {
 		$result = array();
 
 		switch ( $type ) {
-		case 'css':
-			$groups = $this->_config->get_array( 'minify.css.groups' );
-			break;
+			case 'css':
+				$groups = $this->_config->get_array( 'minify.css.groups' );
+				break;
 
-		case 'js':
-			$groups = $this->_config->get_array( 'minify.js.groups' );
-			break;
+			case 'js':
+				$groups = $this->_config->get_array( 'minify.js.groups' );
+				break;
 
-		default:
-			return $result;
+			default:
+				return $result;
 		}
 
-		if ( isset( $groups[$theme]['default'] ) ) {
-			$locations = (array) $groups[$theme]['default'];
+		if ( isset( $groups[ $theme ]['default'] ) ) {
+			$locations = (array) $groups[ $theme ]['default'];
 		} else {
 			$locations = array();
 		}
 
-		if ( $template != 'default' && isset( $groups[$theme][$template] ) ) {
-			$locations = array_merge_recursive( $locations, (array) $groups[$theme][$template] );
+		if ( 'default' !== $template && isset( $groups[ $theme ][ $template ] ) ) {
+			$locations = array_merge_recursive( $locations, (array) $groups[ $theme ][ $template ] );
 		}
 
 		foreach ( $locations as $location => $config ) {
-			if ( !empty( $config['files'] ) ) {
+			if ( ! empty( $config['files'] ) ) {
 				foreach ( (array) $config['files'] as $url ) {
-					if ( !Util_Environment::is_url( $url ) )
-						$url = Util_Environment::home_domain_root_url() . '/' .
-							ltrim( $url, '/' );
+					if ( ! Util_Environment::is_url( $url ) ) {
+						$url = Util_Environment::home_domain_root_url() . '/' . ltrim( $url, '/' );
+					}
 
 					$file = Util_Environment::url_to_docroot_filename( $url );
 
 					if ( is_null( $file ) ) {
-						// it's external url
+						// it's external url.
 						$precached_file = $this->_precache_file( $url, $type );
 
 						if ( $precached_file ) {
-							$result[$location][$url] = $precached_file;
+							$result[ $location ][ $url ] = $precached_file;
 						} else {
 							Minify_Core::debug_error( sprintf( 'Unable to cache remote url: "%s"', $url ) );
 						}
@@ -401,7 +430,7 @@ function get_groups( $theme, $template, $type ) {
 						$path = Util_Environment::document_root() . '/' . $file;
 
 						if ( file_exists( $path ) ) {
-							$result[$location][$file] = '//' . $file;
+							$result[ $location ][ $file ] = '//' . $file;
 						} else {
 							Minify_Core::debug_error( sprintf( 'File "%s" doesn\'t exist', $path ) );
 						}
@@ -414,30 +443,32 @@ function get_groups( $theme, $template, $type ) {
 	}
 
 	/**
-	 * Returns minify cache ID
+	 * Retrieves the cache ID for the specified file.
+	 *
+	 * @param string $file The file for which the cache ID is retrieved.
 	 *
-	 * @param string  $file
-	 * @return string
+	 * @return string The cache ID for the file.
 	 */
-	function get_cache_id( $file ) {
+	public function get_cache_id( $file ) {
 		return $file;
 	}
 
 	/**
-	 * Returns array of group sources
+	 * Retrieves sources for a specific group within a theme, template, and location.
 	 *
-	 * @param string  $theme
-	 * @param string  $template
-	 * @param string  $location
-	 * @param string  $type
-	 * @return array
+	 * @param string $theme    The theme name.
+	 * @param string $template The template name.
+	 * @param string $location The location name within the group.
+	 * @param string $type     The content type (e.g., 'css', 'js').
+	 *
+	 * @return array An array of source file paths.
 	 */
-	function get_sources_group( $theme, $template, $location, $type ) {
+	public function get_sources_group( $theme, $template, $location, $type ) {
 		$sources = array();
-		$groups = $this->get_groups( $theme, $template, $type );
+		$groups  = $this->get_groups( $theme, $template, $type );
 
-		if ( isset( $groups[$location] ) ) {
-			$files = (array) $groups[$location];
+		if ( isset( $groups[ $location ] ) ) {
+			$files = (array) $groups[ $location ];
 
 			$document_root = Util_Environment::document_root();
 
@@ -456,32 +487,34 @@ function get_sources_group( $theme, $template, $location, $type ) {
 	}
 
 	/**
-	 * Returns ID key for group
+	 * Retrieves the ID key for a specific group.
+	 *
+	 * @param string $theme    The theme name.
+	 * @param string $template The template name.
+	 * @param string $location The location name within the group.
+	 * @param string $type     The content type (e.g., 'css', 'js').
 	 *
-	 * @param unknown $theme
-	 * @param unknown $template
-	 * @param unknown $location
-	 * @param unknown $type
-	 * @return string
+	 * @return string The ID key for the specified group.
 	 */
-	function get_id_key_group( $theme, $template, $location, $type ) {
+	public function get_id_key_group( $theme, $template, $location, $type ) {
 		return sprintf( '%s/%s.%s.%s.id', $theme, $template, $location, $type );
 	}
 
 	/**
-	 * Returns id for group
+	 * Retrieves the group ID for a given theme, template, location, and type.
 	 *
-	 * @param string  $theme
-	 * @param string  $template
-	 * @param string  $location
-	 * @param string  $type
-	 * @return integer
+	 * @param string $theme    The theme identifier.
+	 * @param string $template The template identifier.
+	 * @param string $location The location identifier.
+	 * @param string $type     The type identifier.
+	 *
+	 * @return string|null The group ID or null if not found.
 	 */
-	function get_id_group( $theme, $template, $location, $type ) {
+	public function get_id_group( $theme, $template, $location, $type ) {
 		$key = $this->get_id_key_group( $theme, $template, $location, $type );
-		$id = $this->_cache_get( $key );
+		$id  = $this->_cache_get( $key );
 
-		if ( $id === false ) {
+		if ( false === $id ) {
 			$sources = $this->get_sources_group( $theme, $template, $location, $type );
 
 			if ( count( $sources ) ) {
@@ -497,28 +530,31 @@ function get_id_group( $theme, $template, $location, $type ) {
 	}
 
 	/**
-	 * Returns custom files key
+	 * Generates a custom data key based on a hash and type.
+	 *
+	 * @param string $hash The hash value.
+	 * @param string $type The type of data.
 	 *
-	 * @param string  $hash
-	 * @param string  $type
-	 * @return string
+	 * @return string The custom data key.
 	 */
-	function get_custom_data_key( $hash, $type ) {
+	public function get_custom_data_key( $hash, $type ) {
 		return sprintf( '%s.%s.customdata', $hash, $type );
 	}
 
 	/**
-	 * Returns custom files
+	 * Converts a minified filename to an array of filenames for minification.
 	 *
-	 * @param string  $hash
-	 * @param string  $type
-	 * @return array
+	 * @param string $hash The hash representing the filename.
+	 * @param string $type The type of the minified content (e.g., CSS or JS).
+	 *
+	 * @return array An array of filenames for minification.
+	 *
+	 * @throws \Exception If the conversion process encounters an error.
 	 */
-	function minify_filename_to_filenames_for_minification( $hash, $type ) {
-		// if bad data passed as get parameter - it shouldn't fire internal errors
+	public function minify_filename_to_filenames_for_minification( $hash, $type ) {
+		// if bad data passed as get parameter - it shouldn't fire internal errors.
 		try {
-			$files = Minify_Core::minify_filename_to_urls_for_minification(
-				$hash, $type );
+			$files = Minify_Core::minify_filename_to_urls_for_minification( $hash, $type );
 		} catch ( \Exception $e ) {
 			$files = array();
 		}
@@ -529,7 +565,7 @@ function minify_filename_to_filenames_for_minification( $hash, $type ) {
 				$docroot_filename = Util_Environment::url_to_docroot_filename( $file );
 
 				if ( Util_Environment::is_url( $file ) && is_null( $docroot_filename ) ) {
-					// it's external url
+					// it's external url.
 					$precached_file = $this->_precache_file( $file, $type );
 
 					if ( $precached_file ) {
@@ -559,14 +595,15 @@ function minify_filename_to_filenames_for_minification( $hash, $type ) {
 	}
 
 	/**
-	 * Sends error response
+	 * Handles errors and prepares an error response.
 	 *
-	 * @param string  $error
-	 * @param boolean $handle
-	 * @param integer $status
-	 * @return void
+	 * @param string $error               The error message.
+	 * @param bool   $quiet               Whether to suppress output.
+	 * @param bool   $report_about_error  Whether to report the error.
+	 *
+	 * @return array|void
 	 */
-	function finish_with_error( $error, $quiet = false, $report_about_error = true ) {
+	public function finish_with_error( $error, $quiet = false, $report_about_error = true ) {
 		$this->_error_occurred = true;
 
 		Minify_Core::debug_error( $error );
@@ -585,7 +622,7 @@ function finish_with_error( $error, $quiet = false, $report_about_error = true )
 
 		if ( $quiet ) {
 			return array(
-				'content' => $message
+				'content' => $message,
 			);
 		}
 
@@ -596,166 +633,187 @@ function finish_with_error( $error, $quiet = false, $report_about_error = true )
 		}
 	}
 
-
-
+	/**
+	 * Logs a debug error message.
+	 *
+	 * @param string $error The error message to log.
+	 *
+	 * @return void
+	 */
 	public function debug_error( $error ) {
 		Minify_Core::debug_error( $error );
 	}
 
 	/**
-	 * Pre-caches external file
+	 * Pre-caches a file from a URL for minification.
+	 *
+	 * @param string $url  The URL of the file.
+	 * @param string $type The type of the file (e.g., CSS or JS).
 	 *
-	 * @param string  $url
-	 * @param string  $type
-	 * @return string
+	 * @return mixed The minified source or false if caching fails.
 	 */
-	function _precache_file( $url, $type ) {
-		$lifetime = $this->_config->get_integer( 'minify.lifetime' );
+	public function _precache_file( $url, $type ) {
+		$lifetime   = $this->_config->get_integer( 'minify.lifetime' );
 		$cache_path = sprintf( '%s/minify_%s.%s', Util_Environment::cache_blog_dir( 'minify' ), md5( $url ), $type );
 
-		if ( !file_exists( $cache_path ) || @filemtime( $cache_path ) < ( time() - $lifetime ) ) {
-			if ( !@is_dir( dirname( $cache_path ) ) ) {
+		if ( ! file_exists( $cache_path ) || @filemtime( $cache_path ) < ( time() - $lifetime ) ) {
+			if ( ! @is_dir( dirname( $cache_path ) ) ) {
 				Util_File::mkdir_from_safe( dirname( $cache_path ), W3TC_CACHE_DIR );
 			}
 
-			// google-fonts (most used for external inclusion)
-			// doesnt return full content (unicode-range) for simple useragents
-			Util_Http::download( $url, $cache_path,
-				array( 'user-agent' =>
-					'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92' ) );
+			// google-fonts (most used for external inclusion) doesnt return full content (unicode-range) for simple useragents.
+			Util_Http::download(
+				$url,
+				$cache_path,
+				array(
+					'user-agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92',
+				)
+			);
 		}
 
 		return file_exists( $cache_path ) ? $this->_get_minify_source( $cache_path, $url ) : false;
 	}
 
 	/**
-	 * Returns minify source
+	 * Retrieves a minify source from a file path and URL.
 	 *
-	 * @param unknown $file_path
-	 * @param unknown $url
-	 * @return Minify_Source
+	 * @param string $file_path The file path to the cached file.
+	 * @param string $url       The original URL of the file.
+	 *
+	 * @return \W3TCL\Minify\Minify_Source The minify source object.
 	 */
-	function _get_minify_source( $file_path, $url ) {
-		return new \W3TCL\Minify\Minify_Source( array(
-				'filepath' => $file_path,
+	public function _get_minify_source( $file_path, $url ) {
+		return new \W3TCL\Minify\Minify_Source(
+			array(
+				'filepath'      => $file_path,
 				'minifyOptions' => array(
-					'prependRelativePath' => $url
-				)
-			) );
+					'prependRelativePath' => $url,
+				),
+			)
+		);
 	}
 
 	/**
-	 * Returns minify cache object
+	 * Retrieves the caching mechanism used by the minification system.
 	 *
-	 * @return object
+	 * @return mixed The cache object.
 	 */
-	function _get_cache() {
+	public function _get_cache() {
 		static $cache = null;
 
 		if ( is_null( $cache ) ) {
 			$inner_cache = null;
 
 			switch ( $this->_config->get_string( 'minify.engine' ) ) {
-			case 'memcached':
-				$config = array(
-					'blog_id' => Util_Environment::blog_id(),
-					'instance_id' => Util_Environment::instance_id(),
-					'host' =>  Util_Environment::host(),
-					'module' => 'minify',
-					'servers' => $this->_config->get_array( 'minify.memcached.servers' ),
-					'persistent' => $this->_config->get_boolean( 'minify.memcached.persistent' ),
-					'aws_autodiscovery' => $this->_config->get_boolean( 'minify.memcached.aws_autodiscovery' ),
-					'username' => $this->_config->get_string( 'minify.memcached.username' ),
-					'password' => $this->_config->get_string( 'minify.memcached.password' ),
-					'binary_protocol' => $this->_config->get_boolean( 'minify.memcached.binary_protocol' )
-				);
-				if ( class_exists( 'Memcached' ) ) {
-					$inner_cache = new Cache_Memcached( $config );
-				} elseif ( class_exists( 'Memcache' ) ) {
-					$inner_cache = new Cache_Memcache( $config );
-				}
-				break;
+				case 'memcached':
+					$config = array(
+						'blog_id'           => Util_Environment::blog_id(),
+						'instance_id'       => Util_Environment::instance_id(),
+						'host'              => Util_Environment::host(),
+						'module'            => 'minify',
+						'servers'           => $this->_config->get_array( 'minify.memcached.servers' ),
+						'persistent'        => $this->_config->get_boolean( 'minify.memcached.persistent' ),
+						'aws_autodiscovery' => $this->_config->get_boolean( 'minify.memcached.aws_autodiscovery' ),
+						'username'          => $this->_config->get_string( 'minify.memcached.username' ),
+						'password'          => $this->_config->get_string( 'minify.memcached.password' ),
+						'binary_protocol'   => $this->_config->get_boolean( 'minify.memcached.binary_protocol' ),
+					);
+
+					if ( class_exists( 'Memcached' ) ) {
+						$inner_cache = new Cache_Memcached( $config );
+					} elseif ( class_exists( 'Memcache' ) ) {
+						$inner_cache = new Cache_Memcache( $config );
+					}
 
-			case 'redis':
-				$config = array(
-					'blog_id' => Util_Environment::blog_id(),
-					'instance_id' => Util_Environment::instance_id(),
-					'host' =>  Util_Environment::host(),
-					'module' => 'minify',
-					'servers' => $this->_config->get_array( 'minify.redis.servers' ),
-					'verify_tls_certificates' => $this->_config->get_boolean( 'minify.redis.verify_tls_certificates' ),
-					'persistent' => $this->_config->get_boolean( 'minify.redis.persistent' ),
-					'timeout' => $this->_config->get_integer( 'minify.redis.timeout' ),
-					'retry_interval' => $this->_config->get_integer( 'minify.redis.retry_interval' ),
-					'read_timeout' => $this->_config->get_integer( 'minify.redis.read_timeout' ),
-					'dbid' => $this->_config->get_integer( 'minify.redis.dbid' ),
-					'password' => $this->_config->get_string( 'minify.redis.password' )
-				);
-				$inner_cache = new Cache_Redis( $config );
+					break;
+
+				case 'redis':
+					$config = array(
+						'blog_id'                 => Util_Environment::blog_id(),
+						'instance_id'             => Util_Environment::instance_id(),
+						'host'                    => Util_Environment::host(),
+						'module'                  => 'minify',
+						'servers'                 => $this->_config->get_array( 'minify.redis.servers' ),
+						'verify_tls_certificates' => $this->_config->get_boolean( 'minify.redis.verify_tls_certificates' ),
+						'persistent'              => $this->_config->get_boolean( 'minify.redis.persistent' ),
+						'timeout'                 => $this->_config->get_integer( 'minify.redis.timeout' ),
+						'retry_interval'          => $this->_config->get_integer( 'minify.redis.retry_interval' ),
+						'read_timeout'            => $this->_config->get_integer( 'minify.redis.read_timeout' ),
+						'dbid'                    => $this->_config->get_integer( 'minify.redis.dbid' ),
+						'password'                => $this->_config->get_string( 'minify.redis.password' ),
+					);
+
+					$inner_cache = new Cache_Redis( $config );
+
+					break;
+
+				case 'apc':
+					$config = array(
+						'blog_id'     => Util_Environment::blog_id(),
+						'instance_id' => Util_Environment::instance_id(),
+						'host'        => Util_Environment::host(),
+						'module'      => 'minify',
+					);
+
+					if ( function_exists( 'apcu_store' ) ) {
+						$inner_cache = new Cache_Apcu( $config );
+					} elseif ( function_exists( 'apc_store' ) ) {
+						$inner_cache = new Cache_Apc( $config );
+					}
 
-				break;
+					break;
 
-			case 'apc':
-				$config = array(
-					'blog_id' => Util_Environment::blog_id(),
-					'instance_id' => Util_Environment::instance_id(),
-					'host' =>  Util_Environment::host(),
-					'module' => 'minify'
-				);
+				case 'eaccelerator':
+					$config = array(
+						'blog_id'     => Util_Environment::blog_id(),
+						'instance_id' => Util_Environment::instance_id(),
+						'host'        => Util_Environment::host(),
+						'module'      => 'minify',
+					);
 
-				if ( function_exists( 'apcu_store' ) ) {
-					$inner_cache = new Cache_Apcu( $config );
-				} elseif ( function_exists( 'apc_store' ) ) {
-					$inner_cache = new Cache_Apc( $config );
-				}
-				break;
+					$inner_cache = new Cache_Eaccelerator( $config );
 
-			case 'eaccelerator':
-				$config = array(
-					'blog_id' => Util_Environment::blog_id(),
-					'instance_id' => Util_Environment::instance_id(),
-					'host' =>  Util_Environment::host(),
-					'module' => 'minify'
-				);
-				$inner_cache = new Cache_Eaccelerator( $config );
-				break;
+					break;
 
-			case 'xcache':
-				$config = array(
-					'blog_id' => Util_Environment::blog_id(),
-					'instance_id' => Util_Environment::instance_id(),
-					'host' =>  Util_Environment::host(),
-					'module' => 'minify'
-				);
-				$inner_cache = new Cache_Xcache( $config );
-				break;
+				case 'xcache':
+					$config = array(
+						'blog_id'     => Util_Environment::blog_id(),
+						'instance_id' => Util_Environment::instance_id(),
+						'host'        => Util_Environment::host(),
+						'module'      => 'minify',
+					);
 
-			case 'wincache':
-				$config = array(
-					'blog_id' => Util_Environment::blog_id(),
-					'instance_id' => Util_Environment::instance_id(),
-					'host' =>  Util_Environment::host(),
-					'module' => 'minify'
-				);
-				$inner_cache = new Cache_Wincache( $config );
-				break;
+					$inner_cache = new Cache_Xcache( $config );
+
+					break;
+
+				case 'wincache':
+					$config = array(
+						'blog_id'     => Util_Environment::blog_id(),
+						'instance_id' => Util_Environment::instance_id(),
+						'host'        => Util_Environment::host(),
+						'module'      => 'minify',
+					);
+
+					$inner_cache = new Cache_Wincache( $config );
+
+					break;
 			}
 
-			if ( !is_null( $inner_cache ) ) {
+			if ( ! is_null( $inner_cache ) ) {
 				$cache = new \W3TCL\Minify\Minify_Cache_W3TCDerived( $inner_cache );
 			} else {
-				// case 'file' or fallback
-
+				// case 'file' or fallback.
 				$cache = new \W3TCL\Minify\Minify_Cache_File(
 					Util_Environment::cache_blog_minify_dir(),
 					array(
 						'.htaccess',
 						'index.html',
-						'*_old'
+						'*_old',
 					),
 					$this->_config->get_boolean( 'minify.file.locking' ),
 					$this->_config->get_integer( 'timelimit.cache_flush' ),
-					( Util_Environment::blog_id() == 0 ? W3TC_CACHE_MINIFY_DIR : null )
+					( Util_Environment::blog_id() === 0 ? W3TC_CACHE_MINIFY_DIR : null )
 				);
 			}
 		}
@@ -764,16 +822,17 @@ function _get_cache() {
 	}
 
 	/**
-	 * Handle minify error
+	 * Handles an error notification process.
+	 *
+	 * @param string $error The error message to handle.
 	 *
-	 * @param string  $error
 	 * @return void
 	 */
-	function _handle_error( $error ) {
+	public function _handle_error( $error ) {
 		$notification = $this->_config->get_string( 'minify.error.notification' );
 
 		if ( $notification ) {
-			$file = Util_Request::get_string( 'file' );
+			$file  = Util_Request::get_string( 'file' );
 			$state = Dispatcher::config_state_master();
 
 			if ( $file ) {
@@ -788,9 +847,7 @@ function _handle_error( $error ) {
 			if ( stristr( $notification, 'email' ) !== false ) {
 				$last = $state->get_integer( 'minify.error.notification.last' );
 
-				/**
-				 * Prevent email flood: send email every 5 min
-				 */
+				// Prevent email flood: send email every 5 min.
 				if ( ( time() - $last ) > 300 ) {
 					$state->set( 'minify.error.notification.last', time() );
 					$this->_send_notification();
@@ -802,20 +859,21 @@ function _handle_error( $error ) {
 	}
 
 	/**
-	 * Send E-mail notification when error occurred
+	 * Sends an error notification email.
 	 *
-	 * @return boolean
+	 * @return bool True if the email was successfully sent, false otherwise.
 	 */
-	function _send_notification() {
+	public function _send_notification() {
 		$from_email = 'wordpress@' . Util_Environment::host();
-		$from_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
-		$to_name = $to_email = get_option( 'admin_email' );
-		$body = @file_get_contents( W3TC_INC_DIR . '/email/minify_error_notification.php' );
+		$from_name  = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
+		$to_name    = get_option( 'admin_email' );
+		$to_email   = $to_name;
+		$body       = @file_get_contents( W3TC_INC_DIR . '/email/minify_error_notification.php' );
 
 		$headers = array(
 			sprintf( 'From: "%s" <%s>', addslashes( $from_name ), $from_email ),
 			sprintf( 'Reply-To: "%s" <%s>', addslashes( $to_name ), $to_email ),
-			'Content-Type: text/html; charset=utf-8'
+			'Content-Type: text/html; charset=utf-8',
 		);
 
 		@set_time_limit( $this->_config->get_integer( 'timelimit.email_send' ) );
@@ -826,46 +884,50 @@ function _send_notification() {
 	}
 
 	/**
-	 * Generates file ID
+	 * Generates an ID based on the given sources and type.
 	 *
-	 * @param array   $sources
-	 * @param string  $type
-	 * @return string
+	 * @param array  $sources The sources to generate the ID from.
+	 * @param string $type    The type of the sources (e.g., CSS or JS).
+	 *
+	 * @return string|false The generated ID or false if generation fails.
 	 */
-	function _generate_id( $sources, $type ) {
-		$values =array();
-		foreach ( $sources as $source )
-			if ( is_string( $source ) )
+	public function _generate_id( $sources, $type ) {
+		$values = array();
+		foreach ( $sources as $source ) {
+			if ( is_string( $source ) ) {
 				$values[] = $source;
-			else
+			} else {
 				$values[] = $source->filepath;
-			foreach ( $sources as $source ) {
-				if ( is_string( $source ) && file_exists( $source ) ) {
-					$data = @file_get_contents( $source );
+			}
+		}
 
-					if ( $data !== false ) {
+		foreach ( $sources as $source ) {
+			if ( is_string( $source ) && file_exists( $source ) ) {
+				$data = @file_get_contents( $source );
+
+				if ( false !== $data ) {
+					$values[] = md5( $data );
+				} else {
+					return false;
+				}
+			} else {
+				$headers = @get_headers( $source->minifyOptions['prependRelativePath'] );
+				if ( strpos( $headers[0], '200' ) !== false ) {
+					$segments  = explode( '.', $source->minifyOptions['prependRelativePath'] );
+					$ext       = strtolower( array_pop( $segments ) );
+					$pc_source = $this->_precache_file( $source->minifyOptions['prependRelativePath'], $ext );
+					$data      = @file_get_contents( $pc_source->filepath );
+
+					if ( false !== $data ) {
 						$values[] = md5( $data );
 					} else {
 						return false;
 					}
 				} else {
-					$headers = @get_headers( $source->minifyOptions['prependRelativePath'] );
-					if ( strpos( $headers[0], '200' ) !== false ) {
-						$segments = explode( '.', $source->minifyOptions['prependRelativePath'] );
-						$ext = strtolower( array_pop( $segments ) );
-						$pc_source = $this->_precache_file( $source->minifyOptions['prependRelativePath'], $ext );
-						$data = @file_get_contents( $pc_source->filepath );
-
-						if ( $data !== false ) {
-							$values[] = md5( $data );
-						} else {
-							return false;
-						}
-					}else {
-						return false;
-					}
+					return false;
 				}
 			}
+		}
 
 		$keys = array(
 			'minify.debug',
@@ -874,7 +936,7 @@ function _generate_id( $sources, $type ) {
 			'minify.symlinks',
 		);
 
-		if ( $type == 'js' ) {
+		if ( 'js' === $type ) {
 			$engine = $this->_config->get_string( 'minify.js.engine' );
 
 			if ( $this->_config->get_boolean( 'minify.auto' ) ) {
@@ -891,69 +953,87 @@ function _generate_id( $sources, $type ) {
 			}
 
 			switch ( $engine ) {
-			case 'js':
-				$keys = array_merge( $keys, array(
-						'minify.js.strip.comments',
-						'minify.js.strip.crlf',
-					) );
-				break;
-
-			case 'yuijs':
-				$keys = array_merge( $keys, array(
-						'minify.yuijs.options.line-break',
-						'minify.yuijs.options.nomunge',
-						'minify.yuijs.options.preserve-semi',
-						'minify.yuijs.options.disable-optimizations',
-					) );
-				break;
-
-			case 'ccjs':
-				$keys = array_merge( $keys, array(
-						'minify.ccjs.options.compilation_level',
-						'minify.ccjs.options.formatting',
-					) );
-				break;
+				case 'js':
+					$keys = array_merge(
+						$keys,
+						array(
+							'minify.js.strip.comments',
+							'minify.js.strip.crlf',
+						)
+					);
+					break;
+
+				case 'yuijs':
+					$keys = array_merge(
+						$keys,
+						array(
+							'minify.yuijs.options.line-break',
+							'minify.yuijs.options.nomunge',
+							'minify.yuijs.options.preserve-semi',
+							'minify.yuijs.options.disable-optimizations',
+						)
+					);
+					break;
+
+				case 'ccjs':
+					$keys = array_merge(
+						$keys,
+						array(
+							'minify.ccjs.options.compilation_level',
+							'minify.ccjs.options.formatting',
+						)
+					);
+					break;
 			}
-		} elseif ( $type == 'css' ) {
+		} elseif ( 'css' === $type ) {
 			$engine = $this->_config->get_string( 'minify.css.engine' );
 			$keys[] = 'minify.css.method';
 
 			switch ( $engine ) {
-			case 'css':
-				$keys = array_merge( $keys, array(
-						'minify.css.strip.comments',
-						'minify.css.strip.crlf',
-						'minify.css.imports',
-					) );
-				break;
-
-			case 'yuicss':
-				$keys = array_merge( $keys, array(
-						'minify.yuicss.options.line-break',
-					) );
-				break;
-
-			case 'csstidy':
-				$keys = array_merge( $keys, array(
-						'minify.csstidy.options.remove_bslash',
-						'minify.csstidy.options.compress_colors',
-						'minify.csstidy.options.compress_font-weight',
-						'minify.csstidy.options.lowercase_s',
-						'minify.csstidy.options.optimise_shorthands',
-						'minify.csstidy.options.remove_last_;',
-						'minify.csstidy.options.remove_space_before_important',
-						'minify.csstidy.options.case_properties',
-						'minify.csstidy.options.sort_properties',
-						'minify.csstidy.options.sort_selectors',
-						'minify.csstidy.options.merge_selectors',
-						'minify.csstidy.options.discard_invalid_selectors',
-						'minify.csstidy.options.discard_invalid_properties',
-						'minify.csstidy.options.css_level',
-						'minify.csstidy.options.preserve_css',
-						'minify.csstidy.options.timestamp',
-						'minify.csstidy.options.template',
-					) );
-				break;
+				case 'css':
+					$keys = array_merge(
+						$keys,
+						array(
+							'minify.css.strip.comments',
+							'minify.css.strip.crlf',
+							'minify.css.imports',
+						)
+					);
+					break;
+
+				case 'yuicss':
+					$keys = array_merge(
+						$keys,
+						array(
+							'minify.yuicss.options.line-break',
+						)
+					);
+					break;
+
+				case 'csstidy':
+					$keys = array_merge(
+						$keys,
+						array(
+							'minify.csstidy.options.remove_bslash',
+							'minify.csstidy.options.compress_colors',
+							'minify.csstidy.options.compress_font-weight',
+							'minify.csstidy.options.lowercase_s',
+							'minify.csstidy.options.optimise_shorthands',
+							'minify.csstidy.options.remove_last_;',
+							'minify.csstidy.options.remove_space_before_important',
+							'minify.csstidy.options.case_properties',
+							'minify.csstidy.options.sort_properties',
+							'minify.csstidy.options.sort_selectors',
+							'minify.csstidy.options.merge_selectors',
+							'minify.csstidy.options.discard_invalid_selectors',
+							'minify.csstidy.options.discard_invalid_properties',
+							'minify.csstidy.options.css_level',
+							'minify.csstidy.options.preserve_css',
+							'minify.csstidy.options.timestamp',
+							'minify.csstidy.options.template',
+						)
+					);
+					break;
 			}
 		}
 
@@ -967,30 +1047,33 @@ function _generate_id( $sources, $type ) {
 	}
 
 	/**
-	 * Takes a multidimensional array and makes it singledimensional
+	 * Flattens a multidimensional array into a single-dimensional array.
+	 *
+	 * @param array $values The array to flatten.
 	 *
-	 * @param unknown $values
-	 * @return array
+	 * @return array The flattened array.
 	 */
 	private function _flatten_array( $values ) {
 		$flatten = array();
 
 		foreach ( $values as $key => $value ) {
-			if ( is_array( $value ) )
+			if ( is_array( $value ) ) {
 				$flatten = array_merge( $flatten, $this->_flatten_array( $value ) );
-			else
-				$flatten[$key] = $value;
+			} else {
+				$flatten[ $key ] = $value;
+			}
 		}
 		return $flatten;
 	}
 
 	/**
-	 * Returns cache data
+	 * Retrieves a value from the cache by its key.
 	 *
-	 * @param string  $key
-	 * @return bool|array
+	 * @param string $key The key of the cached value.
+	 *
+	 * @return mixed The cached value or null if not found.
 	 */
-	function _cache_get( $key ) {
+	public function _cache_get( $key ) {
 		$cache = $this->_get_cache();
 
 		$data = $cache->fetch( $key );
@@ -1005,13 +1088,14 @@ function _cache_get( $key ) {
 	}
 
 	/**
-	 * Sets cache date
+	 * Sets a value in the cache.
+	 *
+	 * @param string $key   The cache key.
+	 * @param mixed  $value The value to store in the cache.
 	 *
-	 * @param string  $key
-	 * @param string  $value
-	 * @return boolean
+	 * @return bool True on success, false on failure.
 	 */
-	function _cache_set( $key, $value ) {
+	public function _cache_set( $key, $value ) {
 		$cache = $this->_get_cache();
 
 		return $cache->store( $key, array( 'content' => serialize( $value ) ) );
diff --git a/Minify_Page.php b/Minify_Page.php
index af8d1dcea..7d4c91e5a 100644
--- a/Minify_Page.php
+++ b/Minify_Page.php
@@ -1,8 +1,18 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: Minify_Page.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class Minify_Page
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ */
 class Minify_Page extends Base_Page_Settings {
 	/**
 	 * Current page
@@ -12,110 +22,109 @@ class Minify_Page extends Base_Page_Settings {
 	protected $_page = 'w3tc_minify';
 
 	/**
-	 * Minify tab
+	 * Renders the minify settings page.
 	 *
 	 * @return void
 	 */
-	function view() {
+	public function view() {
 		$minify_enabled = $this->_config->get_boolean( 'minify.enabled' );
-		$config_state = Dispatcher::config_state();
+		$config_state   = Dispatcher::config_state();
 
-		$minify_rewrite_disabled = !Util_Rule::can_check_rules() ||
-			$this->_config->is_sealed( 'minify.rewrite' );
-		$themes = Util_Theme::get_themes_by_key();
-		$templates = array();
+		$minify_rewrite_disabled = ! Util_Rule::can_check_rules() || $this->_config->is_sealed( 'minify.rewrite' );
+		$themes                  = Util_Theme::get_themes_by_key();
+		$templates               = array();
 
-		$current_theme = Util_Theme::get_current_theme_name();
+		$current_theme     = Util_Theme::get_current_theme_name();
 		$current_theme_key = '';
 
 		foreach ( $themes as $theme_key => $theme_name ) {
-			if ( $theme_name == $current_theme ) {
+			if ( $theme_name === $current_theme ) {
 				$current_theme_key = $theme_key;
 			}
 
-			$templates[$theme_key] = Util_Theme::get_theme_templates( $theme_name );
+			$templates[ $theme_key ] = Util_Theme::get_theme_templates( $theme_name );
 		}
 
 		$css_imports_values = array(
-			'' => 'None',
-			'bubble' => 'Bubble',
+			''        => 'None',
+			'bubble'  => 'Bubble',
 			'process' => 'Process',
 		);
 
 		$auto = $this->_config->get_boolean( 'minify.auto' );
 
-
-
-		$js_theme = Util_Request::get_string( 'js_theme', $current_theme_key );
+		$js_theme  = Util_Request::get_string( 'js_theme', $current_theme_key );
 		$js_groups = $this->_config->get_array( 'minify.js.groups' );
 
-		$css_theme = Util_Request::get_string( 'css_theme', $current_theme_key );
+		$css_theme  = Util_Request::get_string( 'css_theme', $current_theme_key );
 		$css_groups = $this->_config->get_array( 'minify.css.groups' );
 
-		$js_engine = $this->_config->get_string( 'minify.js.engine' );
-		$css_engine = $this->_config->get_string( 'minify.css.engine' );
+		$js_engine   = $this->_config->get_string( 'minify.js.engine' );
+		$css_engine  = $this->_config->get_string( 'minify.css.engine' );
 		$html_engine = $this->_config->get_string( 'minify.html.engine' );
 
 		$css_imports = $this->_config->get_string( 'minify.css.imports' );
 
-		// Required for Update Media Query String button
-		$browsercache_enabled = $this->_config->get_boolean( 'browsercache.enabled' );
-		$browsercache_update_media_qs = ( $this->_config->get_boolean( 'browsercache.cssjs.replace' ) );
+		// Required for Update Media Query String button.
+		$browsercache_enabled         = $this->_config->get_boolean( 'browsercache.enabled' );
+		$browsercache_update_media_qs = $this->_config->get_boolean( 'browsercache.cssjs.replace' );
 
 		include W3TC_INC_DIR . '/options/minify.php';
 	}
 
-	function recommendations() {
+	/**
+	 * Displays the minify recommendations for a theme.
+	 *
+	 * @return void
+	 */
+	public function recommendations() {
 		$themes = Util_Theme::get_themes_by_key();
 
-		$current_theme = Util_Theme::get_current_theme_name();
-		$current_theme_key = array_search( $current_theme, $themes );
+		$current_theme     = Util_Theme::get_current_theme_name();
+		$current_theme_key = array_search( $current_theme, $themes, true );
 
+		$theme_key  = Util_Request::get_string( 'theme_key', $current_theme_key );
+		$theme_name = ( isset( $themes[ $theme_key ] ) ? $themes[ $theme_key ] : $current_theme );
 
-
-		$theme_key = Util_Request::get_string( 'theme_key', $current_theme_key );
-		$theme_name = ( isset( $themes[$theme_key] ) ? $themes[$theme_key] : $current_theme );
-
-		$templates = Util_Theme::get_theme_templates( $theme_name );
+		$templates       = Util_Theme::get_theme_templates( $theme_name );
 		$recommendations = $this->get_theme_recommendations( $theme_name );
 
 		list ( $js_groups, $css_groups ) = $recommendations;
 
-		$minify_js_groups = $this->_config->get_array( 'minify.js.groups' );
+		$minify_js_groups  = $this->_config->get_array( 'minify.js.groups' );
 		$minify_css_groups = $this->_config->get_array( 'minify.css.groups' );
 
-		$checked_js = array();
-		$checked_css = array();
-
+		$checked_js   = array();
+		$checked_css  = array();
 		$locations_js = array();
 
-		if ( isset( $minify_js_groups[$theme_key] ) ) {
-			foreach ( (array) $minify_js_groups[$theme_key] as $template => $locations ) {
+		if ( isset( $minify_js_groups[ $theme_key ] ) ) {
+			foreach ( (array) $minify_js_groups[ $theme_key ] as $template => $locations ) {
 				foreach ( (array) $locations as $location => $config ) {
 					if ( isset( $config['files'] ) ) {
 						foreach ( (array) $config['files'] as $file ) {
-							if ( !isset( $js_groups[$template] ) || !in_array( $file, $js_groups[$template] ) ) {
-								$js_groups[$template][] = $file;
+							if ( ! isset( $js_groups[ $template ] ) || ! in_array( $file, $js_groups[ $template ], true ) ) {
+								$js_groups[ $template ][] = $file;
 							}
 
-							$checked_js[$template][$file] = true;
-							$locations_js[$template][$file] = $location;
+							$checked_js[ $template ][ $file ]   = true;
+							$locations_js[ $template ][ $file ] = $location;
 						}
 					}
 				}
 			}
 		}
 
-		if ( isset( $minify_css_groups[$theme_key] ) ) {
-			foreach ( (array) $minify_css_groups[$theme_key] as $template => $locations ) {
+		if ( isset( $minify_css_groups[ $theme_key ] ) ) {
+			foreach ( (array) $minify_css_groups [ $theme_key ] as $template => $locations ) {
 				foreach ( (array) $locations as $location => $config ) {
 					if ( isset( $config['files'] ) ) {
 						foreach ( (array) $config['files'] as $file ) {
-							if ( !isset( $css_groups[$template] ) || !in_array( $file, $css_groups[$template] ) ) {
-								$css_groups[$template][] = $file;
+							if ( ! isset( $css_groups[ $template ] ) || ! in_array( $file, $css_groups[ $template ], true ) ) {
+								$css_groups[ $template ][] = $file;
 							}
 
-							$checked_css[$template][$file] = true;
+							$checked_css[ $template ][ $file ] = true;
 						}
 					}
 				}
@@ -126,19 +135,20 @@ function recommendations() {
 	}
 
 	/**
-	 * Returns array of detected URLs for theme templates
+	 * Retrieves the theme URLs for a given theme name.
 	 *
-	 * @param string  $theme_name
-	 * @return array
+	 * @param string $theme_name The name of the theme to retrieve URLs for.
+	 *
+	 * @return array An associative array where the keys are template names and the values are their respective URLs.
 	 */
-	function get_theme_urls( $theme_name ) {
-		$urls = array();
+	public function get_theme_urls( $theme_name ) {
+		$urls  = array();
 		$theme = Util_Theme::get( $theme_name );
 
 		if ( $theme && isset( $theme['Template Files'] ) ) {
 			$front_page_template = false;
 
-			if ( get_option( 'show_on_front' ) == 'page' ) {
+			if ( 'page' === get_option( 'show_on_front' ) ) {
 				$front_page_id = get_option( 'page_on_front' );
 
 				if ( $front_page_id ) {
@@ -150,337 +160,330 @@ function get_theme_urls( $theme_name ) {
 				}
 			}
 
-			$home_url = get_home_url();
+			$home_url       = get_home_url();
 			$template_files = (array) $theme['Template Files'];
 
-			$mime_types = get_allowed_mime_types();
+			$mime_types        = get_allowed_mime_types();
 			$custom_mime_types = array();
 
 			foreach ( $mime_types as $mime_type ) {
 				list ( $type1, $type2 ) = explode( '/', $mime_type );
-				$custom_mime_types = array_merge( $custom_mime_types, array(
+				$custom_mime_types      = array_merge(
+					$custom_mime_types,
+					array(
 						$type1,
 						$type2,
-						$type1 . '_' . $type2
-					) );
+						$type1 . '_' . $type2,
+					)
+				);
 			}
 
 			foreach ( $template_files as $template_file ) {
-				$link = false;
+				$link     = false;
 				$template = basename( $template_file, '.php' );
 
-				/**
-				 * Check common templates
-				 */
+				// Check common templates.
 				switch ( true ) {
-					/**
-					 * Handle home.php or index.php or front-page.php
-					 */
-				case ( !$front_page_template && $template == 'home' ):
-				case ( !$front_page_template && $template == 'index' ):
-				case ( !$front_page_template && $template == 'front-page' ):
-
-					/**
-					 * Handle custom home page
-					 */
-				case ( $template == $front_page_template ):
-					$link = $home_url . '/';
-					break;
-
-					/**
-					 * Handle 404.php
-					 */
-				case ( $template == '404' ):
-					$permalink = get_option( 'permalink_structure' );
-					if ( $permalink ) {
-						$link = sprintf( '%s/%s/', $home_url, '404_test' );
-					} else {
-						$link = sprintf( '%s/?p=%d', $home_url, 999999999 );
-					}
-					break;
-
-					/**
-					 * Handle search.php
-					 */
-				case ( $template == 'search' ):
-					$link = sprintf( '%s/?s=%s', $home_url, 'search_test' );
-					break;
-
-					/**
-					 * Handle date.php or archive.php
-					 */
-				case ( $template == 'date' ):
-				case ( $template == 'archive' ):
-					$posts = get_posts( array(
-							'numberposts' => 1,
-							'orderby' => 'rand'
-						) );
-					if ( is_array( $posts ) && count( $posts ) ) {
-						$time = strtotime( $posts[0]->post_date );
-						$link = get_day_link( date( 'Y', $time ), date( 'm', $time ), date( 'd', $time ) );
-					}
-					break;
-
-					/**
-					 * Handle author.php
-					 */
-				case ( $template == 'author' ):
-					$author_id = false;
-					if ( function_exists( 'get_users' ) ) {
-						$users = get_users();
-						if ( is_array( $users ) && count( $users ) ) {
-							$user = current( $users );
-							$author_id = $user->ID;
+					// Handle home.php or index.php or front-page.php or custom home page.
+					case ( ! $front_page_template && 'home' === $template ):
+					case ( ! $front_page_template && 'index' === $template ):
+					case ( ! $front_page_template && 'front-page' === $template ):
+					case ( $template === $front_page_template ):
+						$link = $home_url . '/';
+						break;
+
+					// Handle 404.php.
+					case ( '404' === $template ):
+						$permalink = get_option( 'permalink_structure' );
+						if ( $permalink ) {
+							$link = sprintf( '%s/%s/', $home_url, '404_test' );
+						} else {
+							$link = sprintf( '%s/?p=%d', $home_url, 999999999 );
 						}
-					} else {
-						$author_ids = get_author_user_ids();
-						if ( is_array( $author_ids ) && count( $author_ids ) ) {
-							$author_id = $author_ids[0];
+						break;
+
+					// Handle search.php.
+					case ( 'search' === $template ):
+						$link = sprintf( '%s/?s=%s', $home_url, 'search_test' );
+						break;
+
+					// Handle date.php or archive.php.
+					case ( 'date' === $template ):
+					case ( 'archive' === $template ):
+						$posts = get_posts(
+							array(
+								'numberposts' => 1,
+								'orderby'     => 'rand',
+							)
+						);
+
+						if ( is_array( $posts ) && count( $posts ) ) {
+							$time = strtotime( $posts[0]->post_date );
+							$link = get_day_link( gmdate( 'Y', $time ), gmdate( 'm', $time ), gmdate( 'd', $time ) );
 						}
-					}
-					if ( $author_id ) {
-						$link = get_author_posts_url( $author_id );
-					}
-					break;
-
-					/**
-					 * Handle category.php
-					 */
-				case ( $template == 'category' ):
-					$category_ids = get_terms( 'category', array(
-							'orderby' => 'id',
-							'number' => 1,
-							'fields' => 'ids' ) );
-
-					if ( is_array( $category_ids ) && count( $category_ids ) ) {
-						$link = get_category_link( $category_ids[0] );
-					}
-					break;
-
-					/**
-					 * Handle tag.php
-					 */
-				case ( $template == 'tag' ):
-					$term_ids = get_terms( 'post_tag', 'fields=ids' );
-					if ( is_array( $term_ids ) && count( $term_ids ) ) {
-						$link = get_term_link( $term_ids[0], 'post_tag' );
-					}
-					break;
-
-					/**
-					 * Handle taxonomy.php
-					 */
-				case ( $template == 'taxonomy' ):
-					$taxonomy = '';
-					if ( isset( $GLOBALS['wp_taxonomies'] ) && is_array( $GLOBALS['wp_taxonomies'] ) ) {
-						foreach ( $GLOBALS['wp_taxonomies'] as $wp_taxonomy ) {
-							if ( !in_array( $wp_taxonomy->name, array(
-										'category',
-										'post_tag',
-										'link_category'
-									) ) ) {
-								$taxonomy = $wp_taxonomy->name;
-								break;
+						break;
+
+					// Handle author.php.
+					case ( 'author' === $template ):
+						$author_id = false;
+						if ( function_exists( 'get_users' ) ) {
+							$users = get_users();
+							if ( is_array( $users ) && count( $users ) ) {
+								$user      = current( $users );
+								$author_id = $user->ID;
+							}
+						} else {
+							$author_ids = get_users(
+								array(
+									'role'   => 'author',
+									'fields' => 'ID', // Only fetch user IDs.
+								)
+							);
+							if ( is_array( $author_ids ) && count( $author_ids ) ) {
+								$author_id = $author_ids[0];
 							}
 						}
-					}
-					if ( $taxonomy ) {
-						$terms = get_terms( $taxonomy, array(
-								'number' => 1
-							) );
+
+						if ( $author_id ) {
+							$link = get_author_posts_url( $author_id );
+						}
+						break;
+
+					// Handle category.php.
+					case ( 'category' === $template ):
+						$category_ids = get_terms(
+							'category',
+							array(
+								'orderby' => 'id',
+								'number'  => 1,
+								'fields'  => 'ids',
+							)
+						);
+
+						if ( is_array( $category_ids ) && count( $category_ids ) ) {
+							$link = get_category_link( $category_ids[0] );
+						}
+						break;
+
+					// Handle tag.php.
+					case ( 'tag' === $template ):
+						$term_ids = get_terms( 'post_tag', 'fields=ids' );
+						if ( is_array( $term_ids ) && count( $term_ids ) ) {
+							$link = get_term_link( $term_ids[0], 'post_tag' );
+						}
+						break;
+
+					// Handle taxonomy.php.
+					case ( 'taxonomy' === $template ):
+						$taxonomy = '';
+						if ( isset( $GLOBALS['wp_taxonomies'] ) && is_array( $GLOBALS['wp_taxonomies'] ) ) {
+							foreach ( $GLOBALS['wp_taxonomies'] as $wp_taxonomy ) {
+								if (
+									! in_array(
+										$wp_taxonomy->name,
+										array(
+											'category',
+											'post_tag',
+											'link_category',
+										),
+										true
+									)
+								) {
+									$taxonomy = $wp_taxonomy->name;
+									break;
+								}
+							}
+						}
+
+						if ( $taxonomy ) {
+							$terms = get_terms(
+								$taxonomy,
+								array(
+									'number' => 1,
+								)
+							);
+							if ( is_array( $terms ) && count( $terms ) ) {
+								$link = get_term_link( $terms[0], $taxonomy );
+							}
+						}
+						break;
+
+					// Handle attachment.php.
+					case ( 'attachment' === $template ):
+						$attachments = get_posts(
+							array(
+								'post_type'   => 'attachment',
+								'numberposts' => 1,
+								'orderby'     => 'rand',
+							)
+						);
+						if ( is_array( $attachments ) && count( $attachments ) ) {
+							$link = get_attachment_link( $attachments[0]->ID );
+						}
+						break;
+
+					// Handle single.php.
+					case ( 'single' === $template ):
+						$posts = get_posts(
+							array(
+								'numberposts' => 1,
+								'orderby'     => 'rand',
+							)
+						);
+						if ( is_array( $posts ) && count( $posts ) ) {
+							$link = get_permalink( $posts[0]->ID );
+						}
+						break;
+
+					// Handle page.php.
+					case ( 'page' === $template ):
+						$pages_ids = get_all_page_ids();
+						if ( is_array( $pages_ids ) && count( $pages_ids ) ) {
+							$link = get_page_link( $pages_ids[0] );
+						}
+						break;
+
+					// Handle comments-popup.php.
+					case ( 'comments-popup' === $template ):
+						$posts = get_posts(
+							array(
+								'numberposts' => 1,
+								'orderby'     => 'rand',
+							)
+						);
+						if ( is_array( $posts ) && count( $posts ) ) {
+							$link = sprintf( '%s/?comments_popup=%d', $home_url, $posts[0]->ID );
+						}
+						break;
+
+					// Handle paged.php.
+					case ( 'paged' === $template ):
+						global $wp_rewrite;
+						if ( $wp_rewrite->using_permalinks() ) {
+							$link = sprintf( '%s/page/%d/', $home_url, 1 );
+						} else {
+							$link = sprintf( '%s/?paged=%d', 1 );
+						}
+						break;
+
+					// Handle author-id.php or author-nicename.php.
+					case preg_match( '~^author-(.+)$~', $template, $matches ):
+						if ( is_numeric( $matches[1] ) ) {
+							$link = get_author_posts_url( $matches[1] );
+						} else {
+							$link = get_author_posts_url( null, $matches[1] );
+						}
+						break;
+
+					// Handle category-id.php or category-slug.php.
+					case preg_match( '~^category-(.+)$~', $template, $matches ):
+						if ( is_numeric( $matches[1] ) ) {
+							$link = get_category_link( $matches[1] );
+						} else {
+							$term = get_term_by( 'slug', $matches[1], 'category' );
+							if ( is_object( $term ) ) {
+								$link = get_category_link( $term->term_id );
+							}
+						}
+						break;
+
+					// Handle tag-id.php or tag-slug.php.
+					case preg_match( '~^tag-(.+)$~', $template, $matches ):
+						if ( is_numeric( $matches[1] ) ) {
+							$link = get_tag_link( $matches[1] );
+						} else {
+							$term = get_term_by( 'slug', $matches[1], 'post_tag' );
+							if ( is_object( $term ) ) {
+								$link = get_tag_link( $term->term_id );
+							}
+						}
+						break;
+
+					// Handle taxonomy-taxonomy-term.php.
+					case preg_match( '~^taxonomy-(.+)-(.+)$~', $template, $matches ):
+						$link = get_term_link( $matches[2], $matches[1] );
+						break;
+
+					// Handle taxonomy-taxonomy.php.
+					case preg_match( '~^taxonomy-(.+)$~', $template, $matches ):
+						$terms = get_terms(
+							$matches[1],
+							array(
+								'number' => 1,
+							)
+						);
 						if ( is_array( $terms ) && count( $terms ) ) {
-							$link = get_term_link( $terms[0], $taxonomy );
+							$link = get_term_link( $terms[0], $matches[1] );
 						}
-					}
-					break;
-
-					/**
-					 * Handle attachment.php
-					 */
-				case ( $template == 'attachment' ):
-					$attachments = get_posts( array(
-							'post_type' => 'attachment',
-							'numberposts' => 1,
-							'orderby' => 'rand'
-						) );
-					if ( is_array( $attachments ) && count( $attachments ) ) {
-						$link = get_attachment_link( $attachments[0]->ID );
-					}
-					break;
-
-					/**
-					 * Handle single.php
-					 */
-				case ( $template == 'single' ):
-					$posts = get_posts( array(
-							'numberposts' => 1,
-							'orderby' => 'rand'
-						) );
-					if ( is_array( $posts ) && count( $posts ) ) {
-						$link = get_permalink( $posts[0]->ID );
-					}
-					break;
-
-					/**
-					 * Handle page.php
-					 */
-				case ( $template == 'page' ):
-					$pages_ids = get_all_page_ids();
-					if ( is_array( $pages_ids ) && count( $pages_ids ) ) {
-						$link = get_page_link( $pages_ids[0] );
-					}
-					break;
-
-					/**
-					 * Handle comments-popup.php
-					 */
-				case ( $template == 'comments-popup' ):
-					$posts = get_posts( array(
-							'numberposts' => 1,
-							'orderby' => 'rand'
-						) );
-					if ( is_array( $posts ) && count( $posts ) ) {
-						$link = sprintf( '%s/?comments_popup=%d', $home_url, $posts[0]->ID );
-					}
-					break;
-
-					/**
-					 * Handle paged.php
-					 */
-				case ( $template == 'paged' ):
-					global $wp_rewrite;
-					if ( $wp_rewrite->using_permalinks() ) {
-						$link = sprintf( '%s/page/%d/', $home_url, 1 );
-					} else {
-						$link = sprintf( '%s/?paged=%d', 1 );
-					}
-					break;
-
-					/**
-					 * Handle author-id.php or author-nicename.php
-					 */
-				case preg_match( '~^author-(.+)$~', $template, $matches ):
-					if ( is_numeric( $matches[1] ) ) {
-						$link = get_author_posts_url( $matches[1] );
-					} else {
-						$link = get_author_posts_url( null, $matches[1] );
-					}
-					break;
-
-					/**
-					 * Handle category-id.php or category-slug.php
-					 */
-				case preg_match( '~^category-(.+)$~', $template, $matches ):
-					if ( is_numeric( $matches[1] ) ) {
-						$link = get_category_link( $matches[1] );
-					} else {
-						$term = get_term_by( 'slug', $matches[1], 'category' );
-						if ( is_object( $term ) ) {
-							$link = get_category_link( $term->term_id );
+						break;
+
+					// Handle MIME_type.php.
+					case in_array( $template, $custom_mime_types, true ):
+						$posts = get_posts(
+							array(
+								'post_mime_type' => '%' . $template . '%',
+								'post_type'      => 'attachment',
+								'numberposts'    => 1,
+								'orderby'        => 'rand',
+							)
+						);
+						if ( is_array( $posts ) && count( $posts ) ) {
+							$link = get_permalink( $posts[0]->ID );
 						}
-					}
-					break;
-
-					/**
-					 * Handle tag-id.php or tag-slug.php
-					 */
-				case preg_match( '~^tag-(.+)$~', $template, $matches ):
-					if ( is_numeric( $matches[1] ) ) {
-						$link = get_tag_link( $matches[1] );
-					} else {
-						$term = get_term_by( 'slug', $matches[1], 'post_tag' );
-						if ( is_object( $term ) ) {
-							$link = get_tag_link( $term->term_id );
+						break;
+
+					// Handle single-posttype.php.
+					case preg_match( '~^single-(.+)$~', $template, $matches ):
+						$posts = get_posts(
+							array(
+								'post_type'   => $matches[1],
+								'numberposts' => 1,
+								'orderby'     => 'rand',
+							)
+						);
+
+						if ( is_array( $posts ) && count( $posts ) ) {
+							$link = get_permalink( $posts[0]->ID );
 						}
-					}
-					break;
-
-					/**
-					 * Handle taxonomy-taxonomy-term.php
-					 */
-				case preg_match( '~^taxonomy-(.+)-(.+)$~', $template, $matches ):
-					$link = get_term_link( $matches[2], $matches[1] );
-					break;
-
-					/**
-					 * Handle taxonomy-taxonomy.php
-					 */
-				case preg_match( '~^taxonomy-(.+)$~', $template, $matches ):
-					$terms = get_terms( $matches[1], array(
-							'number' => 1
-						) );
-					if ( is_array( $terms ) && count( $terms ) ) {
-						$link = get_term_link( $terms[0], $matches[1] );
-					}
-					break;
-
-					/**
-					 * Handle MIME_type.php
-					 */
-				case in_array( $template, $custom_mime_types ):
-					$posts = get_posts( array(
-							'post_mime_type' => '%' . $template . '%',
-							'post_type' => 'attachment',
-							'numberposts' => 1,
-							'orderby' => 'rand'
-						) );
-					if ( is_array( $posts ) && count( $posts ) ) {
-						$link = get_permalink( $posts[0]->ID );
-					}
-					break;
-
-					/**
-					 * Handle single-posttype.php
-					 */
-				case preg_match( '~^single-(.+)$~', $template, $matches ):
-					$posts = get_posts( array(
-							'post_type' => $matches[1],
-							'numberposts' => 1,
-							'orderby' => 'rand'
-						) );
-
-					if ( is_array( $posts ) && count( $posts ) ) {
-						$link = get_permalink( $posts[0]->ID );
-					}
-					break;
-
-					/**
-					 * Handle page-id.php or page-slug.php
-					 */
-				case preg_match( '~^page-(.+)$~', $template, $matches ):
-					if ( is_numeric( $matches[1] ) ) {
-						$link = get_permalink( $matches[1] );
-					} else {
-						$posts = get_posts( array(
-								'pagename' => $matches[1],
-								'post_type' => 'page',
-								'numberposts' => 1
-							) );
+						break;
+
+					// Handle page-id.php or page-slug.php.
+					case preg_match( '~^page-(.+)$~', $template, $matches ):
+						if ( is_numeric( $matches[1] ) ) {
+							$link = get_permalink( $matches[1] );
+						} else {
+							$posts = get_posts(
+								array(
+									'pagename'    => $matches[1],
+									'post_type'   => 'page',
+									'numberposts' => 1,
+								)
+							);
+
+							if ( is_array( $posts ) && count( $posts ) ) {
+								$link = get_permalink( $posts[0]->ID );
+							}
+						}
+						break;
+
+					// Try to handle custom template.
+					default:
+						$posts = get_posts(
+							array(
+								'pagename'    => $template,
+								'post_type'   => 'page',
+								'numberposts' => 1,
+							)
+						);
 
 						if ( is_array( $posts ) && count( $posts ) ) {
 							$link = get_permalink( $posts[0]->ID );
 						}
-					}
-					break;
-
-					/**
-					 * Try to handle custom template
-					 */
-				default:
-					$posts = get_posts( array(
-							'pagename' => $template,
-							'post_type' => 'page',
-							'numberposts' => 1
-						) );
-
-					if ( is_array( $posts ) && count( $posts ) ) {
-						$link = get_permalink( $posts[0]->ID );
-					}
-					break;
+						break;
 				}
 
-				if ( $link && !is_wp_error( $link ) ) {
-					$urls[$template] = $link;
+				if ( $link && ! is_wp_error( $link ) ) {
+					$urls[ $template ] = $link;
 				}
 			}
 		}
@@ -489,104 +492,100 @@ function get_theme_urls( $theme_name ) {
 	}
 
 	/**
-	 * Returns theme recommendations
+	 * Retrieves the theme recommendations (JS and CSS files) based on the specified theme.
+	 *
+	 * @param string $theme_name The name of the theme for which to get recommendations.
 	 *
-	 * @param string  $theme_name
-	 * @return array
+	 * @return array An array containing the theme recommendations, categorized by JS and CSS files.
+	 *
+	 * @throws \Exception If an error occurs while processing the recommendations.
 	 */
-	function get_theme_recommendations( $theme_name ) {
+	public function get_theme_recommendations( $theme_name ) {
 		$urls = $this->get_theme_urls( $theme_name );
 
-		$js_groups = array();
+		$js_groups  = array();
 		$css_groups = array();
 
 		@set_time_limit( $this->_config->get_integer( 'timelimit.minify_recommendations' ) );
 
 		foreach ( $urls as $template => $url ) {
-			/**
-			 * Append theme identifier
-			 */
-			$url .= ( strstr( $url, '?' ) !== false ? '&' : '?' ) .
-				'w3tc_theme=' . urlencode( $theme_name );
-
-			/**
-			 * If preview mode enabled append w3tc_preview
-			 */
+			// Append theme identifier.
+			$url .= ( strstr( $url, '?' ) !== false ? '&' : '?' ) . 'w3tc_theme=' . rawurlencode( $theme_name );
+
+			// If preview mode enabled append w3tc_preview.
 			if ( $this->_config->is_preview() ) {
 				$url .= '&w3tc_preview=1';
 			}
 
-			/**
-			 * Get page contents
-			 */
+			// Get page contents.
 			$response = Util_Http::get( $url );
 
-			if ( !is_wp_error( $response ) &&
-				( $response['response']['code'] == 200 ||
-					( $response['response']['code'] == 404 && $template == '404' ) ) ) {
-				$js_files = $this->get_recommendations_js( $response['body'] );
+			if (
+				! is_wp_error( $response ) &&
+				(
+					200 === $response['response']['code'] ||
+					(
+						404 === $response['response']['code'] &&
+						'404' === $template
+					)
+				)
+			) {
+				$js_files  = $this->get_recommendations_js( $response['body'] );
 				$css_files = $this->get_recommendations_css( $response['body'] );
 
-				$js_groups[$template] = $js_files;
-				$css_groups[$template] = $css_files;
+				$js_groups[ $template ]  = $js_files;
+				$css_groups[ $template ] = $css_files;
 			}
 		}
 
-		$js_groups = $this->get_theme_recommendations_by_groups( $js_groups );
+		$js_groups  = $this->get_theme_recommendations_by_groups( $js_groups );
 		$css_groups = $this->get_theme_recommendations_by_groups( $css_groups );
 
 		$recommendations = array(
 			$js_groups,
-			$css_groups
+			$css_groups,
 		);
 
 		return $recommendations;
 	}
 
 	/**
-	 * Find common files and place them into default group
+	 * Groups the theme recommendations by their usage across different templates.
+	 *
+	 * @param array $groups An array of theme recommendations categorized by template.
 	 *
-	 * @param array   $groups
-	 * @return array
+	 * @return array An array of grouped recommendations, with a 'default' group for common files.
 	 */
-	function get_theme_recommendations_by_groups( $groups ) {
-		/**
-		 * First calculate file usage count
-		 */
+	public function get_theme_recommendations_by_groups( $groups ) {
+		// First calculate file usage count.
 		$all_files = array();
 
 		foreach ( $groups as $template => $files ) {
 			foreach ( $files as $file ) {
-				if ( !isset( $all_files[$file] ) ) {
-					$all_files[$file] = 0;
+				if ( ! isset( $all_files[ $file ] ) ) {
+					$all_files[ $file ] = 0;
 				}
 
-				$all_files[$file]++;
+				$all_files[ $file ]++;
 			}
 		}
 
-		/**
-		 * Determine default group files
-		 */
+		// Determine default group files.
 		$default_files = array();
-		$count = count( $groups );
+		$count         = count( $groups );
 
 		foreach ( $all_files as $all_file => $all_file_count ) {
-			/**
-			 * If file usage count == groups count then file is common
-			 */
-			if ( $count == $all_file_count ) {
+			// If file usage count == groups count then file is common.
+			if ( $count === $all_file_count ) {
 				$default_files[] = $all_file;
 
-				/**
-				 * If common file found unset it from all groups
-				 */
+				// If common file found unset it from all groups.
 				foreach ( $groups as $template => $files ) {
 					foreach ( $files as $index => $file ) {
-						if ( $file == $all_file ) {
-							array_splice( $groups[$template], $index, 1 );
-							if ( !count( $groups[$template] ) ) {
-								unset( $groups[$template] );
+						if ( $file === $all_file ) {
+							array_splice( $groups[ $template ], $index, 1 );
+							if ( ! count( $groups[ $template ] ) ) {
+								unset( $groups[ $template ] );
 							}
 							break;
 						}
@@ -595,26 +594,22 @@ function get_theme_recommendations_by_groups( $groups ) {
 			}
 		}
 
-		/**
-		 * If there are common files append add them into default group
-		 */
+		// If there are common files append add them into default group.
 		if ( count( $default_files ) ) {
-			$new_groups = array();
+			$new_groups            = array();
 			$new_groups['default'] = $default_files;
 
 			foreach ( $groups as $template => $files ) {
-				$new_groups[$template] = $files;
+				$new_groups[ $template ] = $files;
 			}
 
 			$groups = $new_groups;
 		}
 
-		/**
-		 * Unset empty templates
-		 */
+		// Unset empty templates.
 		foreach ( $groups as $template => $files ) {
-			if ( !count( $files ) ) {
-				unset( $groups[$template] );
+			if ( ! count( $files ) ) {
+				unset( $groups[ $template ] );
 			}
 		}
 
@@ -622,39 +617,41 @@ function get_theme_recommendations_by_groups( $groups ) {
 	}
 
 	/**
-	 * Parse content and return JS recommendations
+	 * Extracts and normalizes the JavaScript files from the provided content.
 	 *
-	 * @param string  $content
-	 * @return array
+	 * @param string $content The HTML content from which to extract JavaScript files.
+	 *
+	 * @return array A list of unique JavaScript file URLs after normalization.
 	 */
-	function get_recommendations_js( $content ) {
-
-
+	public function get_recommendations_js( $content ) {
 		$files = Minify_Extract::extract_js( $content );
 
-		$files = array_map( array( '\W3TC\Util_Environment', 'normalize_file_minify' ), $files );
-		$files = array_unique( $files );
+		$files        = array_map( array( '\W3TC\Util_Environment', 'normalize_file_minify' ), $files );
+		$files        = array_unique( $files );
 		$ignore_files = $this->_config->get_array( 'minify.reject.files.js' );
-		$files = array_diff( $files, $ignore_files );
+		$files        = array_diff( $files, $ignore_files );
+
 		return $files;
 	}
 
 	/**
-	 * Parse content and return CSS recommendations
+	 * Extracts and normalizes the CSS files from the provided content.
 	 *
-	 * @param string  $content
-	 * @return array
+	 * @param string $content The HTML content from which to extract CSS files.
+	 *
+	 * @return array A list of unique CSS file URLs after normalization.
 	 */
-	function get_recommendations_css( $content ) {
+	public function get_recommendations_css( $content ) {
 		$tag_files = Minify_Extract::extract_css( $content );
-		$files = array();
-		foreach ( $tag_files as $tag_file )
+		$files     = array();
+		foreach ( $tag_files as $tag_file ) {
 			$files[] = $tag_file[1];
+		}
 
-		$files = array_map( array( '\W3TC\Util_Environment', 'normalize_file_minify' ), $files );
-		$files = array_unique( $files );
+		$files        = array_map( array( '\W3TC\Util_Environment', 'normalize_file_minify' ), $files );
+		$files        = array_unique( $files );
 		$ignore_files = $this->_config->get_array( 'minify.reject.files.css' );
-		$files = array_diff( $files, $ignore_files );
+		$files        = array_diff( $files, $ignore_files );
 
 		return $files;
 	}
diff --git a/Minify_Plugin.php b/Minify_Plugin.php
index 6cae45775..a4ed018a8 100644
--- a/Minify_Plugin.php
+++ b/Minify_Plugin.php
@@ -1,8 +1,17 @@
 <?php
+/**
+ * File: Minify_Plugin.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * class Minify_Plugin
+ * Class Minify_Plugin
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
  */
 class Minify_Plugin {
 	/**
@@ -62,63 +71,62 @@ class Minify_Plugin {
 	private $_config = null;
 
 	/**
-	 * Constructor.
+	 * Constructor for the Minify_Plugin class.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs plugin
+	 * Initializes the plugin by registering filters and actions.
+	 *
+	 * @return void
 	 */
 	public function run() {
 		add_action( 'init', array( $this, 'init' ) );
-		add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) );
+		add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) ); // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected
 		add_action( 'w3tc_minifycache_purge_wpcron', array( $this, 'w3tc_minifycache_purge_wpcron' ) );
 
-		add_filter( 'w3tc_admin_bar_menu',
-			array( $this, 'w3tc_admin_bar_menu' ) );
+		add_filter( 'w3tc_admin_bar_menu', array( $this, 'w3tc_admin_bar_menu' ) );
 
-		add_filter( 'w3tc_footer_comment', array(
-				$this, 'w3tc_footer_comment' ) );
+		add_filter( 'w3tc_footer_comment', array( $this, 'w3tc_footer_comment' ) );
 
-		if ( $this->_config->get_string( 'minify.engine' ) == 'file' ) {
-			add_action( 'w3_minify_cleanup', array(
-					$this,
-					'cleanup'
-				) );
+		if ( 'file' === $this->_config->get_string( 'minify.engine' ) ) {
+			add_action( 'w3_minify_cleanup', array( $this, 'cleanup' ) );
 		}
-		add_filter( 'w3tc_pagecache_set_header',
-			array( $this, 'w3tc_pagecache_set_header' ), 20, 2 );
+		add_filter( 'w3tc_pagecache_set_header', array( $this, 'w3tc_pagecache_set_header' ), 20, 2 );
 
-		// usage statistics handling
-		add_action( 'w3tc_usage_statistics_of_request', array(
-				$this, 'w3tc_usage_statistics_of_request' ), 10, 1 );
-		add_filter( 'w3tc_usage_statistics_metrics', array(
-				$this, 'w3tc_usage_statistics_metrics' ) );
+		// usage statistics handling.
+		add_action( 'w3tc_usage_statistics_of_request', array( $this, 'w3tc_usage_statistics_of_request' ), 10, 1 );
+		add_filter( 'w3tc_usage_statistics_metrics', array( $this, 'w3tc_usage_statistics_metrics' ) );
 
-		/**
-		 * Start minify
-		 */
+		// Start minify.
 		if ( $this->can_minify() ) {
 			Util_Bus::add_ob_callback( 'minify', array( $this, 'ob_callback' ) );
 		}
 	}
 
+	/**
+	 * Initializes the Minify Plugin during the `init` action.
+	 *
+	 * @return void
+	 */
 	public function init() {
-		$url = Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR );
-		$parsed = parse_url( $url );
+		$url    = Util_Environment::filename_to_url( W3TC_CACHE_MINIFY_DIR );
+		$parsed = wp_parse_url( $url );
 		$prefix = '/' . trim( $parsed['path'], '/' ) . '/';
 
 		$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
-		if ( substr( $request_uri, 0, strlen( $prefix ) ) == $prefix ) {
+		if ( substr( $request_uri, 0, strlen( $prefix ) ) === $prefix ) {
 			$w3_minify = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
-			$filename = Util_Environment::remove_query_all( substr( $request_uri, strlen( $prefix ) ) );
+			$filename  = Util_Environment::remove_query_all( substr( $request_uri, strlen( $prefix ) ) );
 			$w3_minify->process( $filename );
 			exit();
 		}
 
-		if ( !empty( Util_Request::get_string( 'w3tc_minify' ) ) ) {
+		if ( ! empty( Util_Request::get_string( 'w3tc_minify' ) ) ) {
 			$w3_minify = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
 			$w3_minify->process( Util_Request::get_string( 'w3tc_minify' ) );
 			exit();
@@ -126,21 +134,21 @@ public function init() {
 	}
 
 	/**
-	 * Does disk cache cleanup
+	 * Cleans up the minify cache.
 	 *
 	 * @return void
 	 */
-	function cleanup() {
+	public function cleanup() {
 		$a = Dispatcher::component( 'Minify_Plugin_Admin' );
 		$a->cleanup();
 	}
 
 	/**
-	 * Cron schedules filter
+	 * Adds custom schedules for cron jobs related to minify cache cleanup.
 	 *
-	 * @param array $schedules Schedules.
+	 * @param array $schedules The existing cron schedules.
 	 *
-	 * @return array
+	 * @return array The updated cron schedules.
 	 */
 	public function cron_schedules( $schedules ) {
 		$c              = $this->_config;
@@ -163,7 +171,7 @@ public function cron_schedules( $schedules ) {
 	}
 
 	/**
-	 * Cron job for processing purging database cache.
+	 * Purges the minify cache via WP-Cron.
 	 *
 	 * @since 2.8.0
 	 *
@@ -175,62 +183,61 @@ public function w3tc_minifycache_purge_wpcron() {
 	}
 
 	/**
-	 * OB callback
+	 * Handles output buffering for minification and optimization.
+	 *
+	 * @param string $buffer The output buffer content.
 	 *
-	 * @param string  $buffer
-	 * @return string
+	 * @return string The processed buffer after minification.
+	 *
+	 * @throws \Exception If an error occurs during the minification process.
 	 */
-	function ob_callback( $buffer ) {
-		$enable = Util_Content::is_html( $buffer ) &&
-			$this->can_minify2( $buffer );
+	public function ob_callback( $buffer ) {
+		$enable = Util_Content::is_html( $buffer ) && $this->can_minify2( $buffer );
 		$enable = apply_filters( 'w3tc_minify_enable', $enable );
-		if ( !$enable )
+		if ( ! $enable ) {
 			return $buffer;
-
+		}
 
 		$this->minify_helpers = new _W3_MinifyHelpers( $this->_config );
 
-		/**
-		 * Replace script and style tags
-		 */
-		$js_enable = $this->_config->get_boolean( 'minify.js.enable' );
-		$css_enable = $this->_config->get_boolean( 'minify.css.enable' );
+		// Replace script and style tags.
+		$js_enable   = $this->_config->get_boolean( 'minify.js.enable' );
+		$css_enable  = $this->_config->get_boolean( 'minify.css.enable' );
 		$html_enable = $this->_config->get_boolean( 'minify.html.enable' );
 
 		if ( function_exists( 'is_feed' ) && is_feed() ) {
-			$js_enable = false;
+			$js_enable  = false;
 			$css_enable = false;
 		}
 
-		$js_enable = apply_filters( 'w3tc_minify_js_enable', $js_enable );
-		$css_enable = apply_filters( 'w3tc_minify_css_enable', $css_enable );
+		$js_enable   = apply_filters( 'w3tc_minify_js_enable', $js_enable );
+		$css_enable  = apply_filters( 'w3tc_minify_css_enable', $css_enable );
 		$html_enable = apply_filters( 'w3tc_minify_html_enable', $html_enable );
 
-		$head_prepend = '';
-		$body_prepend = '';
-		$body_append = '';
+		$head_prepend   = '';
+		$body_prepend   = '';
+		$body_append    = '';
 		$embed_extsrcjs = false;
-		$buffer = apply_filters( 'w3tc_minify_before', $buffer );
+		$buffer         = apply_filters( 'w3tc_minify_before', $buffer );
 
 		// If the minify cache folder is missing minify fails. This will generate the minify folder path if missing.
 		$minify_environment = Dispatcher::component( 'Minify_Environment' );
 		try {
 			$minify_environment->fix_on_wpadmin_request( $this->_config, true );
-		} catch ( \Exception $e ) {}
+		} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
+			// Exception.
+		}
 
 		if ( $this->_config->get_boolean( 'minify.auto' ) ) {
 			if ( $js_enable ) {
-				$minifier = new Minify_AutoJs( $this->_config,
-					$buffer, $this->minify_helpers );
-				$buffer = $minifier->execute();
-				$this->replaced_scripts =
-					$minifier->get_debug_minified_urls();
+				$minifier               = new Minify_AutoJs( $this->_config, $buffer, $this->minify_helpers );
+				$buffer                 = $minifier->execute();
+				$this->replaced_scripts = $minifier->get_debug_minified_urls();
 			}
 
 			if ( $css_enable ) {
-				$minifier = new Minify_AutoCss( $this->_config, $buffer,
-					$this->minify_helpers );
-				$buffer = $minifier->execute();
+				$minifier = new Minify_AutoCss( $this->_config, $buffer, $this->minify_helpers );
+				$buffer   = $minifier->execute();
 			}
 
 			$buffer = apply_filters( 'w3tc_minify_processed', $buffer );
@@ -239,101 +246,95 @@ function ob_callback( $buffer ) {
 				$style = $this->get_style_group( 'include' );
 
 				if ( $style['body'] ) {
-					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-css -->/', $buffer, $style['body'] ) )
+					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-css -->/', $buffer, $style['body'] ) ) {
 						$head_prepend .= $style['body'];
+					}
 
 					$this->remove_styles_group( $buffer, 'include' );
 				}
 
 				if ( $this->_config->getf_boolean( 'minify.css.http2push' ) ) {
-					$this->minify_helpers->http2_header_add( $style['url'],
-						'style' );
+					$this->minify_helpers->http2_header_add( $style['url'], 'style' );
 				}
 			}
 
 			if ( $js_enable ) {
 				$embed_type = $this->_config->get_string( 'minify.js.header.embed_type' );
-				$http2push = $this->_config->getf_boolean( 'minify.js.http2push' );
+				$http2push  = $this->_config->getf_boolean( 'minify.js.http2push' );
 
 				$script = $this->get_script_group( 'include', $embed_type );
 
 				if ( $script['body'] ) {
-					$embed_extsrcjs = $embed_type == 'extsrc' || $embed_type == 'asyncsrc'?true:$embed_extsrcjs;
+					$embed_extsrcjs = 'extsrc' === $embed_type || 'asyncsrc' === $embed_type ? true : $embed_extsrcjs;
 
-					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-js-head -->/', $buffer, $script['body'] ) )
+					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-js-head -->/', $buffer, $script['body'] ) ) {
 						$head_prepend .= $script['body'];
+					}
 
 					$this->remove_scripts_group( $buffer, 'include' );
 				}
 				if ( $http2push ) {
-					$this->minify_helpers->http2_header_add( $script['url'],
-						'script' );
+					$this->minify_helpers->http2_header_add( $script['url'], 'script' );
 				}
 
 				$embed_type = $this->_config->get_string( 'minify.js.body.embed_type' );
-				$script = $this->get_script_group( 'include-body', $embed_type );
+				$script     = $this->get_script_group( 'include-body', $embed_type );
 
 				if ( $script['body'] ) {
-					$embed_extsrcjs = $embed_type == 'extsrc' || $embed_type == 'asyncsrc'?true:$embed_extsrcjs;
+					$embed_extsrcjs = 'extsrc' === $embed_type || 'asyncsrc' === $embed_type ? true : $embed_extsrcjs;
 
-					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-js-body-start -->/', $buffer, $script['body'] ) )
+					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-js-body-start -->/', $buffer, $script['body'] ) ) {
 						$body_prepend .= $script['body'];
+					}
 
 					$this->remove_scripts_group( $buffer, 'include-body' );
 				}
 				if ( $http2push ) {
-					$this->minify_helpers->http2_header_add( $script['url'],
-						'script' );
+					$this->minify_helpers->http2_header_add( $script['url'], 'script' );
 				}
 
 				$embed_type = $this->_config->get_string( 'minify.js.footer.embed_type' );
-				$script = $this->get_script_group( 'include-footer', $embed_type );
+				$script     = $this->get_script_group( 'include-footer', $embed_type );
 
 				if ( $script['body'] ) {
-					$embed_extsrcjs = $embed_type == 'extsrc' || $embed_type == 'asyncsrc'?true:$embed_extsrcjs;
+					$embed_extsrcjs = 'extsrc' === $embed_type || 'asyncsrc' === $embed_type ? true : $embed_extsrcjs;
 
-					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-js-body-end -->/', $buffer, $script['body'] ) )
+					if ( $this->_custom_location_does_not_exist( '/<!-- W3TC-include-js-body-end -->/', $buffer, $script['body'] ) ) {
 						$body_append .= $script['body'];
+					}
 
 					$this->remove_scripts_group( $buffer, 'include-footer' );
 				}
 				if ( $http2push ) {
-					$this->minify_helpers->http2_header_add( $script['url'],
-						'script' );
+					$this->minify_helpers->http2_header_add( $script['url'], 'script' );
 				}
 			}
 		}
 
-		if ( $head_prepend != '' ) {
-			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui',
-				'\\0' . $head_prepend, $buffer, 1 );
+		if ( '' !== $head_prepend ) {
+			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui', '\\0' . $head_prepend, $buffer, 1 );
 		}
 
-		if ( $body_prepend != '' ) {
-			$buffer = preg_replace( '~<body(\s+[^>]*)*>~Ui',
-				'\\0' . $body_prepend, $buffer, 1 );
+		if ( '' !== $body_prepend ) {
+			$buffer = preg_replace( '~<body(\s+[^>]*)*>~Ui', '\\0' . $body_prepend, $buffer, 1 );
 		}
 
-		if ( $body_append != '' ) {
-			$buffer = preg_replace( '~<\\/body>~',
-				$body_append . '\\0', $buffer, 1 );
+		if ( '' !== $body_append ) {
+			$buffer = preg_replace( '~<\\/body>~', $body_append . '\\0', $buffer, 1 );
 		}
 
 		if ( $embed_extsrcjs ) {
-			$script = "
+			$script = '
 <script>
-" ."var extsrc=null;
-".'(function(){function j(){if(b&&g){document.write=k;document.writeln=l;var f=document.createElement("span");f.innerHTML=b;g.appendChild(f);b=""}}function d(){j();for(var f=document.getElementsByTagName("script"),c=0;c<f.length;c++){var e=f[c],h=e.getAttribute("asyncsrc");if(h){e.setAttribute("asyncsrc","");var a=document.createElement("script");a.async=!0;a.src=h;document.getElementsByTagName("head")[0].appendChild(a)}if(h=e.getAttribute("extsrc")){e.setAttribute("extsrc","");g=document.createElement("span");e.parentNode.insertBefore(g,e);document.write=function(a){b+=a};document.writeln=function(a){b+=a;b+="\n"};a=document.createElement("script");a.async=!0;a.src=h;/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent)?a.onreadystatechange=function(){("loaded"==this.readyState||"complete"==this.readyState)&&d()}:-1!=navigator.userAgent.indexOf("Firefox")||"onerror"in a?(a.onload=d,a.onerror=d):(a.onload=d,a.onreadystatechange=d);document.getElementsByTagName("head")[0].appendChild(a);return}}j();document.write=k;document.writeln=l;for(c=0;c<extsrc.complete.funcs.length;c++)extsrc.complete.funcs[c]()}function i(){arguments.callee.done||(arguments.callee.done=!0,d())}extsrc={complete:function(b){this.complete.funcs.push(b)}};extsrc.complete.funcs=[];var k=document.write,l=document.writeln,b="",g="";document.addEventListener&&document.addEventListener("DOMContentLoaded",i,!1);if(/WebKit/i.test(navigator.userAgent))var m=setInterval(function(){/loaded|complete/.test(document.readyState)&&(clearInterval(m),i())},10);window.onload=i})();' . "
+var extsrc=null;
+(function(){function j(){if(b&&g){document.write=k;document.writeln=l;var f=document.createElement("span");f.innerHTML=b;g.appendChild(f);b=""}}function d(){j();for(var f=document.getElementsByTagName("script"),c=0;c<f.length;c++){var e=f[c],h=e.getAttribute("asyncsrc");if(h){e.setAttribute("asyncsrc","");var a=document.createElement("script");a.async=!0;a.src=h;document.getElementsByTagName("head")[0].appendChild(a)}if(h=e.getAttribute("extsrc")){e.setAttribute("extsrc","");g=document.createElement("span");e.parentNode.insertBefore(g,e);document.write=function(a){b+=a};document.writeln=function(a){b+=a;b+="\n"};a=document.createElement("script");a.async=!0;a.src=h;/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent)?a.onreadystatechange=function(){("loaded"==this.readyState||"complete"==this.readyState)&&d()}:-1!=navigator.userAgent.indexOf("Firefox")||"onerror"in a?(a.onload=d,a.onerror=d):(a.onload=d,a.onreadystatechange=d);document.getElementsByTagName("head")[0].appendChild(a);return}}j();document.write=k;document.writeln=l;for(c=0;c<extsrc.complete.funcs.length;c++)extsrc.complete.funcs[c]()}function i(){arguments.callee.done||(arguments.callee.done=!0,d())}extsrc={complete:function(b){this.complete.funcs.push(b)}};extsrc.complete.funcs=[];var k=document.write,l=document.writeln,b="",g="";document.addEventListener&&document.addEventListener("DOMContentLoaded",i,!1);if(/WebKit/i.test(navigator.userAgent))var m=setInterval(function(){/loaded|complete/.test(document.readyState)&&(clearInterval(m),i())},10);window.onload=i})();
 </script>
-";
+';
 
-			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui',
-				'\\0' . $script, $buffer, 1 );
+			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui', '\\0' . $script, $buffer, 1 );
 		}
 
-		/**
-		 * Minify HTML/Feed
-		 */
+		// Minify HTML/Feed.
 		if ( $html_enable ) {
 			try {
 				$buffer = $this->minify_html( $buffer );
@@ -345,42 +346,62 @@ function ob_callback( $buffer ) {
 		return $buffer;
 	}
 
+	/**
+	 * Adds the minify flush item to the WordPress admin bar menu.
+	 *
+	 * @param array $menu_items Array of existing admin bar menu items.
+	 *
+	 * @return array Modified menu items with the minify cache option included.
+	 */
 	public function w3tc_admin_bar_menu( $menu_items ) {
 		$menu_items['20210.minify'] = array(
-			'id' => 'w3tc_flush_minify',
+			'id'     => 'w3tc_flush_minify',
 			'parent' => 'w3tc_flush',
-			'title' => __( 'Minify Cache', 'w3-total-cache' ),
-			'href' => wp_nonce_url( admin_url(
-					'admin.php?page=w3tc_dashboard&amp;w3tc_flush_minify' ),
-				'w3tc' )
+			'title'  => __( 'Minify Cache', 'w3-total-cache' ),
+			'href'   => wp_nonce_url(
+				admin_url(
+					'admin.php?page=w3tc_dashboard&amp;w3tc_flush_minify'
+				),
+				'w3tc'
+			),
 		);
 
 		return $menu_items;
 	}
 
-	function w3tc_footer_comment( $strings ) {
+	/**
+	 * Appends a footer comment regarding minification to the HTML strings.
+	 *
+	 * @param array $strings Array of footer comments to append.
+	 *
+	 * @return array Modified array of footer comments.
+	 */
+	public function w3tc_footer_comment( $strings ) {
 		$strings[] = sprintf(
-			__( 'Minified using %s%s', 'w3-total-cache' ),
+			// Translators: 1 engine name, 2 reject reason.
+			__(
+				'Minified using %1$s%2$s',
+				'w3-total-cache'
+			),
 			Cache::engine_name( $this->_config->get_string( 'minify.engine' ) ),
-			( $this->minify_reject_reason != ''
-				? sprintf( ' (%s)', $this->minify_reject_reason )
-				: '' ) );
+			( '' !== $this->minify_reject_reason ? sprintf( ' (%s)', $this->minify_reject_reason ) : '' )
+		);
 
 		if ( $this->_config->get_boolean( 'minify.debug' ) ) {
 			$strings[] = '';
 			$strings[] = 'Minify debug info:';
-			$strings[] = sprintf( "%s%s", str_pad( 'Theme: ', 20 ), $this->get_theme() );
-			$strings[] = sprintf( "%s%s", str_pad( 'Template: ', 20 ), $this->get_template() );
+			$strings[] = sprintf( '%s%s', str_pad( 'Theme: ', 20 ), $this->get_theme() );
+			$strings[] = sprintf( '%s%s', str_pad( 'Template: ', 20 ), $this->get_template() );
 
 			if ( $this->error ) {
-				$strings[] = sprintf( "%s%s", str_pad( 'Errors: ', 20 ), $this->error );
+				$strings[] = sprintf( '%s%s', str_pad( 'Errors: ', 20 ), $this->error );
 			}
 
 			if ( count( $this->replaced_styles ) ) {
 				$strings[] = 'Replaced CSS files:';
 
 				foreach ( $this->replaced_styles as $index => $file ) {
-					$strings[] = sprintf( "%d. %s", $index + 1, Util_Content::escape_comment( $file ) );
+					$strings[] = sprintf( '%d. %s', $index + 1, Util_Content::escape_comment( $file ) );
 				}
 			}
 
@@ -391,56 +412,67 @@ function w3tc_footer_comment( $strings ) {
 					$strings[] = sprintf( "%d. %s\r\n", $index + 1, Util_Content::escape_comment( $file ) );
 				}
 			}
+
 			$strings[] = '';
 		}
 
 		return $strings;
 	}
+
 	/**
-	 * Checks to see if pattern exists in source if so replaces it with the provided script
-	 * and returns false. If pattern does not exists returns true.
+	 * Checks if a custom minification location does not exist.
 	 *
-	 * @param unknown $pattern
-	 * @param unknown $source
-	 * @param unknown $script
-	 * @return bool
+	 * @param string $pattern Regular expression pattern to search.
+	 * @param string $source  Source string to check.
+	 * @param string $script  Replacement script for the match.
+	 *
+	 * @return bool True if the location does not exist, false otherwise.
 	 */
-	function _custom_location_does_not_exist( $pattern, &$source, $script ) {
-		$count = 0;
+	public function _custom_location_does_not_exist( $pattern, &$source, $script ) {
+		$count  = 0;
 		$source = preg_replace( $pattern, $script, $source, 1, $count );
-		return $count==0;
+		return 0 === $count;
 	}
 
 	/**
-	 * Removes style tags from the source
+	 * Removes specified CSS files from the provided content.
+	 *
+	 * @param string $content HTML content to search for CSS references.
+	 * @param array  $files   List of CSS files to remove.
 	 *
-	 * @param string  $content
-	 * @param array   $files
 	 * @return void
 	 */
-	function remove_styles( &$content, $files ) {
-		$regexps = array();
+	public function remove_styles( &$content, $files ) {
+		$regexps         = array();
 		$home_url_regexp = Util_Environment::home_url_regexp();
 
 		$path = '';
-		if ( Util_Environment::is_wpmu() && !Util_Environment::is_wpmu_subdomain() )
+		if ( Util_Environment::is_wpmu() && ! Util_Environment::is_wpmu_subdomain() ) {
 			$path = ltrim( Util_Environment::home_url_uri(), '/' );
+		}
 
 		foreach ( $files as $file ) {
-			if ( $path && strpos( $file, $path ) === 0 )
+			if ( $path && strpos( $file, $path ) === 0 ) {
 				$file = substr( $file, strlen( $path ) );
+			}
 
 			$this->replaced_styles[] = $file;
 
-			if ( Util_Environment::is_url( $file ) && !preg_match( '~' . $home_url_regexp . '~i', $file ) ) {
-				// external CSS files
+			if ( Util_Environment::is_url( $file ) && ! preg_match( '~' . $home_url_regexp . '~i', $file ) ) {
+				// external CSS files.
 				$regexps[] = Util_Environment::preg_quote( $file );
 			} else {
-				// local CSS files
+				// local CSS files.
 				$file = ltrim( $file, '/' );
-				if ( home_url() == site_url() && ltrim( Util_Environment::site_url_uri(), '/' ) && strpos( $file, ltrim( Util_Environment::site_url_uri(), '/' ) ) === 0 )
+				if (
+					home_url() === site_url() &&
+					ltrim( Util_Environment::site_url_uri(), '/' ) &&
+					strpos( $file, ltrim( Util_Environment::site_url_uri(), '/' ) ) === 0
+				) {
 					$file = str_replace( ltrim( Util_Environment::site_url_uri(), '/' ), '', $file );
-				$file = ltrim( preg_replace( '~' . $home_url_regexp . '~i', '', $file ), '/\\' );
+				}
+
+				$file      = ltrim( preg_replace( '~' . $home_url_regexp . '~i', '', $file ), '/\\' );
 				$regexps[] = '(' . $home_url_regexp . ')?/?' . Util_Environment::preg_quote( $file );
 			}
 		}
@@ -454,18 +486,19 @@ function remove_styles( &$content, $files ) {
 	}
 
 	/**
-	 * Remove script tags from the source
+	 * Removes specified JavaScript files from the provided content.
+	 *
+	 * @param string $content HTML content to search for script references.
+	 * @param array  $files   List of JavaScript files to remove.
 	 *
-	 * @param string  $content
-	 * @param array   $files
 	 * @return void
 	 */
-	function remove_scripts( &$content, $files ) {
-		$regexps = array();
+	public function remove_scripts( &$content, $files ) {
+		$regexps         = array();
 		$home_url_regexp = Util_Environment::home_url_regexp();
 
 		$path = '';
-		if ( Util_Environment::is_wpmu() && !Util_Environment::is_wpmu_subdomain() ) {
+		if ( Util_Environment::is_wpmu() && ! Util_Environment::is_wpmu_subdomain() ) {
 			$path = ltrim( Util_Environment::network_home_url_uri(), '/' );
 		}
 
@@ -476,19 +509,21 @@ function remove_scripts( &$content, $files ) {
 
 			$this->replaced_scripts[] = $file;
 
-			if ( Util_Environment::is_url( $file ) && !preg_match( '~' . $home_url_regexp . '~i', $file ) ) {
-				// external JS files
+			if ( Util_Environment::is_url( $file ) && ! preg_match( '~' . $home_url_regexp . '~i', $file ) ) {
+				// external JS files.
 				$regexps[] = Util_Environment::preg_quote( $file );
 			} else {
-				// local JS files
+				// local JS files.
 				$file = ltrim( $file, '/' );
-				if ( home_url() == site_url() &&
-						ltrim( Util_Environment::site_url_uri(), '/' ) &&
-						strpos( $file, ltrim( Util_Environment::site_url_uri(), '/' ) ) === 0 ) {
+				if (
+					home_url() === site_url() &&
+					ltrim( Util_Environment::site_url_uri(), '/' ) &&
+					strpos( $file, ltrim( Util_Environment::site_url_uri(), '/' ) ) === 0
+				) {
 					$file = str_replace( ltrim( Util_Environment::site_url_uri(), '/' ), '', $file );
 				}
 
-				$file = ltrim( preg_replace( '~' . $home_url_regexp . '~i', '', $file ), '/\\' );
+				$file      = ltrim( preg_replace( '~' . $home_url_regexp . '~i', '', $file ), '/\\' );
 				$regexps[] = '(' . $home_url_regexp . ')?/?' . Util_Environment::preg_quote( $file );
 			}
 		}
@@ -499,61 +534,64 @@ function remove_scripts( &$content, $files ) {
 	}
 
 	/**
-	 * Removes style tag from the source for group
+	 * Removes a group of CSS files for a specified location.
+	 *
+	 * @param string $content  HTML content to search for CSS references.
+	 * @param string $location Location identifier for the CSS group.
 	 *
-	 * @param string  $content
-	 * @param string  $location
 	 * @return void
 	 */
-	function remove_styles_group( &$content, $location ) {
-		$theme = $this->get_theme();
+	public function remove_styles_group( &$content, $location ) {
+		$theme    = $this->get_theme();
 		$template = $this->get_template();
 
-		$files = array();
+		$files  = array();
 		$groups = $this->_config->get_array( 'minify.css.groups' );
 
-		if ( isset( $groups[$theme]['default'][$location]['files'] ) ) {
-			$files = (array) $groups[$theme]['default'][$location]['files'];
+		if ( isset( $groups[ $theme ]['default'][ $location ]['files'] ) ) {
+			$files = (array) $groups[ $theme ]['default'][ $location ]['files'];
 		}
 
-		if ( $template != 'default' && isset( $groups[$theme][$template][$location]['files'] ) ) {
-			$files = array_merge( $files, (array) $groups[$theme][$template][$location]['files'] );
+		if ( 'default' !== $template && isset( $groups[ $theme ][ $template ][ $location ]['files'] ) ) {
+			$files = array_merge( $files, (array) $groups[ $theme ][ $template ][ $location ]['files'] );
 		}
 
 		$this->remove_styles( $content, $files );
 	}
 
 	/**
-	 * Removes script tags from the source for group
+	 * Removes a group of JavaScript files for a specified location.
+	 *
+	 * @param string $content  HTML content to search for script references.
+	 * @param string $location Location identifier for the script group.
 	 *
-	 * @param string  $content
-	 * @param string  $location
 	 * @return void
 	 */
-	function remove_scripts_group( &$content, $location ) {
-		$theme = $this->get_theme();
+	public function remove_scripts_group( &$content, $location ) {
+		$theme    = $this->get_theme();
 		$template = $this->get_template();
-		$files = array();
-		$groups = $this->_config->get_array( 'minify.js.groups' );
+		$files    = array();
+		$groups   = $this->_config->get_array( 'minify.js.groups' );
 
-		if ( isset( $groups[$theme]['default'][$location]['files'] ) ) {
-			$files = (array) $groups[$theme]['default'][$location]['files'];
+		if ( isset( $groups[ $theme ]['default'][ $location ]['files'] ) ) {
+			$files = (array) $groups[ $theme ]['default'][ $location ]['files'];
 		}
 
-		if ( $template != 'default' && isset( $groups[$theme][$template][$location]['files'] ) ) {
-			$files = array_merge( $files, (array) $groups[$theme][$template][$location]['files'] );
+		if ( 'default' !== $template && isset( $groups[ $theme ][ $template ][ $location ]['files'] ) ) {
+			$files = array_merge( $files, (array) $groups[ $theme ][ $template ][ $location ]['files'] );
 		}
 
 		$this->remove_scripts( $content, $files );
 	}
 
 	/**
-	 * Minifies HTML
+	 * Minifies the provided HTML content.
 	 *
-	 * @param string  $html
-	 * @return string
+	 * @param string $html HTML content to minify.
+	 *
+	 * @return string Minified HTML content.
 	 */
-	function minify_html( $html ) {
+	public function minify_html( $html ) {
 		$w3_minifier = Dispatcher::component( 'Minify_ContentMinifier' );
 
 		$ignored_comments = $this->_config->get_array( 'minify.html.comments.ignore' );
@@ -568,12 +606,12 @@ function minify_html( $html ) {
 		if ( $this->_config->get_boolean( 'minify.html.inline.js' ) ) {
 			$js_engine = $this->_config->get_string( 'minify.js.engine' );
 
-			if ( !$w3_minifier->exists( $js_engine ) || !$w3_minifier->available( $js_engine ) ) {
+			if ( ! $w3_minifier->exists( $js_engine ) || ! $w3_minifier->available( $js_engine ) ) {
 				$js_engine = 'js';
 			}
 
 			$js_minifier = $w3_minifier->get_minifier( $js_engine );
-			$js_options = $w3_minifier->get_options( $js_engine );
+			$js_options  = $w3_minifier->get_options( $js_engine );
 
 			$w3_minifier->init( $js_engine );
 
@@ -583,12 +621,12 @@ function minify_html( $html ) {
 		if ( $this->_config->get_boolean( 'minify.html.inline.css' ) ) {
 			$css_engine = $this->_config->get_string( 'minify.css.engine' );
 
-			if ( !$w3_minifier->exists( $css_engine ) || !$w3_minifier->available( $css_engine ) ) {
+			if ( ! $w3_minifier->exists( $css_engine ) || ! $w3_minifier->available( $css_engine ) ) {
 				$css_engine = 'css';
 			}
 
 			$css_minifier = $w3_minifier->get_minifier( $css_engine );
-			$css_options = $w3_minifier->get_options( $css_engine );
+			$css_options  = $w3_minifier->get_options( $css_engine );
 
 			$w3_minifier->init( $css_engine );
 
@@ -597,7 +635,7 @@ function minify_html( $html ) {
 
 		$engine = $this->_config->get_string( 'minify.html.engine' );
 
-		if ( !$w3_minifier->exists( $engine ) || !$w3_minifier->available( $engine ) ) {
+		if ( ! $w3_minifier->exists( $engine ) || ! $w3_minifier->available( $engine ) ) {
 			$engine = 'html';
 		}
 
@@ -606,7 +644,7 @@ function minify_html( $html ) {
 		}
 
 		$minifier = $w3_minifier->get_minifier( $engine );
-		$options = $w3_minifier->get_options( $engine );
+		$options  = $w3_minifier->get_options( $engine );
 
 		$w3_minifier->init( $engine );
 
@@ -620,14 +658,14 @@ function minify_html( $html ) {
 	}
 
 	/**
-	 * Returns current theme
+	 * Retrieves the current theme identifier.
 	 *
-	 * @return string
+	 * @return string Theme identifier.
 	 */
-	function get_theme() {
+	public function get_theme() {
 		static $theme = null;
 
-		if ( $theme === null ) {
+		if ( null === $theme ) {
 			$theme = Util_Theme::get_theme_key( get_theme_root(), get_template(), get_stylesheet() );
 		}
 
@@ -635,39 +673,42 @@ function get_theme() {
 	}
 
 	/**
-	 * Returns current template
+	 * Retrieves the current template identifier.
+	 *
+	 * phpcs:disable WordPress.CodeAnalysis.AssignmentInCondition.Found
+	 * phpcs:disable Squiz.PHP.DisallowMultipleAssignments.Found
 	 *
-	 * @return string
+	 * @return string Template identifier.
 	 */
-	function get_template() {
+	public function get_template() {
 		static $template = null;
 
-		if ( $template === null ) {
+		if ( null === $template ) {
 			$template_file = 'index.php';
 			switch ( true ) {
-			case ( is_404() && ( $template_file = get_404_template() ) ):
-			case ( is_search() && ( $template_file = get_search_template() ) ):
-			case ( is_tax() && ( $template_file = get_taxonomy_template() ) ):
-			case ( is_front_page() && function_exists( 'get_front_page_template' ) && $template_file = get_front_page_template() ):
-			case ( is_home() && ( $template_file = get_home_template() ) ):
-			case ( is_attachment() && ( $template_file = get_attachment_template() ) ):
-			case ( is_single() && ( $template_file = get_single_template() ) ):
-			case ( is_page() && ( $template_file = get_page_template() ) ):
-			case ( is_category() && ( $template_file = get_category_template() ) ):
-			case ( is_tag() && ( $template_file = get_tag_template() ) ):
-			case ( is_author() && ( $template_file = get_author_template() ) ):
-			case ( is_date() && ( $template_file = get_date_template() ) ):
-			case ( is_archive() && ( $template_file = get_archive_template() ) ):
-			case ( is_paged() && ( $template_file = get_paged_template() ) ):
-				break;
-
-			default:
-				if ( function_exists( 'get_index_template' ) ) {
-					$template_file = get_index_template();
-				} else {
-					$template_file = 'index.php';
-				}
-				break;
+				case ( is_404() && ( $template_file = get_404_template() ) ):
+				case ( is_search() && ( $template_file = get_search_template() ) ):
+				case ( is_tax() && ( $template_file = get_taxonomy_template() ) ):
+				case ( is_front_page() && function_exists( 'get_front_page_template' ) && $template_file = get_front_page_template() ):
+				case ( is_home() && ( $template_file = get_home_template() ) ):
+				case ( is_attachment() && ( $template_file = get_attachment_template() ) ):
+				case ( is_single() && ( $template_file = get_single_template() ) ):
+				case ( is_page() && ( $template_file = get_page_template() ) ):
+				case ( is_category() && ( $template_file = get_category_template() ) ):
+				case ( is_tag() && ( $template_file = get_tag_template() ) ):
+				case ( is_author() && ( $template_file = get_author_template() ) ):
+				case ( is_date() && ( $template_file = get_date_template() ) ):
+				case ( is_archive() && ( $template_file = get_archive_template() ) ):
+				case ( is_paged() && ( $template_file = get_query_template( 'paged' ) ) ):
+					break;
+
+				default:
+					if ( function_exists( 'get_index_template' ) ) {
+						$template_file = get_index_template();
+					} else {
+						$template_file = 'index.php';
+					}
+					break;
 			}
 
 			$template = basename( $template_file, '.php' );
@@ -677,63 +718,71 @@ function get_template() {
 	}
 
 	/**
-	 * Returns style tag
+	 * Generates the HTML markup for including a stylesheet.
+	 *
+	 * phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
 	 *
-	 * @param string  $url
-	 * @param boolean $import
-	 * @param boolean $use_style
-	 * @return string
+	 * @param string $url        URL of the stylesheet.
+	 * @param bool   $import     Whether to use @import syntax.
+	 * @param bool   $use_style  Whether to wrap @import in <style> tags.
+	 *
+	 * @return string Generated HTML markup.
 	 */
-	function get_style( $url, $import = false, $use_style = true ) {
+	public function get_style( $url, $import = false, $use_style = true ) {
 		if ( $import && $use_style ) {
-			return "<style media=\"all\">@import url(\"" . $url . "\");</style>\r\n";
-		} elseif ( $import && !$use_style ) {
-			return "@import url(\"" . $url . "\");\r\n";
-		}else {
-			return "<link rel=\"stylesheet\" href=\"" . str_replace( '&', '&amp;', $url ) . "\" media=\"all\" />\r\n";
+			return '<style media="all">@import url("' . $url . "\");</style>\r\n";
+		} elseif ( $import && ! $use_style ) {
+			return '@import url("' . $url . "\");\r\n";
+		} else {
+			return '<link rel="stylesheet" href="' . str_replace( '&', '&amp;', $url ) . "\" media=\"all\" />\r\n";
 		}
 	}
 
 	/**
-	 * Returns style tag for style group
+	 * Retrieves the details of a grouped CSS style by location.
 	 *
-	 * @param string  $location
-	 * @return array
+	 * @param string $location Location identifier for the style group.
+	 *
+	 * @return array Associative array containing 'url' and 'body' keys.
 	 */
-	function get_style_group( $location ) {
-		$style = false;
-		$type = 'css';
-		$groups = $this->_config->get_array( 'minify.css.groups' );
-		$theme = $this->get_theme();
+	public function get_style_group( $location ) {
+		$style    = false;
+		$type     = 'css';
+		$groups   = $this->_config->get_array( 'minify.css.groups' );
+		$theme    = $this->get_theme();
 		$template = $this->get_template();
 
-		if ( $template != 'default' && empty( $groups[$theme][$template][$location]['files'] ) ) {
+		if ( 'default' !== $template && empty( $groups[ $theme ][ $template ][ $location ]['files'] ) ) {
 			$template = 'default';
 		}
 
 		$return = array(
-			'url' => null,
-			'body' => ''
+			'url'  => null,
+			'body' => '',
 		);
 
-		if ( !empty( $groups[$theme][$template][$location]['files'] ) ) {
+		if ( ! empty( $groups[ $theme ][ $template ][ $location ]['files'] ) ) {
 			if ( $this->_config->get_boolean( 'minify.css.embed' ) ) {
-				$minify = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
-				$minify_filename = $this->get_minify_manual_filename(
-					$theme, $template, $location, $type );
+				$minify          = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
+				$minify_filename = $this->get_minify_manual_filename( $theme, $template, $location, $type );
 
 				$m = $minify->process( $minify_filename, true );
-				if ( isset( $m['content'] ) )
+				if ( isset( $m['content'] ) ) {
 					$style = $m['content'];
-				else
+				} else {
 					$style = 'not set';
+				}
 
 				$return['body'] = "<style media=\"all\">$style</style>\r\n";
 			} else {
 				$return['url'] = $this->get_minify_manual_url( $theme, $template, $location, $type );
 
 				if ( $return['url'] ) {
-					$import = ( isset( $groups[$theme][$template][$location]['import'] ) ? (boolean) $groups[$theme][$template][$location]['import'] : false );
+					$import = (
+						isset( $groups[ $theme ][ $template ][ $location ]['import'] ) ?
+						(bool) $groups[ $theme ][ $template ][ $location ]['import'] :
+						false
+					);
 
 					$return['body'] = $this->get_style( $return['url'], $import );
 				}
@@ -744,34 +793,34 @@ function get_style_group( $location ) {
 	}
 
 	/**
-	 * Returns script tag for script group
+	 * Retrieves the script group for the specified location and embed type.
 	 *
-	 * @param string  $location
-	 * @param string  $embed_type
-	 * @return array
+	 * @param string $location   The location of the scripts (e.g., 'header', 'footer').
+	 * @param string $embed_type The embed type, defaults to 'blocking'.
+	 *
+	 * @return array Associative array containing 'url' and 'body'.
 	 */
-	function get_script_group( $location, $embed_type = 'blocking' ) {
-		$script = false;
-		$fileType = 'js';
-		$theme = $this->get_theme();
-		$template = $this->get_template();
-		$groups = $this->_config->get_array( 'minify.js.groups' );
-
-		if ( $template != 'default' && empty( $groups[$theme][$template][$location]['files'] ) ) {
+	public function get_script_group( $location, $embed_type = 'blocking' ) {
+		$script    = false;
+		$file_type = 'js';
+		$theme     = $this->get_theme();
+		$template  = $this->get_template();
+		$groups    = $this->_config->get_array( 'minify.js.groups' );
+
+		if ( 'default' !== $template && empty( $groups[ $theme ][ $template ][ $location ]['files'] ) ) {
 			$template = 'default';
 		}
 
 		$return = array(
-			'url' => null,
-			'body' => ''
+			'url'  => null,
+			'body' => '',
 		);
 
-		if ( !empty( $groups[$theme][$template][$location]['files'] ) ) {
-			$return['url'] = $this->get_minify_manual_url( $theme, $template, $location, $fileType );
+		if ( ! empty( $groups[ $theme ][ $template ][ $location ]['files'] ) ) {
+			$return['url'] = $this->get_minify_manual_url( $theme, $template, $location, $file_type );
 
 			if ( $return['url'] ) {
-				$return['body'] = $this->minify_helpers->generate_script_tag(
-					$return['url'], $embed_type );
+				$return['body'] = $this->minify_helpers->generate_script_tag( $return['url'], $embed_type );
 			}
 		}
 
@@ -779,51 +828,66 @@ function get_script_group( $location, $embed_type = 'blocking' ) {
 	}
 
 	/**
-	 * Returns style tag for custom files
+	 * Generates a style tag or URL for custom styles.
+	 *
+	 * @param array $files         Array of file paths for the styles.
+	 * @param bool  $embed_to_html Whether to embed styles directly in HTML.
 	 *
-	 * @return string
+	 * @return array Associative array containing 'url' and 'body'.
 	 */
-	function get_style_custom( $files, $embed_to_html = false ) {
-		return $this->minify_helpers->generate_css_style_tag(
-			$files, $embed_to_html );
+	public function get_style_custom( $files, $embed_to_html = false ) {
+		return $this->minify_helpers->generate_css_style_tag( $files, $embed_to_html );
 	}
 
 	/**
-	 * Generates filename for minify manual resource
+	 * Retrieves the manual filename for minified resources.
+	 *
+	 * @param string $theme    The theme name.
+	 * @param string $template The template name.
+	 * @param string $location The location identifier.
+	 * @param string $type     The resource type ('js' or 'css').
+	 *
+	 * @return string|false The generated filename or false if not available.
 	 */
-	function get_minify_manual_filename( $theme, $template, $location, $type ) {
+	public function get_minify_manual_filename( $theme, $template, $location, $type ) {
 		$minify = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
-		$id = $minify->get_id_group( $theme, $template, $location, $type );
-		if ( !$id )
+		$id     = $minify->get_id_group( $theme, $template, $location, $type );
+		if ( ! $id ) {
 			return false;
+		}
 
-		return $theme . '.' . $template . '.' . $location . '.'. $id .
-			'.' . $type;
+		return $theme . '.' . $template . '.' . $location . '.' . $id . '.' . $type;
 	}
 
 	/**
-	 * Generates URL for minify manual resource
+	 * Retrieves the manual URL for minified resources.
+	 *
+	 * @param string $theme    The theme name.
+	 * @param string $template The template name.
+	 * @param string $location The location identifier.
+	 * @param string $type     The resource type ('js' or 'css').
+	 *
+	 * @return string The generated URL.
 	 */
-	function get_minify_manual_url( $theme, $template, $location, $type ) {
-		return Minify_Core::minified_url( $this->get_minify_manual_filename(
-			$theme, $template, $location, $type ) );
+	public function get_minify_manual_url( $theme, $template, $location, $type ) {
+		return Minify_Core::minified_url( $this->get_minify_manual_filename( $theme, $template, $location, $type ) );
 	}
 
 	/**
-	 * Returns array of minify URLs
+	 * Retrieves an array of all URLs for minified resources.
 	 *
-	 * @return array
+	 * @return array Array of URLs.
 	 */
-	function get_urls() {
+	public function get_urls() {
 		$files = array();
 
-		$js_groups = $this->_config->get_array( 'minify.js.groups' );
+		$js_groups  = $this->_config->get_array( 'minify.js.groups' );
 		$css_groups = $this->_config->get_array( 'minify.css.groups' );
 
 		foreach ( $js_groups as $js_theme => $js_templates ) {
 			foreach ( $js_templates as $js_template => $js_locations ) {
 				foreach ( (array) $js_locations as $js_location => $js_config ) {
-					if ( !empty( $js_config['files'] ) ) {
+					if ( ! empty( $js_config['files'] ) ) {
 						$files[] = $this->get_minify_manual_url( $js_theme, $js_template, $js_location, 'js' );
 					}
 				}
@@ -833,7 +897,7 @@ function get_urls() {
 		foreach ( $css_groups as $css_theme => $css_templates ) {
 			foreach ( $css_templates as $css_template => $css_locations ) {
 				foreach ( (array) $css_locations as $css_location => $css_config ) {
-					if ( !empty( $css_config['files'] ) ) {
+					if ( ! empty( $css_config['files'] ) ) {
 						$files[] = $this->get_minify_manual_url( $css_theme, $css_template, $css_location, 'css' );
 					}
 				}
@@ -844,87 +908,69 @@ function get_urls() {
 	}
 
 	/**
-	 * Check if we can do minify logic
+	 * Checks whether minification can be applied based on the current environment.
 	 *
-	 * @return boolean
+	 * @return bool True if minification can proceed, false otherwise.
 	 */
-	function can_minify() {
-		/**
-		 * Skip if doint AJAX
-		 */
+	public function can_minify() {
+		// Skip if doint AJAX.
 		if ( defined( 'DOING_AJAX' ) ) {
 			$this->minify_reject_reason = 'Doing AJAX';
 
 			return false;
 		}
 
-		/**
-		 * Skip if doing cron
-		 */
+		// Skip if doing cron.
 		if ( defined( 'DOING_CRON' ) ) {
 			$this->minify_reject_reason = 'Doing cron';
 
 			return false;
 		}
 
-		/**
-		 * Skip if APP request
-		 */
+		// Skip if APP request.
 		if ( defined( 'APP_REQUEST' ) ) {
 			$this->minify_reject_reason = 'Application request';
 
 			return false;
 		}
 
-		/**
-		 * Skip if XMLRPC request
-		 */
+		// Skip if XMLRPC request.
 		if ( defined( 'XMLRPC_REQUEST' ) ) {
 			$this->minify_reject_reason = 'XMLRPC request';
 
 			return false;
 		}
 
-		/**
-		 * Skip if Admin
-		 */
+		// Skip if Admin.
 		if ( defined( 'WP_ADMIN' ) ) {
 			$this->minify_reject_reason = 'wp-admin';
 
 			return false;
 		}
 
-		/**
-		 * Check for WPMU's and WP's 3.0 short init
-		 */
+		// Check for WPMU's and WP's 3.0 short init.
 		if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
 			$this->minify_reject_reason = 'Short init';
 
 			return false;
 		}
 
-		/**
-		 * Check User agent
-		 */
-		if ( !$this->check_ua() ) {
+		// Check User agent.
+		if ( ! $this->check_ua() ) {
 			$this->minify_reject_reason = 'User agent is rejected';
 
 			return false;
 		}
 
-		/**
-		 * Check request URI
-		 */
-		if ( !$this->check_request_uri() ) {
+		// Check request URI.
+		if ( ! $this->check_request_uri() ) {
 			$this->minify_reject_reason = 'Request URI is rejected';
 
 			return false;
 		}
 
-		/**
-		 * Skip if user is logged in
-		 */
-		if ( $this->_config->get_boolean( 'minify.reject.logged' ) && !$this->check_logged_in() ) {
+		// Skip if user is logged in.
+		if ( $this->_config->get_boolean( 'minify.reject.logged' ) && ! $this->check_logged_in() ) {
 			$this->minify_reject_reason = 'User is logged in';
 
 			return false;
@@ -934,24 +980,21 @@ function can_minify() {
 	}
 
 	/**
-	 * Returns true if we can minify
+	 * Checks whether minification can be applied to the provided buffer.
+	 *
+	 * @param string $buffer The buffer to check.
 	 *
-	 * @param string  $buffer
-	 * @return string
+	 * @return bool True if the buffer can be minified, false otherwise.
 	 */
-	function can_minify2( $buffer ) {
-		/**
-		 * Check for DONOTMINIFY constant
-		 */
+	public function can_minify2( $buffer ) {
+		// Check for DONOTMINIFY constant.
 		if ( defined( 'DONOTMINIFY' ) && DONOTMINIFY ) {
 			$this->minify_reject_reason = 'DONOTMINIFY constant is defined';
 
 			return false;
 		}
 
-		/**
-		 * Check feed minify
-		 */
+		// Check feed minify.
 		if ( $this->_config->get_boolean( 'minify.html.reject.feed' ) && function_exists( 'is_feed' ) && is_feed() ) {
 			$this->minify_reject_reason = 'Feed is rejected';
 
@@ -962,17 +1005,20 @@ function can_minify2( $buffer ) {
 	}
 
 	/**
-	 * Checks User Agent
+	 * Validates the user agent for minification.
 	 *
-	 * @return boolean
+	 * @return bool True if the user agent is allowed, false otherwise.
 	 */
-	function check_ua() {
-		$uas = array_merge( $this->_config->get_array( 'minify.reject.ua' ), array(
-				W3TC_POWERED_BY
-			) );
+	public function check_ua() {
+		$uas = array_merge(
+			$this->_config->get_array( 'minify.reject.ua' ),
+			array(
+				W3TC_POWERED_BY,
+			)
+		);
 
 		foreach ( $uas as $ua ) {
-			if ( !empty( $ua ) ) {
+			if ( ! empty( $ua ) ) {
 				if ( stristr( isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '', $ua ) !== false ) {
 					return false;
 				}
@@ -983,28 +1029,29 @@ function check_ua() {
 	}
 
 	/**
-	 * Check if user is logged in
+	 * Checks whether the current user is logged in.
 	 *
-	 * @return boolean
+	 * @return bool True if the user is not logged in, false otherwise.
 	 */
-	function check_logged_in() {
+	public function check_logged_in() {
 		foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
-			if ( strpos( $cookie_name, 'wordpress_logged_in' ) === 0 )
+			if ( strpos( $cookie_name, 'wordpress_logged_in' ) === 0 ) {
 				return false;
+			}
 		}
 
 		return true;
 	}
 
 	/**
-	 * Checks request URI
+	 * Validates the request URI for minification.
 	 *
-	 * @return boolean
+	 * @return bool True if the URI is valid, false otherwise.
 	 */
-	function check_request_uri() {
+	public function check_request_uri() {
 		$auto_reject_uri = array(
 			'wp-login',
-			'wp-register'
+			'wp-register',
 		);
 
 		foreach ( $auto_reject_uri as $uri ) {
@@ -1025,35 +1072,57 @@ function check_request_uri() {
 			}
 		}
 
-		if ( Util_Request::get_string( 'wp_customize' ) )
+		if ( Util_Request::get_string( 'wp_customize' ) ) {
 			return false;
+		}
 
 		return true;
 	}
 
-
-
+	/**
+	 * Collects usage statistics for the current request.
+	 *
+	 * @param mixed $storage The storage object or array for the statistics.
+	 *
+	 * @return void
+	 */
 	public function w3tc_usage_statistics_of_request( $storage ) {
 		$o = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
 		$o->w3tc_usage_statistics_of_request( $storage );
 	}
 
-
-
+	/**
+	 * Adds minification-related metrics to the usage statistics.
+	 *
+	 * @param array $metrics Existing metrics array.
+	 *
+	 * @return array Modified metrics array.
+	 */
 	public function w3tc_usage_statistics_metrics( $metrics ) {
-		return array_merge( $metrics, array(
+		return array_merge(
+			$metrics,
+			array(
 				'minify_requests_total',
-				'minify_original_length_css', 'minify_output_length_css',
-				'minify_original_length_js', 'minify_output_length_js', ) );
+				'minify_original_length_css',
+				'minify_output_length_css',
+				'minify_original_length_js',
+				'minify_output_length_js',
+			)
+		);
 	}
 
-
-
+	/**
+	 * Modifies or stores preload Link headers for page caching.
+	 *
+	 * @param array $header          The current header being processed.
+	 * @param array $header_original The original header details.
+	 *
+	 * @return array The modified header.
+	 */
 	public function w3tc_pagecache_set_header( $header, $header_original ) {
-		if ( $header_original['n'] == 'Link' &&
-				false !== strpos( $header_original['v'], 'rel=preload' ) ) {
-			// store preload Link headers in cache
-			$new = $header_original;
+		if ( 'Link' === $header_original['n'] && false !== strpos( $header_original['v'], 'rel=preload' ) ) {
+			// store preload Link headers in cache.
+			$new                = $header_original;
 			$new['files_match'] = '\\.html[_a-z]*$';
 			return $new;
 		}
@@ -1062,38 +1131,52 @@ public function w3tc_pagecache_set_header( $header, $header_original ) {
 	}
 }
 
-
-
+/**
+ * Class _W3_MinifyHelpers
+ *
+ * phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
+ * phpcs:disable PEAR.NamingConventions.ValidClassName.StartWithCapital
+ */
 class _W3_MinifyHelpers {
 	/**
 	 * Config
+	 *
+	 * @var Config
 	 */
 	private $config;
+
+	/**
+	 * Debug flag
+	 *
+	 * @var bool
+	 */
 	private $debug = false;
 
 	/**
-	 * Constructor
+	 * Initializes the _W3_MinifyHelpers class.
 	 *
-	 * @param W3_COnfig $config
+	 * @param Config $config Configuration instance used for the class.
+	 *
+	 * @return void
 	 */
-	function __construct( $config ) {
+	public function __construct( $config ) {
 		$this->config = $config;
-		$this->debug = $config->get_boolean( 'minify.debug' );
+		$this->debug  = $config->get_boolean( 'minify.debug' );
 	}
 
 	/**
-	 * Formats custom URL
+	 * Retrieves the minified URL for a given set of files and type.
 	 *
-	 * @param array   $files
-	 * @param string  $type
-	 * @return array
+	 * @param array  $files Array of file paths to be minified.
+	 * @param string $type  Type of files (e.g., 'css', 'js').
+	 *
+	 * @return string|null The minified URL or null if no URL is generated.
 	 */
-	function get_minify_url_for_files( $files, $type ) {
-		$minify_filename =
-			Minify_Core::urls_for_minification_to_minify_filename(
-			$files, $type );
-		if ( is_null( $minify_filename ) )
+	public function get_minify_url_for_files( $files, $type ) {
+		$minify_filename = Minify_Core::urls_for_minification_to_minify_filename( $files, $type );
+		if ( is_null( $minify_filename ) ) {
 			return null;
+		}
 
 		$url = Minify_Core::minified_url( $minify_filename );
 		$url = Util_Environment::url_to_maybe_https( $url );
@@ -1104,75 +1187,74 @@ function get_minify_url_for_files( $files, $type ) {
 	}
 
 	/**
-	 * Returns minified content
+	 * Retrieves the minified content for a given set of files and type.
 	 *
-	 * @param array   $files
-	 * @param string  $type
-	 * @return array
+	 * @param array  $files Array of file paths to be minified.
+	 * @param string $type  Type of files (e.g., 'css', 'js').
+	 *
+	 * @return string|null The minified content wrapped in HTML or null if no content is available.
 	 */
-	function get_minified_content_for_files( $files, $type ) {
-		$minify_filename =
-			Minify_Core::urls_for_minification_to_minify_filename(
-			$files, $type );
-		if ( is_null( $minify_filename ) )
+	public function get_minified_content_for_files( $files, $type ) {
+		$minify_filename = Minify_Core::urls_for_minification_to_minify_filename( $files, $type );
+		if ( is_null( $minify_filename ) ) {
 			return null;
+		}
+
 		$minify = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
 
 		$m = $minify->process( $minify_filename, true );
-		if ( !isset( $m['content'] ) )
+		if ( ! isset( $m['content'] ) ) {
 			return null;
-		if ( empty( $m['content'] ) )
+		}
+
+		if ( empty( $m['content'] ) ) {
 			return null;
+		}
 
 		$style = $m['content'];
+
 		return "<style media=\"all\">$style</style>\r\n";
 	}
 
 	/**
-	 * Prints script tag
+	 * Generates a script tag for a given URL and embed type.
+	 *
+	 * @param string $url        URL of the script.
+	 * @param string $embed_type Type of embed (e.g., 'blocking', 'nb-js', 'nb-async').
 	 *
-	 * @param string  $url
-	 * @param string  $embed_type
-	 * @return string
+	 * @return string The generated script tag.
 	 */
-	function generate_script_tag( $url, $embed_type = 'blocking' ) {
+	public function generate_script_tag( $url, $embed_type = 'blocking' ) {
 		static $non_blocking_function = false;
 
-		$rocket_loader_ignore = "";
-		if( $this->config->get_boolean( array( 'cloudflare', 'minify_js_rl_exclude' ) ) ){
+		$rocket_loader_ignore = '';
+		if ( $this->config->get_boolean( array( 'cloudflare', 'minify_js_rl_exclude' ) ) ) {
 			$rocket_loader_ignore = 'data-cfasync="false"';
 		}
 
-		if ( $embed_type == 'blocking' ) {
-			$script = '<script ' . $rocket_loader_ignore . ' src="' .
-				str_replace( '&', '&amp;', $url ) . '"></script>';
+		if ( 'blocking' === $embed_type ) {
+			$script = '<script ' . $rocket_loader_ignore . ' src="' . str_replace( '&', '&amp;', $url ) . '"></script>';
 		} else {
 			$script = '';
 
-			if ( $embed_type == 'nb-js' ) {
-				if ( !$non_blocking_function ) {
+			if ( 'nb-js' === $embed_type ) {
+				if ( ! $non_blocking_function ) {
 					$non_blocking_function = true;
-					$script = "<script>function w3tc_load_js(u){var d=document,p=d.getElementsByTagName('HEAD')[0],c=d.createElement('script');c.src=u;p.appendChild(c);}</script>";
+					$script                = "<script>function w3tc_load_js(u){var d=document,p=d.getElementsByTagName('HEAD')[0],c=d.createElement('script');c.src=u;p.appendChild(c);}</script>";
 				}
 
-				$script .= "<script>w3tc_load_js('" .
-					$url . "');</script>";
-
-			} elseif ( $embed_type == 'nb-async' ) {
-				$script = '<script ' . $rocket_loader_ignore . ' async src="' .
-					str_replace( '&', '&amp;', $url ) . '"></script>';
-			} elseif ( $embed_type == 'nb-defer' ) {
-				$script = '<script ' . $rocket_loader_ignore . ' defer src="' .
-					str_replace( '&', '&amp;', $url ) . '"></script>';
-			} elseif ( $embed_type == 'extsrc' ) {
-				$script = '<script ' . $rocket_loader_ignore . ' extsrc="' .
-					str_replace( '&', '&amp;', $url ) . '"></script>';
-			} elseif ( $embed_type == 'asyncsrc' ) {
-				$script = '<script ' . $rocket_loader_ignore . ' asyncsrc="' .
-					str_replace( '&', '&amp;', $url ) . '"></script>';
+				$script .= "<script>w3tc_load_js('" . $url . "');</script>";
+
+			} elseif ( 'nb-async' === $embed_type ) {
+				$script = '<script ' . $rocket_loader_ignore . ' async src="' . str_replace( '&', '&amp;', $url ) . '"></script>';
+			} elseif ( 'nb-defer' === $embed_type ) {
+				$script = '<script ' . $rocket_loader_ignore . ' defer src="' . str_replace( '&', '&amp;', $url ) . '"></script>';
+			} elseif ( 'extsrc' === $embed_type ) {
+				$script = '<script ' . $rocket_loader_ignore . ' extsrc="' . str_replace( '&', '&amp;', $url ) . '"></script>';
+			} elseif ( 'asyncsrc' === $embed_type ) {
+				$script = '<script ' . $rocket_loader_ignore . ' asyncsrc="' . str_replace( '&', '&amp;', $url ) . '"></script>';
 			} else {
-				$script = '<script ' . $rocket_loader_ignore . ' src="' .
-					str_replace( '&', '&amp;', $url ) . '"></script>';
+				$script = '<script ' . $rocket_loader_ignore . ' src="' . str_replace( '&', '&amp;', $url ) . '"></script>';
 			}
 		}
 
@@ -1180,58 +1262,58 @@ function generate_script_tag( $url, $embed_type = 'blocking' ) {
 	}
 
 	/**
-	 * URL file filter
+	 * Determines whether a given file or URL should be minified.
+	 *
+	 * @param string $url  URL of the file to check.
+	 * @param string $file File path to check (optional).
 	 *
-	 * @param string  $file
-	 * @return bool
+	 * @return string Indicates the type of minification ('url', 'file', or empty string).
 	 */
 	public function is_file_for_minification( $url, $file ) {
 		static $external;
 		static $external_regexp;
-		if ( !isset( $external ) ) {
-			$external = $this->config->get_array( 'minify.cache.files' );
+		if ( ! isset( $external ) ) {
+			$external        = $this->config->get_array( 'minify.cache.files' );
 			$external_regexp = $this->config->get_boolean( 'minify.cache.files_regexp' );
 		}
 
 		foreach ( $external as $item ) {
-			if ( empty( $item ) )
+			if ( empty( $item ) ) {
 				continue;
+			}
 
 			if ( $external_regexp ) {
 				$item = str_replace( '~', '\~', $item );
-				if ( ! preg_match( '~' . $item . '~', $url ) )
+				if ( ! preg_match( '~' . $item . '~', $url ) ) {
 					continue;
+				}
 			} else {
-				if ( ! preg_match( '~^' . Util_Environment::get_url_regexp( $item ) . '~', $url ) )
+				if ( ! preg_match( '~^' . Util_Environment::get_url_regexp( $item ) . '~', $url ) ) {
 					continue;
+				}
 			}
 
 			if ( $this->debug ) {
-				Minify_Core::log(
-					'is_file_for_minification: whilelisted ' . $url . ' by ' . $item );
+				Minify_Core::log( 'is_file_for_minification: whilelisted ' . $url . ' by ' . $item );
 			}
 
 			return 'url';
 		}
 
-
 		if ( is_null( $file ) ) {
 			if ( $this->debug ) {
-				Minify_Core::log(
-					'is_file_for_minification: external not whitelisted url ' . $url );
+				Minify_Core::log( 'is_file_for_minification: external not whitelisted url ' . $url );
 			}
 
 			return '';
 		}
 
 		$file_normalized = Util_Environment::remove_query_all( $file );
-		$ext = strrchr( $file_normalized, '.' );
+		$ext             = strrchr( $file_normalized, '.' );
 
-		if ( $ext != '.js' && $ext != '.css' ) {
+		if ( '.js' !== $ext && '.css' !== $ext ) {
 			if ( $this->debug ) {
-				Minify_Core::log(
-					'is_file_for_minification: unknown extension ' . $ext .
-					' for ' . $file );
+				Minify_Core::log( 'is_file_for_minification: unknown extension ' . $ext . ' for ' . $file );
 			}
 
 			return '';
@@ -1239,70 +1321,78 @@ public function is_file_for_minification( $url, $file ) {
 
 		$path = Util_Environment::docroot_to_full_filename( $file );
 
-		if ( !file_exists( $path ) ) {
+		if ( ! file_exists( $path ) ) {
 			if ( $this->debug ) {
-				Minify_Core::log(
-					'is_file_for_minification: file doesnt exists ' . $path );
+				Minify_Core::log( 'is_file_for_minification: file doesnt exists ' . $path );
 			}
 
 			return '';
 		}
 
 		if ( $this->debug ) {
-			Minify_Core::log(
-				'is_file_for_minification: true for file ' . $file .
-				' path ' . $path );
+			Minify_Core::log( 'is_file_for_minification: true for file ' . $file . ' path ' . $path );
 		}
 
 		return 'file';
 	}
 
 	/**
-	 * Sends HTTP/2 push header
+	 * Adds an HTTP/2 header for preloading a given URL.
+	 *
+	 * @param string $url URL to be preloaded.
+	 * @param string $as  Resource type (e.g., 'script', 'style').
+	 *
+	 * @return void
 	 */
 	public function http2_header_add( $url, $as ) {
-		if ( empty( $url ) )
+		if ( empty( $url ) ) {
 			return;
+		}
 
-		// Cloudflare needs URI without host
+		// Cloudflare needs URI without host.
 		$uri = Util_Environment::url_to_uri( $url );
 
 		// priorities attached:
 		// 3000 - cdn
-		// 4000 - browsercache
-		$data = apply_filters( 'w3tc_minify_http2_preload_url', array(
-			'result_link' => $uri,
-			'original_url' => $url
-		) );
+		// 4000 - browsercache.
+		$data = apply_filters(
+			'w3tc_minify_http2_preload_url',
+			array(
+				'result_link'  => $uri,
+				'original_url' => $url,
+			)
+		);
 
 		header( 'Link: <' . $data['result_link'] . '>; rel=preload; as=' . $as, false );
 	}
 
-
-
-	function generate_css_style_tag( $files, $embed_to_html ) {
+	/**
+	 * Generates a CSS style tag or URL for embedding styles.
+	 *
+	 * @param array $files         Array of CSS file paths.
+	 * @param bool  $embed_to_html Whether to embed the CSS content directly into the HTML.
+	 *
+	 * @return array Contains 'url' (string|null) and 'body' (string) keys.
+	 */
+	public function generate_css_style_tag( $files, $embed_to_html ) {
 		$return = array(
-			'url' => null,
-			'body' => ''
+			'url'  => null,
+			'body' => '',
 		);
 
 		if ( count( $files ) ) {
 			if ( $embed_to_html ) {
-				$body = $this->get_minified_content_for_files(
-					$files, 'css' );
-				if ( !is_null( $body ) ) {
+				$body = $this->get_minified_content_for_files( $files, 'css' );
+				if ( ! is_null( $body ) ) {
 					$return['body'] = $body;
 				}
 			}
 
 			if ( empty( $return['body'] ) ) {
-				$return['url'] = $this->get_minify_url_for_files(
-					$files, 'css' );
-				if ( !is_null( $return['url'] ) ) {
-					$return['body'] =
-						"<link rel=\"stylesheet\" href=\"" .
-						str_replace( '&', '&amp;', $return['url'] ) .
-						"\" media=\"all\" />\r\n";
+				$return['url'] = $this->get_minify_url_for_files( $files, 'css' );
+				if ( ! is_null( $return['url'] ) ) {
+					$return['body'] = '<link rel="stylesheet" href="' . // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
+						str_replace( '&', '&amp;', $return['url'] ) . "\" media=\"all\" />\r\n";
 				}
 			}
 		}
diff --git a/Minify_Plugin_Admin.php b/Minify_Plugin_Admin.php
index b9a307ea5..4c0e755ed 100644
--- a/Minify_Plugin_Admin.php
+++ b/Minify_Plugin_Admin.php
@@ -1,78 +1,99 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: Minify_Plugin_Admin.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class Minify_Plugin_Admin
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ */
 class Minify_Plugin_Admin {
+	/**
+	 * Config
+	 *
+	 * @var Config
+	 */
 	private $_config = null;
 
-	function __construct() {
+	/**
+	 * Constructor method for the Minify_Plugin_Admin class.
+	 *
+	 * @return void
+	 */
+	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs plugin
+	 * Initializes the plugin by registering filters and actions.
+	 *
+	 * @return void
 	 */
-	function run() {
+	public function run() {
 		add_filter( 'w3tc_save_options', array( $this, 'w3tc_save_options' ) );
 
 		$config_labels = new Minify_ConfigLabels();
 		add_filter( 'w3tc_config_labels', array( $config_labels, 'config_labels' ) );
 
 		if ( $this->_config->get_boolean( 'minify.enabled' ) ) {
-			add_filter( 'w3tc_usage_statistics_summary_from_history', array(
-					$this, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
+			add_filter( 'w3tc_usage_statistics_summary_from_history', array( $this, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
 			add_filter( 'w3tc_notes', array( $this, 'w3tc_notes' ) );
 			add_filter( 'w3tc_errors', array( $this, 'w3tc_errors' ) );
 		}
 
-		add_action( 'w3tc_ajax_minify_help', array(
-				$this,
-				'w3tc_ajax_minify_help'
-			) );
-		add_action( 'w3tc_message_action_minify_help', array(
-				$this,
-				'w3tc_message_action_minify_help'
-			) );
+		add_action( 'w3tc_ajax_minify_help', array( $this, 'w3tc_ajax_minify_help' ) );
+		add_action( 'w3tc_message_action_minify_help', array( $this, 'w3tc_message_action_minify_help' ) );
 
-		if ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG )
+		if ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG ) {
 			add_filter( 'w3tc_admin_bar_menu', array( $this, 'w3tc_admin_bar_menu' ) );
-
+		}
 	}
 
-
-
+	/**
+	 * Adds the Minify cache menu item to the WordPress admin bar.
+	 *
+	 * @param array $menu_items Existing menu items.
+	 *
+	 * @return array Modified menu items.
+	 */
 	public function w3tc_admin_bar_menu( $menu_items ) {
 		$menu_items['90040.minify'] = array(
-			'id' => 'w3tc_overlay_minify',
+			'id'     => 'w3tc_overlay_minify',
 			'parent' => 'w3tc_debug_overlays',
-			'title' => __( 'Minify Cache', 'w3-total-cache' ),
-			'href' => wp_nonce_url( network_admin_url(
-					'admin.php?page=w3tc_dashboard&amp;w3tc_message_action=minify_help' ), 'w3tc' )
+			'title'  => __( 'Minify Cache', 'w3-total-cache' ),
+			'href'   => wp_nonce_url( network_admin_url( 'admin.php?page=w3tc_dashboard&amp;w3tc_message_action=minify_help' ), 'w3tc' ),
 		);
 
 		return $menu_items;
 	}
 
-
-
+	/**
+	 * Handles the minify help action triggered in admin messages.
+	 *
+	 * @return void
+	 */
 	public function w3tc_message_action_minify_help() {
-		wp_enqueue_script( 'w3tc-minify-help',
-			plugins_url( 'Minify_GeneralPage_View_ShowHelp.js', W3TC_FILE ),
-			array(), W3TC_VERSION );
-		wp_enqueue_script( 'w3tc-minify-help-force',
-			plugins_url( 'Minify_GeneralPage_View_ShowHelpForce.js', W3TC_FILE ),
-			array(), W3TC_VERSION );
+		wp_enqueue_script( 'w3tc-minify-help', plugins_url( 'Minify_GeneralPage_View_ShowHelp.js', W3TC_FILE ), array(), W3TC_VERSION, false );
+		wp_enqueue_script( 'w3tc-minify-help-force', plugins_url( 'Minify_GeneralPage_View_ShowHelpForce.js', W3TC_FILE ), array(), W3TC_VERSION, false );
 	}
 
-
-
+	/**
+	 * Processes and saves plugin options.
+	 *
+	 * @param array $data Array containing new and old configuration data.
+	 *
+	 * @return array Processed configuration data.
+	 */
 	public function w3tc_save_options( $data ) {
 		$new_config = $data['new_config'];
 		$old_config = $data['old_config'];
 
 		if ( $new_config->get_boolean( 'minify.enabled' ) && ! $old_config->get_boolean( 'minify.enabled' ) ) {
-
 			$state = Dispatcher::config_state();
 			$state->set( 'minify.hide_minify_help', true );
 			$state->save();
@@ -104,181 +125,210 @@ public function w3tc_save_options( $data ) {
 		return $data;
 	}
 
-
-
+	/**
+	 * Prints admin scripts for the general settings page.
+	 *
+	 * @return void
+	 */
 	public static function admin_print_scripts_w3tc_general() {
 		$state = Dispatcher::config_state();
-		if ( !$state->get_boolean( 'minify.hide_minify_help' ) ) {
-			wp_enqueue_script( 'w3tc-minify-help',
-				plugins_url( 'Minify_GeneralPage_View_ShowHelp.js', W3TC_FILE ),
-				array(), W3TC_VERSION );
+		if ( ! $state->get_boolean( 'minify.hide_minify_help' ) ) {
+			wp_enqueue_script( 'w3tc-minify-help', plugins_url( 'Minify_GeneralPage_View_ShowHelp.js', W3TC_FILE ), array(), W3TC_VERSION, false );
 		}
 	}
 
-
-
 	/**
-	 * Does disk cache cleanup
+	 * Cleans up expired and unnecessary cache files.
 	 *
 	 * @return void
 	 */
-	function cleanup() {
-		$w3_cache_file_cleaner_generic = new Cache_File_Cleaner_Generic( array(
-				'exclude' => array(
+	public function cleanup() {
+		$w3_cache_file_cleaner_generic = new Cache_File_Cleaner_Generic(
+			array(
+				'exclude'         => array(
 					'*.files',
 					'.htaccess',
-					'index.html'
+					'index.html',
 				),
-				'cache_dir' => Util_Environment::cache_blog_dir( 'minify' ),
-				'expire' => $this->_config->get_integer( 'minify.file.gc' ),
-				'clean_timelimit' => $this->_config->get_integer( 'timelimit.cache_gc' )
-			) );
+				'cache_dir'       => Util_Environment::cache_blog_dir( 'minify' ),
+				'expire'          => $this->_config->get_integer( 'minify.file.gc' ),
+				'clean_timelimit' => $this->_config->get_integer( 'timelimit.cache_gc' ),
+			)
+		);
 
 		$w3_cache_file_cleaner_generic->clean();
 	}
 
-	function w3tc_errors( $errors ) {
-		$c = Dispatcher::config();
+	/**
+	 * Collects and returns errors related to Minify configuration or usage.
+	 *
+	 * @param array $errors Existing errors.
+	 *
+	 * @return array Updated list of errors.
+	 */
+	public function w3tc_errors( $errors ) {
+		$c     = Dispatcher::config();
 		$state = Dispatcher::config_state_master();
 
-		/**
-		 * Minify error occured
-		 */
+		// Minify error occured.
 		if ( $state->get_boolean( 'minify.show_note_minify_error' ) ) {
 			$errors['minify_error_creating'] = sprintf(
-				__( 'Recently an error occurred while creating the CSS / JS minify cache: %s. %s',
-					'w3-total-cache' ),
+				// Translators: 1 last minify error, 2 dismiss button.
+				__(
+					'Recently an error occurred while creating the CSS / JS minify cache: %1$s. %2$s',
+					'w3-total-cache'
+				),
 				$state->get_string( 'minify.error.last' ),
-				Util_Ui::button_hide_note2( array(
+				Util_Ui::button_hide_note2(
+					array(
 						'w3tc_default_config_state_master' => 'y',
-						'key' => 'minify.show_note_minify_error',
-						'value' => 'false' ) ) );
+						'key'                              => 'minify.show_note_minify_error',
+						'value'                            => 'false',
+					)
+				)
+			);
 		}
 
-		if ( $c->get_string( 'minify.engine' ) == 'memcached' ) {
-			$memcached_servers = $c->get_array( 'minify.memcached.servers' );
+		if ( 'memcached' === $c->get_string( 'minify.engine' ) ) {
+			$memcached_servers         = $c->get_array( 'minify.memcached.servers' );
 			$memcached_binary_protocol = $c->get_boolean( 'minify.memcached.binary_protocol' );
-			$memcached_username = $c->get_string( 'minify.memcached.username' );
-			$memcached_password = $c->get_string( 'minify.memcached.password' );
-
-			if ( !Util_Installed::is_memcache_available( $memcached_servers, $memcached_binary_protocol, $memcached_username, $memcached_password ) ) {
-				if ( !isset( $errors['memcache_not_responding.details'] ) )
+			$memcached_username        = $c->get_string( 'minify.memcached.username' );
+			$memcached_password        = $c->get_string( 'minify.memcached.password' );
+
+			if (
+				! Util_Installed::is_memcache_available(
+					$memcached_servers,
+					$memcached_binary_protocol,
+					$memcached_username,
+					$memcached_password
+				)
+			) {
+				if ( ! isset( $errors['memcache_not_responding.details'] ) ) {
 					$errors['memcache_not_responding.details'] = array();
+				}
 
 				$errors['memcache_not_responding.details'][] = sprintf(
-					__( 'Minify: %s.', 'w3-total-cache' ),
-					implode( ', ', $memcached_servers ) );
+					// Translators: 1 memcache servers.
+					__(
+						'Minify: %1$s.',
+						'w3-total-cache'
+					),
+					implode( ', ', $memcached_servers )
+				);
 			}
 		}
 
 		return $errors;
 	}
 
-	function w3tc_notes( $notes ) {
+	/**
+	 * Adds notes or messages related to Minify cache actions.
+	 *
+	 * @param array $notes Existing notes.
+	 *
+	 * @return array Updated notes.
+	 */
+	public function w3tc_notes( $notes ) {
 		$state_note = Dispatcher::config_state();
-		/**
-		 * Show notification when minify needs to be emptied
-		 */
-		if ( $state_note->get_boolean( 'minify.show_note.need_flush' ) &&
-			!is_network_admin() /* flushing doesnt work in network admin */ &&
-			!$this->_config->is_preview() ) {
+
+		// Show notification when minify needs to be emptied.
+		if (
+			$state_note->get_boolean( 'minify.show_note.need_flush' ) &&
+			! is_network_admin() && // flushing doesnt work in network admin.
+			! $this->_config->is_preview()
+		) {
 			$notes['minify_flush_needed'] = sprintf(
-				__( 'The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.',
-					'w3-total-cache' ),
+				// Translators: 1 empty cache button.
+				__(
+					'The setting change(s) made either invalidate the cached data or modify the behavior of the site. %1$s now to provide a consistent user experience.',
+					'w3-total-cache'
+				),
 				Util_Ui::button_link(
 					__( 'Empty the minify cache', 'w3-total-cache' ),
-					Util_Ui::url( array( 'w3tc_flush_minify' => 'y' ) ) ) );
+					Util_Ui::url( array( 'w3tc_flush_minify' => 'y' ) )
+				)
+			);
 		}
 
 		return $notes;
 	}
 
-
-
+	/**
+	 * Handles the AJAX request for displaying Minify help.
+	 *
+	 * @return void
+	 */
 	public function w3tc_ajax_minify_help() {
-		include  W3TC_DIR . '/Minify_HelpPopup_View.php';
+		include W3TC_DIR . '/Minify_HelpPopup_View.php';
 	}
 
-
-
+	/**
+	 * Summarizes Minify usage statistics from history.
+	 *
+	 * @param array $summary Existing summary data.
+	 * @param array $history Historical usage data.
+	 *
+	 * @return array Updated summary data.
+	 */
 	public function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
-		// memcached servers
+		// memcached servers.
 		$c = Dispatcher::config();
-		if ( $c->get_string( 'minify.engine' ) == 'memcached' ) {
+		if ( 'memcached' === $c->get_string( 'minify.engine' ) ) {
 			$summary['memcached_servers']['minify'] = array(
-				'servers' => $c->get_array( 'minify.memcached.servers' ),
-				'username' => $c->get_string( 'minify.memcached.username' ),
-				'password' => $c->get_string( 'minify.memcached.password' ),
+				'servers'         => $c->get_array( 'minify.memcached.servers' ),
+				'username'        => $c->get_string( 'minify.memcached.username' ),
+				'password'        => $c->get_string( 'minify.memcached.password' ),
 				'binary_protocol' => $c->get_boolean( 'minify.memcached.binary_protocol' ),
-				'name' => __( 'Minification', 'w3-total-cache' )
+				'name'            => __( 'Minification', 'w3-total-cache' ),
 			);
-		} elseif ( $c->get_string( 'minify.engine' ) == 'redis' ) {
+		} elseif ( 'redis' === $c->get_string( 'minify.engine' ) ) {
 			$summary['redis_servers']['minify'] = array(
-				'servers' => $c->get_array( 'minify.redis.servers' ),
+				'servers'  => $c->get_array( 'minify.redis.servers' ),
 				'username' => $c->get_boolean( 'minify.redis.username' ),
-				'dbid' => $c->get_integer( 'minify.redis.dbid' ),
+				'dbid'     => $c->get_integer( 'minify.redis.dbid' ),
 				'password' => $c->get_string( 'minify.redis.password' ),
-				'name' => __( 'Minification', 'w3-total-cache' )
+				'name'     => __( 'Minification', 'w3-total-cache' ),
 			);
 		}
 
 		$e = $this->_config->get_string( 'minify.engine' );
 		$a = array(
-			'size_visible' => ( $e == 'file' ),
-			'requests_visible' =>
-			!( $e == 'file' && $this->_config->get_boolean( 'minify.rewrite' ) )
+			'size_visible'     => ( 'file' === $e ),
+			'requests_visible' => ! ( 'file' === $e && $this->_config->get_boolean( 'minify.rewrite' ) ),
 		);
 
-		if ( !isset( $summary['period']['timestamp_end'] ) ) {
-			// summary requested, enough
+		if ( ! isset( $summary['period']['timestamp_end'] ) ) {
+			// summary requested, enough.
 			$summary['minify'] = $a;
 			return $summary;
 		}
 
-		// get requests rate stats
+		// get requests rate stats.
 		if ( $a['requests_visible'] ) {
-			// counters
-			$requests_total = Util_UsageStatistics::sum( $history,
-				'minify_requests_total' );
-			$original_length_css = Util_UsageStatistics::sum( $history,
-				'minify_original_length_css' );
-			$output_length_css = Util_UsageStatistics::sum( $history,
-				'minify_output_length_css' );
-
-			$original_length_js = Util_UsageStatistics::sum( $history,
-				'minify_original_length_js' );
-			$output_length_js = Util_UsageStatistics::sum( $history,
-				'minify_output_length_js' );
-
-			$a['requests_total'] = Util_UsageStatistics::integer(
-				$requests_total );
-			$a['requests_per_second'] =
-				Util_UsageStatistics::value_per_period_seconds(
-				$requests_total, $summary );
-			$a['compression_css'] = Util_UsageStatistics::percent(
-				$original_length_css - $output_length_css, $original_length_css );
-			$a['compression_js'] = Util_UsageStatistics::percent(
-				$original_length_js - $output_length_js, $original_length_js );
+			// counters.
+			$requests_total      = Util_UsageStatistics::sum( $history, 'minify_requests_total' );
+			$original_length_css = Util_UsageStatistics::sum( $history, 'minify_original_length_css' );
+			$output_length_css   = Util_UsageStatistics::sum( $history, 'minify_output_length_css' );
+
+			$original_length_js = Util_UsageStatistics::sum( $history, 'minify_original_length_js' );
+			$output_length_js   = Util_UsageStatistics::sum( $history, 'minify_output_length_js' );
+
+			$a['requests_total']      = Util_UsageStatistics::integer( $requests_total );
+			$a['requests_per_second'] = Util_UsageStatistics::value_per_period_seconds( $requests_total, $summary );
+			$a['compression_css']     = Util_UsageStatistics::percent( $original_length_css - $output_length_css, $original_length_css );
+			$a['compression_js']      = Util_UsageStatistics::percent( $original_length_js - $output_length_js, $original_length_js );
 		}
 		if ( $a['size_visible'] ) {
-			list( $v, $should_count ) =
-				Util_UsageStatistics::get_or_init_size_transient(
-				'w3tc_ustats_minify_size', $summary );
+			list( $v, $should_count ) = Util_UsageStatistics::get_or_init_size_transient( 'w3tc_ustats_minify_size', $summary );
 			if ( $should_count ) {
-				$h = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
+				$h     = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
 				$stats = $h->get_stats_size( $summary['timeout_time'] );
 
-				// build stats to show
-				$v['size_used'] = Util_UsageStatistics::bytes_to_size(
-					$stats['css']['output_length'] + $stats['js']['output_length'] );
-				$v['size_items'] = Util_UsageStatistics::integer(
-					$stats['css']['items'] + $stats['js']['items'] );
-				$v['size_compression_css'] = Util_UsageStatistics::percent(
-					$stats['css']['original_length'] - $stats['css']['output_length'],
-					$stats['css']['original_length'] );
-				$v['size_compression_js'] = Util_UsageStatistics::percent(
-					$stats['js']['original_length'] - $stats['js']['output_length'],
-					$stats['js']['original_length'] );
+				// build stats to show.
+				$v['size_used']            = Util_UsageStatistics::bytes_to_size( $stats['css']['output_length'] + $stats['js']['output_length'] );
+				$v['size_items']           = Util_UsageStatistics::integer( $stats['css']['items'] + $stats['js']['items'] );
+				$v['size_compression_css'] = Util_UsageStatistics::percent( $stats['css']['original_length'] - $stats['css']['output_length'], $stats['css']['original_length'] );
+				$v['size_compression_js']  = Util_UsageStatistics::percent( $stats['js']['original_length'] - $stats['js']['output_length'], $stats['js']['original_length'] );
 
 				set_transient( 'w3tc_ustats_pagecache_size', $v, 120 );
 			}
@@ -292,6 +342,7 @@ public function w3tc_usage_statistics_summary_from_history( $summary, $history )
 		}
 
 		$summary['minify'] = $a;
+
 		return $summary;
 	}
 }
diff --git a/Mobile_Base.php b/Mobile_Base.php
index 77f9aade5..b31a66f9b 100644
--- a/Mobile_Base.php
+++ b/Mobile_Base.php
@@ -1,6 +1,17 @@
 <?php
+/**
+ * File: Mobile_Base.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Mobile_Base
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ */
 abstract class Mobile_Base {
 	/**
 	 * Groups
@@ -8,31 +19,66 @@ abstract class Mobile_Base {
 	 * @var array
 	 */
 	private $_groups = array();
+
+	/**
+	 * Compare key
+	 *
+	 * @var string
+	 */
 	private $_compare_key = '';
+
+	/**
+	 * Config key
+	 *
+	 * @var string
+	 */
 	private $_config_key = '';
+
+	/**
+	 * Cache case
+	 *
+	 * @var string
+	 */
 	private $_cachecase = '';
 
 	/**
-	 * PHP5-style constructor
+	 * Initializes the Mobile_Base instance with the provided configuration and comparison keys.
+	 *
+	 * @param string $config_key  The configuration key for retrieving group settings.
+	 * @param string $compare_key The comparison key for validating groups.
+	 *
+	 * @return void
 	 */
-	function __construct( $config_key, $compare_key ) {
-		$config = Dispatcher::config();
-		$this->_groups = $config->get_array( $config_key );
-		$this->_config_key = $config_key;
+	public function __construct( $config_key, $compare_key ) {
+		$config             = Dispatcher::config();
+		$this->_groups      = $config->get_array( $config_key );
+		$this->_config_key  = $config_key;
 		$this->_compare_key = $compare_key;
-		$this->_cachecase = substr( $config_key, 0, strpos( $config_key, '.' ) );
+		$this->_cachecase   = substr( $config_key, 0, strpos( $config_key, '.' ) );
 	}
 
-	abstract function group_verifier( $group_compare_value );
+	/**
+	 * Abstract method to verify a group based on the provided comparison value.
+	 *
+	 * @param mixed $group_compare_value The value to compare against group settings.
+	 *
+	 * @return void
+	 */
+	abstract public function group_verifier( $group_compare_value );
 
+	/**
+	 * Retrieves the active group if one exists.
+	 *
+	 * @return string|false The name of the active group or false if no group is active.
+	 */
 	public function get_group() {
 		static $group = null;
 
-		if ( $group === null ) {
+		if ( null === $group ) {
 			if ( $this->do_get_group() ) {
 				foreach ( $this->_groups as $config_group => $config ) {
-					if ( isset( $config['enabled'] ) && $config['enabled'] && isset( $config[$this->_compare_key] ) ) {
-						foreach ( (array) $config[$this->_compare_key] as $group_compare_value ) {
+					if ( isset( $config['enabled'] ) && $config['enabled'] && isset( $config[ $this->_compare_key ] ) ) {
+						foreach ( (array) $config[ $this->_compare_key ] as $group_compare_value ) {
 							if ( $group_compare_value && $this->group_verifier( $group_compare_value ) ) {
 								$group = $config_group;
 								return $group;
@@ -48,13 +94,12 @@ public function get_group() {
 		return $group;
 	}
 
-
 	/**
-	 * Returns temaplte
+	 * Retrieves the template part of the theme associated with the active group.
 	 *
-	 * @return string
+	 * @return string|false The template name or false if no theme is associated.
 	 */
-	function get_template() {
+	public function get_template() {
 		$theme = $this->get_theme();
 
 		if ( $theme ) {
@@ -67,11 +112,11 @@ function get_template() {
 	}
 
 	/**
-	 * Returns stylesheet
+	 * Retrieves the stylesheet part of the theme associated with the active group.
 	 *
-	 * @return string
+	 * @return string|false The stylesheet name or false if no theme is associated.
 	 */
-	function get_stylesheet() {
+	public function get_stylesheet() {
 		$theme = $this->get_theme();
 
 		if ( $theme ) {
@@ -83,90 +128,101 @@ function get_stylesheet() {
 	}
 
 	/**
-	 * Returns redirect
+	 * Retrieves the redirect URL for the active group.
 	 *
-	 * @return string
+	 * @return string|false The redirect URL or false if none is defined.
 	 */
-	function get_redirect() {
+	public function get_redirect() {
 		$group = $this->get_group();
 
-		if ( isset( $this->_groups[$group]['redirect'] ) ) {
-			return $this->_groups[$group]['redirect'];
+		if ( isset( $this->_groups[ $group ]['redirect'] ) ) {
+			return $this->_groups[ $group ]['redirect'];
 		}
 
 		return false;
 	}
 
 	/**
-	 * Returns theme
+	 * Retrieves the theme associated with the active group.
 	 *
-	 * @return string
+	 * @return string|false The theme key or false if none is associated.
 	 */
-	function get_theme() {
+	public function get_theme() {
 		$group = $this->get_group();
 
-		if ( isset( $this->_groups[$group]['theme'] ) ) {
-			return $this->_groups[$group]['theme'];
+		if ( isset( $this->_groups[ $group ]['theme'] ) ) {
+			return $this->_groups[ $group ]['theme'];
 		}
 
 		return false;
 	}
 
 	/**
-	 * Return array of themes
+	 * Retrieves all available themes as a key-value array.
 	 *
-	 * @return array
+	 * @return array Associative array of themes with keys as theme identifiers and values as names.
 	 */
-	function get_themes() {
-		$themes = array();
+	public function get_themes() {
+		$themes    = array();
 		$wp_themes = Util_Theme::get_themes();
 
 		foreach ( $wp_themes as $wp_theme ) {
-			$theme_key = sprintf( '%s/%s', $wp_theme['Template'], $wp_theme['Stylesheet'] );
-			$themes[$theme_key] = $wp_theme['Name'];
+			$theme_key            = sprintf( '%s/%s', $wp_theme['Template'], $wp_theme['Stylesheet'] );
+			$themes[ $theme_key ] = $wp_theme['Name'];
 		}
 
 		return $themes;
 	}
 
-
 	/**
-	 * Checks if there are enabled referrer groups
+	 * Checks if any groups are enabled in the configuration.
 	 *
-	 * @return bool
+	 * @return bool True if at least one group is enabled, otherwise false.
 	 */
-	function has_enabled_groups() {
-		foreach ( $this->_groups as $group => $config )
-			if ( isset( $config['enabled'] ) && $config['enabled'] )
+	public function has_enabled_groups() {
+		foreach ( $this->_groups as $group => $config ) {
+			if ( isset( $config['enabled'] ) && $config['enabled'] ) {
 				return true;
+			}
+
 			return false;
+		}
 	}
 
-	function do_get_group() {
+	/**
+	 * Determines whether a group should be retrieved.
+	 *
+	 * @return bool Always returns true.
+	 */
+	public function do_get_group() {
 		return true;
 	}
 
 	/**
-	 * Use Util_Theme::get_themes() to get a list themenames to use with user agent groups
+	 * Saves or updates the configuration for a specific group.
+	 *
+	 * @param string $group    The name of the group to save or update.
+	 * @param string $theme    The theme associated with the group.
+	 * @param string $redirect The redirect URL for the group.
+	 * @param array  $values   The values used to compare for this group.
+	 * @param bool   $enabled  Whether the group is enabled.
 	 *
-	 * @param unknown $group
-	 * @param string  $theme    the themename default is default theme. For childtheme it should be parentthemename/childthemename
-	 * @param string  $redirect
-	 * @param array   $values   Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported.
-	 * @param bool    $enabled
+	 * @return void
 	 */
-	function save_group( $group, $theme = 'default', $redirect = '', $values = array(), $enabled = false ) {
-		$config = Dispatcher::config();
-		$groups = $config->get_array( $this->_config_key );
-		$group_config = array();
-		$group_config['theme'] = $theme;
-		$group_config['enabled'] = $enabled;
+	public function save_group( $group, $theme = 'default', $redirect = '', $values = array(), $enabled = false ) {
+		$config                   = Dispatcher::config();
+		$groups                   = $config->get_array( $this->_config_key );
+		$group_config             = array();
+		$group_config['theme']    = $theme;
+		$group_config['enabled']  = $enabled;
 		$group_config['redirect'] = $redirect;
-		$values = array_unique( $values );
-		$values = array_map( 'strtolower', $values );
+		$values                   = array_unique( $values );
+		$values                   = array_map( 'strtolower', $values );
+
 		sort( $values );
-		$group_config[$this->_compare_key] = $values;
-		$groups[$group] = $group_config;
+
+		$group_config[ $this->_compare_key ] = $values;
+		$groups[ $group ]                    = $group_config;
 
 		$enable = false;
 		foreach ( $groups as $group => $group_config ) {
@@ -175,17 +231,24 @@ function save_group( $group, $theme = 'default', $redirect = '', $values = array
 				break;
 			}
 		}
+
 		$config->set( $this->_cachecase . '.enabled', $enable );
 		$config->set( $this->_config_key, $groups );
 		$config->save();
 		$this->_groups = $groups;
 	}
 
-
-	function delete_group( $group ) {
+	/**
+	 * Deletes a specific group from the configuration.
+	 *
+	 * @param string $group The name of the group to delete.
+	 *
+	 * @return void
+	 */
+	public function delete_group( $group ) {
 		$config = Dispatcher::config();
 		$groups = $config->get_array( 'mobile.rgroups' );
-		unset( $groups[$group] );
+		unset( $groups[ $group ] );
 
 		$enable = false;
 		foreach ( $groups as $group => $group_config ) {
@@ -194,19 +257,33 @@ function delete_group( $group ) {
 				break;
 			}
 		}
+
 		$config->set( $this->_cachecase . '.enabled', $enable );
 		$config->set( $this->_config_key, $groups );
 		$config->save();
 		$this->_groups = $groups;
 	}
 
-	function get_group_values( $group ) {
+	/**
+	 * Retrieves the configuration values for a specific group.
+	 *
+	 * @param string $group The name of the group whose values are retrieved.
+	 *
+	 * @return array The configuration values of the specified group.
+	 */
+	public function get_group_values( $group ) {
 		$config = Dispatcher::config();
 		$groups = $config->get_array( $this->_config_key );
-		return $groups[$group];
+
+		return $groups[ $group ];
 	}
 
-	function get_groups() {
+	/**
+	 * Retrieves all groups currently configured.
+	 *
+	 * @return array Associative array of all groups and their configurations.
+	 */
+	public function get_groups() {
 		return $this->_groups;
 	}
 }
diff --git a/Mobile_Redirect.php b/Mobile_Redirect.php
index 24729c49b..90a76c7c5 100644
--- a/Mobile_Redirect.php
+++ b/Mobile_Redirect.php
@@ -1,18 +1,40 @@
 <?php
+/**
+ * File: Mobile_Redirect.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * class Redirect
+ * Class Mobile_Redirect
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
  */
 class Mobile_Redirect {
-
+	/**
+	 * Mobile
+	 *
+	 * @var Mobile_UserAgent
+	 */
 	private $_mobile = null;
+
+	/**
+	 * Referrer
+	 *
+	 * @var Mobile_Referrer
+	 */
 	private $_referrer = null;
 
 	/**
-	 * PHP5 Constructor
+	 * Constructor for the Mobile_Redirect class.
+	 *
+	 * Initializes mobile and referrer components if their respective features are enabled in the configuration.
+	 *
+	 * @return void
 	 */
-	function __construct() {
+	public function __construct() {
 		$config = Dispatcher::config();
 		if ( $config->get_boolean( 'mobile.enabled' ) ) {
 			$this->_mobile = Dispatcher::component( 'Mobile_UserAgent' );
@@ -24,31 +46,35 @@ function __construct() {
 	}
 
 	/**
-	 * Do logic
+	 * Processes the request to determine and execute mobile or referrer redirections.
+	 *
+	 * Skips processing for certain predefined conditions such as AJAX requests, cron jobs, or admin pages.
+	 *
+	 * @return void
 	 */
-	function process() {
-		/**
-		 * Skip some pages
-		 */
+	public function process() {
+		// Skip some pages.
 		switch ( true ) {
-		case defined( 'DOING_AJAX' ):
-		case defined( 'DOING_CRON' ):
-		case defined( 'APP_REQUEST' ):
-		case defined( 'XMLRPC_REQUEST' ):
-		case defined( 'WP_ADMIN' ):
-		case ( defined( 'SHORTINIT' ) && SHORTINIT ):
-			return;
+			case defined( 'DOING_AJAX' ):
+			case defined( 'DOING_CRON' ):
+			case defined( 'APP_REQUEST' ):
+			case defined( 'XMLRPC_REQUEST' ):
+			case defined( 'WP_ADMIN' ):
+			case ( defined( 'SHORTINIT' ) && SHORTINIT ):
+				return;
 		}
 
-		/**
-		 * Handle mobile or referrer redirects
-		 */
+		// Handle mobile or referrer redirects.
 		if ( $this->_mobile || $this->_referrer ) {
-			$mobile_redirect = $referrer_redirect = '';
-			if ( $this->_mobile )
+			$mobile_redirect = '';
+			if ( $this->_mobile ) {
 				$mobile_redirect = $this->_mobile->get_redirect();
-			if ( $this->_referrer )
+			}
+
+			$referrer_redirect = '';
+			if ( $this->_referrer ) {
 				$referrer_redirect = $this->_referrer->get_redirect();
+			}
 
 			$redirect = ( $mobile_redirect ? $mobile_redirect : $referrer_redirect );
 
diff --git a/Mobile_Referrer.php b/Mobile_Referrer.php
index 4ba00a6fd..0033eb143 100644
--- a/Mobile_Referrer.php
+++ b/Mobile_Referrer.php
@@ -1,26 +1,37 @@
 <?php
-namespace W3TC;
-
 /**
- * W3TC Referrer detection
+ * File: Mobile_Referrer.php
+ *
+ * @package W3TC
  */
+
+namespace W3TC;
+
+// W3TC Referrer detection.
 define( 'W3TC_REFERRER_COOKIE_NAME', 'w3tc_referrer' );
 
 /**
- * Class: Mobile_Referrer
+ * Class Mobile_Referrer
  */
 class Mobile_Referrer extends Mobile_Base {
 	/**
-	 * PHP5-style constructor
+	 * Constructs the Mobile_Referrer object.
+	 *
+	 * Initializes the parent class with specific group and referrer settings.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		parent::__construct( 'referrer.rgroups', 'referrers' );
 	}
 
 	/**
-	 * Returns HTTP referrer value.
+	 * Retrieves the HTTP referrer from cookies or the server.
+	 *
+	 * If enabled groups are present, attempts to get the HTTP referrer from a cookie or the server.
+	 * Sets or clears cookies based on conditions.
 	 *
-	 * @return string
+	 * @return string The sanitized HTTP referrer or an empty string if not available.
 	 */
 	public function get_http_referrer() {
 		$http_referrer = '';
@@ -40,14 +51,33 @@ public function get_http_referrer() {
 		return $http_referrer;
 	}
 
-	function group_verifier( $group_compare_value ) {
+	/**
+	 * Verifies if the HTTP referrer matches a specified group comparison value.
+	 *
+	 * Uses a static reference to store the HTTP referrer for efficient reuse.
+	 * Matches the referrer against a regular expression provided in `$group_compare_value`.
+	 *
+	 * @param string $group_compare_value The regex pattern to compare against the HTTP referrer.
+	 *
+	 * @return bool True if the referrer matches the provided pattern, false otherwise.
+	 */
+	public function group_verifier( $group_compare_value ) {
 		static $http_referrer = null;
-		if ( is_null( $http_referrer ) )
+		if ( is_null( $http_referrer ) ) {
 			$http_referrer = $this->get_http_referrer();
+		}
+
 		return $http_referrer && preg_match( '~' . $group_compare_value . '~i', $http_referrer );
 	}
 
-	function do_get_group() {
+	/**
+	 * Retrieves the group HTTP referrer.
+	 *
+	 * This method acts as a wrapper for `get_http_referrer`.
+	 *
+	 * @return string The sanitized HTTP referrer.
+	 */
+	public function do_get_group() {
 		return $this->get_http_referrer();
 	}
 }
diff --git a/Mobile_UserAgent.php b/Mobile_UserAgent.php
index 5c329fe45..a8286c013 100644
--- a/Mobile_UserAgent.php
+++ b/Mobile_UserAgent.php
@@ -5,6 +5,7 @@
  * W3TC Mobile detection.
  *
  * @package W3TC
+ *
  * @subpackage QA
  */
 
@@ -15,23 +16,27 @@
  */
 class Mobile_UserAgent extends Mobile_Base {
 	/**
-	 * PHP5-style constructor
+	 * Constructs the Mobile_UserAgent object and initializes the parent constructor.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		parent::__construct( 'mobile.rgroups', 'agents' );
 	}
 
 	/**
-	 * Group verifier.
+	 * Verifies if the given group_compare_value matches the User-Agent string.
+	 *
+	 * phpcs:disable WordPress.Security.ValidatedSanitizedInput
+	 *
+	 * @param string $group_compare_value The regex pattern to compare with the User-Agent string.
 	 *
-	 * @param string $group_compare_value Group comparison value.
-	 * @return int|false
+	 * @return bool True if the User-Agent matches the pattern, false otherwise.
 	 */
 	public function group_verifier( $group_compare_value ) {
 		return preg_match(
 			'~' . $group_compare_value . '~i',
-			isset( $_SERVER['HTTP_USER_AGENT'] ) ?
-				htmlspecialchars( $_SERVER['HTTP_USER_AGENT'] ) : '' // phpcs:ignore
+			isset( $_SERVER['HTTP_USER_AGENT'] ) ? htmlspecialchars( $_SERVER['HTTP_USER_AGENT'] ) : ''
 		);
 	}
 }
diff --git a/ModuleStatus.php b/ModuleStatus.php
index 3bd857644..9bd44f554 100644
--- a/ModuleStatus.php
+++ b/ModuleStatus.php
@@ -1,79 +1,116 @@
 <?php
+/**
+ * File: ModuleStatus.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class ModuleStatus
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
+ */
 class ModuleStatus {
-
+	/**
+	 * Opcode Engines
+	 *
+	 * @var array
+	 */
 	private $_opcode_engines = array(
 		'apc',
 		'eaccelerator',
 		'xcache',
-		'wincache'
+		'wincache',
 	);
+
+	/**
+	 * File engines
+	 *
+	 * @var array
+	 */
 	private $_file_engines = array(
 		'file',
-		'file_generic'
+		'file_generic',
 	);
+
+	/**
+	 * Config
+	 *
+	 * @var Config
+	 */
 	private $_config;
 
+	/**
+	 * Constructor for initializing the ModuleStatus class.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
+	 * Checks whether any caching or optimization plugin is enabled.
 	 *
-	 *
-	 * @return bool
+	 * @return bool True if any plugin is enabled, false otherwise.
 	 */
 	public function plugin_is_enabled() {
-		return $this->is_enabled( 'pgcache' )
-			|| $this->is_enabled( 'minify' )
-			|| $this->is_enabled( 'dbcache' )
-			|| $this->is_enabled( 'objectcache' )
-			|| $this->is_enabled( 'browsercache' )
-			|| $this->is_enabled( 'cdn' )
-			|| $this->is_enabled( 'cdnfsd' )
-			|| $this->is_enabled( 'varnish' )
-			|| $this->is_enabled( 'newrelic' )
-			|| $this->is_enabled( 'fragmentcache' );
+		return $this->is_enabled( 'pgcache' ) ||
+			$this->is_enabled( 'minify' ) ||
+			$this->is_enabled( 'dbcache' ) ||
+			$this->is_enabled( 'objectcache' ) ||
+			$this->is_enabled( 'browsercache' ) ||
+			$this->is_enabled( 'cdn' ) ||
+			$this->is_enabled( 'cdnfsd' ) ||
+			$this->is_enabled( 'varnish' ) ||
+			$this->is_enabled( 'newrelic' ) ||
+			$this->is_enabled( 'fragmentcache' );
 	}
 
 	/**
+	 * Checks if a specific module is enabled.
 	 *
+	 * @param string $module The name of the module to check.
 	 *
-	 * @param unknown $module
-	 * @return bool
+	 * @return bool True if the module is enabled, false otherwise.
 	 */
 	public function is_enabled( $module ) {
 		return $this->_config->get_boolean( "$module.enabled" );
 	}
 
 	/**
-	 * Verifies that the module is actually running and not only enabled.
+	 * Checks if a specific module is running.
+	 *
+	 * phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
 	 *
-	 * @param unknown $module
-	 * @return mixed|void
+	 * @param string $module The name of the module to check.
+	 *
+	 * @return bool True if the module is running, false otherwise.
 	 */
 	public function is_running( $module ) {
 		return apply_filters( "w3tc_module_is_running-{$module}", $this->is_enabled( $module ) );
 	}
 
 	/**
+	 * Determines whether Memcached can be emptied.
 	 *
-	 *
-	 * @return bool
+	 * @return bool True if Memcached can be emptied, false otherwise.
 	 */
 	public function can_empty_memcache() {
-		return $this->_enabled_module_uses_engine( 'pgcache', 'memcached' )
-			|| $this->_enabled_module_uses_engine( 'dbcache', 'memcached' )
-			|| $this->_enabled_module_uses_engine( 'objectcache', 'memcached' )
-			|| $this->_enabled_module_uses_engine( 'minify', 'memcached' )
-			|| $this->_enabled_module_uses_engine( 'fragmentcache', 'memcached' );
+		return $this->_enabled_module_uses_engine( 'pgcache', 'memcached' ) ||
+			$this->_enabled_module_uses_engine( 'dbcache', 'memcached' ) ||
+			$this->_enabled_module_uses_engine( 'objectcache', 'memcached' ) ||
+			$this->_enabled_module_uses_engine( 'minify', 'memcached' ) ||
+			$this->_enabled_module_uses_engine( 'fragmentcache', 'memcached' );
 	}
 
 	/**
+	 * Determines whether the Opcache can be emptied.
 	 *
-	 *
-	 * @return bool
+	 * @return bool True if Opcache can be emptied, false otherwise.
 	 */
 	public function can_empty_opcode() {
 		$o = Dispatcher::component( 'SystemOpCache_Core' );
@@ -81,41 +118,51 @@ public function can_empty_opcode() {
 	}
 
 	/**
+	 * Determines whether file-based caches can be emptied.
 	 *
-	 *
-	 * @return bool
+	 * @return bool True if file-based caches can be emptied, false otherwise.
 	 */
 	public function can_empty_file() {
-		return $this->_enabled_module_uses_engine( 'pgcache', $this->_file_engines )
-			|| $this->_enabled_module_uses_engine( 'dbcache', $this->_file_engines )
-			|| $this->_enabled_module_uses_engine( 'objectcache', $this->_file_engines )
-			|| $this->_enabled_module_uses_engine( 'minify', $this->_file_engines )
-			|| $this->_enabled_module_uses_engine( 'fragmentcache', $this->_file_engines );
+		return $this->_enabled_module_uses_engine( 'pgcache', $this->_file_engines ) ||
+			$this->_enabled_module_uses_engine( 'dbcache', $this->_file_engines ) ||
+			$this->_enabled_module_uses_engine( 'objectcache', $this->_file_engines ) ||
+			$this->_enabled_module_uses_engine( 'minify', $this->_file_engines ) ||
+			$this->_enabled_module_uses_engine( 'fragmentcache', $this->_file_engines );
 	}
 
 	/**
+	 * Determines whether Varnish cache can be emptied.
 	 *
-	 *
-	 * @return mixed
+	 * @return bool True if Varnish cache can be emptied, false otherwise.
 	 */
 	public function can_empty_varnish() {
 		return $this->_config->get_boolean( 'varnish.enabled' );
 	}
 
 	/**
+	 * Retrieves the engine used by a specific module.
 	 *
+	 * @param string $module The name of the module.
 	 *
-	 * @param unknown $module
-	 * @return mixed
+	 * @return string The engine associated with the module.
 	 */
 	public function get_module_engine( $module ) {
 		return $this->_config->get_string( "$module.engine" );
 	}
 
+	/**
+	 * Checks if an enabled module uses a specific caching engine.
+	 *
+	 * @param string $module The name of the module.
+	 * @param mixed  $engine The engine or an array of engines to check.
+	 *
+	 * @return bool True if the module uses the specified engine, false otherwise.
+	 */
 	private function _enabled_module_uses_engine( $module, $engine ) {
-		if ( is_array( $engine ) )
-			return $this->is_enabled( $module ) && in_array( $this->get_module_engine( $module ), $engine );
-		else
-			return $this->is_enabled( $module ) && $this->get_module_engine( $module ) == $engine;
+		if ( is_array( $engine ) ) {
+			return $this->is_enabled( $module ) && in_array( $this->get_module_engine( $module ), $engine, true );
+		} else {
+			return $this->is_enabled( $module ) && $this->get_module_engine( $module ) === $engine;
+		}
 	}
 }
diff --git a/ObjectCache_ConfigLabels.php b/ObjectCache_ConfigLabels.php
index 2a84bb859..3f61f4b85 100644
--- a/ObjectCache_ConfigLabels.php
+++ b/ObjectCache_ConfigLabels.php
@@ -1,17 +1,36 @@
 <?php
+/**
+ * File: ObjectCache_ConfigLabels.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class ObjectCache_ConfigLabels
+ */
 class ObjectCache_ConfigLabels {
+	/**
+	 * Merges the provided configuration labels with default object cache labels.
+	 *
+	 * @param array $config_labels Array of configuration labels to be merged.
+	 *
+	 * @return array Merged configuration labels with default object cache labels.
+	 */
 	public function config_labels( $config_labels ) {
-		return array_merge( $config_labels, array(
-				'objectcache.engine' =>  __( 'Object Cache Method:', 'w3-total-cache' ),
-				'objectcache.enabled' => __( 'Object Cache:', 'w3-total-cache' ),
-				'objectcache.debug' =>  __( 'Object Cache', 'w3-total-cache' ),
-				'objectcache.lifetime' => __( 'Default lifetime of cache objects:', 'w3-total-cache' ),
-				'objectcache.file.gc' => __( 'Garbage collection interval:', 'w3-total-cache' ),
-				'objectcache.groups.global' => __( 'Global groups:', 'w3-total-cache' ),
+		return array_merge(
+			$config_labels,
+			array(
+				'objectcache.engine'               => __( 'Object Cache Method:', 'w3-total-cache' ),
+				'objectcache.enabled'              => __( 'Object Cache:', 'w3-total-cache' ),
+				'objectcache.debug'                => __( 'Object Cache', 'w3-total-cache' ),
+				'objectcache.lifetime'             => __( 'Default lifetime of cache objects:', 'w3-total-cache' ),
+				'objectcache.file.gc'              => __( 'Garbage collection interval:', 'w3-total-cache' ),
+				'objectcache.groups.global'        => __( 'Global groups:', 'w3-total-cache' ),
 				'objectcache.groups.nonpersistent' => __( 'Non-persistent groups:', 'w3-total-cache' ),
-				'objectcache.purge.all' => __( 'Flush all cache on post, comment etc changes.', 'w3-total-cache' )
-			) );
+				'objectcache.purge.all'            => __( 'Flush all cache on post, comment etc changes.', 'w3-total-cache' ),
+			)
+		);
 	}
 }
diff --git a/ObjectCache_Environment.php b/ObjectCache_Environment.php
index 79805593b..5133767c8 100644
--- a/ObjectCache_Environment.php
+++ b/ObjectCache_Environment.php
@@ -1,21 +1,30 @@
 <?php
-namespace W3TC;
-
 /**
- * W3 Object Cache plugin - administrative interface
+ * File: ObjectCache_Environment.php
+ *
+ * @package W3TC
  */
 
+namespace W3TC;
+
 /**
- * class ObjectCache_Environment
+ * Class ObjectCache_Environment
+ *
+ * W3 Object Cache plugin - administrative interface
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 class ObjectCache_Environment {
 	/**
-	 * Fixes environment in each wp-admin request
+	 * Fixes the object cache configuration on a WP admin request.
 	 *
-	 * @param Config $config           Config.
-	 * @param bool   $force_all_checks Force checks flag.
+	 * @param object $config           Configuration object.
+	 * @param bool   $force_all_checks Whether to force all checks.
 	 *
-	 * @throws Util_Environment_Exceptions Exceptions.
+	 * @return void
+	 *
+	 * @throws \Util_Environment_Exceptions If there are filesystem operation errors.
 	 */
 	public function fix_on_wpadmin_request( $config, $force_all_checks ) {
 		$exs                 = new Util_Environment_Exceptions();
@@ -39,13 +48,13 @@ public function fix_on_wpadmin_request( $config, $force_all_checks ) {
 	}
 
 	/**
-	 * Fixes environment once event occurs.
+	 * Fixes the object cache configuration based on a specific event.
 	 *
-	 * @param Config      $config     Config.
-	 * @param string      $event      Event.
-	 * @param null|Config $old_config Old Config.
+	 * @param object      $config     Configuration object.
+	 * @param string      $event      Event name.
+	 * @param object|null $old_config Optional old configuration object.
 	 *
-	 * @throws Util_Environment_Exceptions Exception.
+	 * @return void
 	 */
 	public function fix_on_event( $config, $event, $old_config = null ) {
 		$objectcache_enabled = $config->get_boolean( 'objectcache.enabled' );
@@ -68,12 +77,11 @@ public function fix_on_event( $config, $event, $old_config = null ) {
 	}
 
 	/**
-	 * Fixes environment after plugin deactivation.
-	 *
-	 * @throws Util_Environment_Exceptions Exception.
-	 * @throws Util_WpFile_FilesystemOperationException Exception.
+	 * Fixes the object cache configuration after deactivation.
 	 *
 	 * @return void
+	 *
+	 * @throws \Util_Environment_Exceptions If there are filesystem operation errors.
 	 */
 	public function fix_after_deactivation() {
 		$exs = new Util_Environment_Exceptions();
@@ -93,17 +101,20 @@ public function fix_after_deactivation() {
 	}
 
 	/**
-	 * Returns required rules for module
+	 * Retrieves the required rules for the object cache.
 	 *
-	 * @var Config $config
-	 * @return array
+	 * @param object $config Configuration object.
+	 *
+	 * @return null Always returns null.
 	 */
-	function get_required_rules( $config ) {
+	public function get_required_rules( $config ) {
 		return null;
 	}
 
 	/**
-	 * scheduling stuff
+	 * Unschedules the object cache garbage collection.
+	 *
+	 * @return void
 	 */
 	private function unschedule_gc() {
 		if ( wp_next_scheduled( 'w3_objectcache_cleanup' ) ) {
@@ -112,7 +123,7 @@ private function unschedule_gc() {
 	}
 
 	/**
-	 * Remove cron job for object cache purge.
+	 * Unschedules the object cache purge cron job.
 	 *
 	 * @since 2.8.0
 	 *
@@ -125,9 +136,11 @@ private function unschedule_purge_wpcron() {
 	}
 
 	/**
-	 * Creates add-in
+	 * Creates the object cache add-in file.
+	 *
+	 * @return void
 	 *
-	 * @throws Util_WpFile_FilesystemOperationException
+	 * @throws \Util_WpFile_FilesystemOperationException If there is a filesystem operation error.
 	 */
 	private function create_addin() {
 		$src = W3TC_INSTALL_FILE_OBJECT_CACHE;
@@ -136,12 +149,11 @@ private function create_addin() {
 		if ( $this->objectcache_installed() ) {
 			if ( $this->is_objectcache_add_in() ) {
 				$script_data = @file_get_contents( $dst );
-				if ( $script_data == @file_get_contents( $src ) ) {
+				if ( @file_get_contents( $src ) === $script_data ) {
 					return;
 				}
-			} elseif ( 'yes' === get_transient( 'w3tc_remove_add_in_objectcache' ) ) {
-				// user already manually asked to remove another plugin's add in,
-				// we should try to apply ours
+			} elseif ( 'yes' === get_transient( 'w3tc_remove_add_in_objectcache' ) ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElseif
+				// user already manually asked to remove another plugin's add in, we should try to apply ours
 				// (in case of missing permissions deletion could fail).
 			} elseif ( ! $this->is_objectcache_old_add_in() ) {
 				$page_val = Util_Request::get_string( 'page' );
@@ -180,48 +192,54 @@ private function create_addin() {
 	}
 
 	/**
-	 * Deletes add-in
+	 * Deletes the object cache add-in file.
 	 *
-	 * @throws Util_WpFile_FilesystemOperationException
+	 * @return void
 	 */
 	private function delete_addin() {
-		if ( $this->is_objectcache_add_in() )
+		if ( $this->is_objectcache_add_in() ) {
 			Util_WpFile::delete_file( W3TC_ADDIN_FILE_OBJECT_CACHE );
+		}
 	}
 
 	/**
-	 * Returns true if object-cache.php is installed
+	 * Checks if the object cache add-in is installed.
 	 *
-	 * @return boolean
+	 * @return bool True if the object cache add-in is installed, false otherwise.
 	 */
 	public function objectcache_installed() {
 		return file_exists( W3TC_ADDIN_FILE_OBJECT_CACHE );
 	}
 
 	/**
-	 * Returns true if object-cache.php is old version.
+	 * Checks if the object cache add-in is an old version.
 	 *
-	 * @return boolean
+	 * @return bool True if the object cache add-in is an old version, false otherwise.
 	 */
 	public function is_objectcache_old_add_in() {
-		if ( !$this->objectcache_installed() )
+		if ( ! $this->objectcache_installed() ) {
 			return false;
+		}
 
-		return ( ( $script_data = @file_get_contents( W3TC_ADDIN_FILE_OBJECT_CACHE ) )
-			&& ( ( strstr( $script_data, 'W3 Total Cache Object Cache' ) !== false ) ||
-				strstr( $script_data, 'w3_instance' ) !== false ) );
+		$script_data = @file_get_contents( W3TC_ADDIN_FILE_OBJECT_CACHE );
+		return $script_data && (
+			strstr( $script_data, 'W3 Total Cache Object Cache' ) !== false ||
+			strstr( $script_data, 'w3_instance' ) !== false
+		);
 	}
 
 	/**
-	 * Checks if object-cache.php is latest version
+	 * Checks if the object cache add-in is installed and is the correct version.
 	 *
-	 * @return boolean
+	 * @return bool True if the object cache add-in is installed and is the correct version, false otherwise.
 	 */
 	public function is_objectcache_add_in() {
-		if ( !$this->objectcache_installed() )
+		if ( ! $this->objectcache_installed() ) {
 			return false;
+		}
+
+		$script_data = @file_get_contents( W3TC_ADDIN_FILE_OBJECT_CACHE );
 
-		return ( ( $script_data = @file_get_contents( W3TC_ADDIN_FILE_OBJECT_CACHE ) )
-			&& strstr( $script_data, 'ObjectCache Version: 1.5' ) !== false );
+		return $script_data && strstr( $script_data, 'ObjectCache Version: 1.5' ) !== false;
 	}
 }
diff --git a/ObjectCache_Page.php b/ObjectCache_Page.php
index 49390083b..df672d49a 100644
--- a/ObjectCache_Page.php
+++ b/ObjectCache_Page.php
@@ -1,8 +1,17 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: ObjectCache_Page.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class ObjectCache_Page
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ */
 class ObjectCache_Page extends Base_Page_Settings {
 	/**
 	 * Current page
@@ -12,14 +21,13 @@ class ObjectCache_Page extends Base_Page_Settings {
 	protected $_page = 'w3tc_objectcache';
 
 	/**
-	 * Objects cache tab
+	 * Displays the object cache options page.
 	 *
 	 * @return void
 	 */
-	function view() {
+	public function view() {
 		$objectcache_enabled = $this->_config->getf_boolean( 'objectcache.enabled' );
 
 		include W3TC_INC_DIR . '/options/objectcache.php';
 	}
-
 }
diff --git a/ObjectCache_Page_View_PurgeLog.php b/ObjectCache_Page_View_PurgeLog.php
index 7512cf790..110ef39dd 100644
--- a/ObjectCache_Page_View_PurgeLog.php
+++ b/ObjectCache_Page_View_PurgeLog.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: ObjectCache_Page_View_PurgeLog.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
@@ -16,7 +22,7 @@
 	<h1><?php esc_html_e( 'Purges Log', 'w3-total-cache' ); ?></h1>
 
 	<div class="w3tc_purge_log_table">
-		<?php foreach ( $lines as $line ): ?>
+		<?php foreach ( $lines as $line ) : ?>
 			<div class="w3tc_purge_log_date"><?php echo esc_html( $line['date'] ); ?></div>
 			<div class="w3tc_purge_log_message"><td><?php echo esc_html( $line['message'] ); ?></div>
 			<div class="w3tc_purge_log_backtrace">
diff --git a/ObjectCache_Plugin.php b/ObjectCache_Plugin.php
index 9553960f1..5dcddb0a2 100644
--- a/ObjectCache_Plugin.php
+++ b/ObjectCache_Plugin.php
@@ -30,17 +30,24 @@ class ObjectCache_Plugin {
 	private static $flushed = false;
 
 	/**
-	 * Constructor.
+	 * Constructs the ObjectCache_Plugin class and initializes configuration.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs plugin
+	 * Registers necessary actions and filters for object cache functionality.
+	 *
+	 * phpcs:disable WordPress.WP.CronInterval.ChangeDetected
+	 *
+	 * @link https://developer.wordpress.org/reference/hooks/updated_option/
+	 *
+	 * @return void
 	 */
 	public function run() {
-		// @link https://developer.wordpress.org/reference/hooks/updated_option/
 		add_action( 'updated_option', array( $this, 'delete_option_cache' ), 10, 0 );
 
 		add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) );
@@ -61,20 +68,18 @@ public function run() {
 	}
 
 	/**
-	 * Delete the options cache object.
+	 * Deletes the cache for all options.
 	 *
 	 * @since 2.7.6
 	 *
-	 * @link https://developer.wordpress.org/reference/functions/wp_cache_delete/
-	 *
-	 * @return bool
+	 * @return bool True on successful removal, false on failure.
 	 */
 	public function delete_option_cache() {
 		return wp_cache_delete( 'alloptions', 'options' );
 	}
 
 	/**
-	 * Does disk cache cleanup
+	 * Cleans up object cache files based on the configured time limit.
 	 *
 	 * @return void
 	 */
@@ -90,11 +95,11 @@ public function cleanup() {
 	}
 
 	/**
-	 * Cron schedules filter
+	 * Adds custom cron schedules for object cache cleanup.
 	 *
-	 * @param array $schedules Schedules.
+	 * @param array $schedules Existing cron schedules.
 	 *
-	 * @return array
+	 * @return array Modified cron schedules.
 	 */
 	public function cron_schedules( $schedules ) {
 		$c                   = $this->_config;
@@ -117,7 +122,7 @@ public function cron_schedules( $schedules ) {
 	}
 
 	/**
-	 * Cron job for processing purging object cache.
+	 * Purges the object cache via WP-Cron.
 	 *
 	 * @since 2.8.0
 	 *
@@ -129,9 +134,11 @@ public function w3tc_objectcache_purge_wpcron() {
 	}
 
 	/**
-	 * Setup admin menu elements
+	 * Adds an item to the admin bar menu for object cache flushing.
+	 *
+	 * @param array $menu_items Existing menu items.
 	 *
-	 * @param array $menu_items Menu items.
+	 * @return array Modified menu items.
 	 */
 	public function w3tc_admin_bar_menu( $menu_items ) {
 		$menu_items['20410.objectcache'] = array(
@@ -145,9 +152,11 @@ public function w3tc_admin_bar_menu( $menu_items ) {
 	}
 
 	/**
-	 * Setup admin menu elements
+	 * Adds a footer comment related to object cache to the strings.
+	 *
+	 * @param string $strings Existing footer strings.
 	 *
-	 * @param array $strings Strings.
+	 * @return string Modified footer strings.
 	 */
 	public function w3tc_footer_comment( $strings ) {
 		$o       = Dispatcher::component( 'ObjectCache_WpObjectCache_Regular' );
@@ -157,9 +166,11 @@ public function w3tc_footer_comment( $strings ) {
 	}
 
 	/**
-	 * Usage statistics of request filter
+	 * Collects usage statistics for the object cache.
 	 *
-	 * @param object $storage Storage object.
+	 * @param mixed $storage Data storage to collect statistics.
+	 *
+	 * @return void
 	 */
 	public function w3tc_usage_statistics_of_request( $storage ) {
 		$o = Dispatcher::component( 'ObjectCache_WpObjectCache_Regular' );
@@ -167,9 +178,11 @@ public function w3tc_usage_statistics_of_request( $storage ) {
 	}
 
 	/**
-	 * Retrive usage statistics metrics
+	 * Adds object cache metrics to the usage statistics.
+	 *
+	 * @param array $metrics Existing metrics.
 	 *
-	 * @param array $metrics Metrics.
+	 * @return array Modified metrics.
 	 */
 	public function w3tc_usage_statistics_metrics( $metrics ) {
 		$metrics = array_merge(
@@ -187,11 +200,11 @@ public function w3tc_usage_statistics_metrics( $metrics ) {
 	}
 
 	/**
-	 * Usage Statisitcs sources filter.
+	 * Adds object cache sources to the usage statistics.
 	 *
-	 * @param array $sources Sources.
+	 * @param array $sources Existing sources.
 	 *
-	 * @return array
+	 * @return array Modified sources.
 	 */
 	public function w3tc_usage_statistics_sources( $sources ) {
 		$c = Dispatcher::config();
diff --git a/ObjectCache_Plugin_Admin.php b/ObjectCache_Plugin_Admin.php
index 7fba1a17d..76732ca0f 100644
--- a/ObjectCache_Plugin_Admin.php
+++ b/ObjectCache_Plugin_Admin.php
@@ -1,8 +1,22 @@
 <?php
+/**
+ * File: ObjectCache_Plugin_Admin.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class ObjectCache_Plugin_Admin
+ */
 class ObjectCache_Plugin_Admin {
-	function run() {
+	/**
+	 * Registers necessary filters and actions.
+	 *
+	 * @return void
+	 */
+	public function run() {
 		add_filter( 'w3tc_save_options', array( $this, 'w3tc_save_options' ) );
 
 		$config_labels = new ObjectCache_ConfigLabels();
@@ -12,14 +26,20 @@ function run() {
 		if ( $c->getf_boolean( 'objectcache.enabled' ) ) {
 			add_filter( 'w3tc_errors', array( $this, 'w3tc_errors' ) );
 			add_filter( 'w3tc_notes', array( $this, 'w3tc_notes' ) );
-			add_filter( 'w3tc_usage_statistics_summary_from_history', array(
-					$this, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
+			add_filter( 'w3tc_usage_statistics_summary_from_history', array( $this, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
 		}
 
 		add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
 		add_action( 'w3tc_ajax_objectcache_diskpopup', array( $this, 'w3tc_ajax_objectcache_diskpopup' ) );
 	}
 
+	/**
+	 * Handles saving of options, scheduling or clearing cron events for object cache.
+	 *
+	 * @param array $data Associative array containing 'new_config' and 'old_config' values.
+	 *
+	 * @return array Modified data array with options.
+	 */
 	public function w3tc_save_options( $data ) {
 		$new_config = $data['new_config'];
 		$old_config = $data['old_config'];
@@ -49,80 +69,108 @@ public function w3tc_save_options( $data ) {
 		return $data;
 	}
 
+	/**
+	 * Checks and adds errors related to the memcached configuration.
+	 *
+	 * @param array $errors Existing errors to be modified or added to.
+	 *
+	 * @return array Modified errors array.
+	 */
 	public function w3tc_errors( $errors ) {
 		$c = Dispatcher::config();
 
-		if ( $c->get_string( 'objectcache.engine' ) == 'memcached' ) {
-			$memcached_servers = $c->get_array(
-				'objectcache.memcached.servers' );
-			$memcached_binary_protocol = $c->get_boolean(
-				'objectcache.memcached.binary_protocol' );
-			$memcached_username = $c->get_string(
-				'objectcache.memcached.username' );
-			$memcached_password = $c->get_string(
-				'objectcache.memcached.password' );
-
-			if ( !Util_Installed::is_memcache_available( $memcached_servers, $memcached_binary_protocol, $memcached_username, $memcached_password ) ) {
-				if ( !isset( $errors['memcache_not_responding.details'] ) )
+		if ( 'memcached' === $c->get_string( 'objectcache.engine' ) ) {
+			$memcached_servers         = $c->get_array( 'objectcache.memcached.servers' );
+			$memcached_binary_protocol = $c->get_boolean( 'objectcache.memcached.binary_protocol' );
+			$memcached_username        = $c->get_string( 'objectcache.memcached.username' );
+			$memcached_password        = $c->get_string( 'objectcache.memcached.password' );
+
+			if (
+				! Util_Installed::is_memcache_available(
+					$memcached_servers,
+					$memcached_binary_protocol,
+					$memcached_username,
+					$memcached_password
+				)
+			) {
+				if ( ! isset( $errors['memcache_not_responding.details'] ) ) {
 					$errors['memcache_not_responding.details'] = array();
+				}
 
 				$errors['memcache_not_responding.details'][] = sprintf(
-					__( 'Object Cache: %s.', 'w3-total-cache' ),
-					implode( ', ', $memcached_servers ) );
+					// Translators: 1 memecached servers.
+					__(
+						'Object Cache: %1$s.',
+						'w3-total-cache'
+					),
+					implode( ', ', $memcached_servers )
+				);
 			}
 		}
 
 		return $errors;
 	}
 
-
-
+	/**
+	 * Adds notes related to object cache state and actions needed.
+	 *
+	 * @param array $notes Existing notes to be modified or added to.
+	 *
+	 * @return array Modified notes array.
+	 */
 	public function w3tc_notes( $notes ) {
-		$c = Dispatcher::config();
-		$state = Dispatcher::config_state();
+		$c          = Dispatcher::config();
+		$state      = Dispatcher::config_state();
 		$state_note = Dispatcher::config_state_note();
 
-		/**
-		 * Show notification when object cache needs to be emptied
-		 */
-		if ( $state_note->get( 'objectcache.show_note.flush_needed' ) &&
-			!is_network_admin() /* flushed dont work under network admin */ &&
-			!$c->is_preview() ) {
+		// Show notification when object cache needs to be emptied.
+		if (
+			$state_note->get( 'objectcache.show_note.flush_needed' ) &&
+			! is_network_admin() && // flushed dont work under network admin.
+			! $c->is_preview()
+		) {
 			$notes['objectcache_flush_needed'] = sprintf(
-				__( 'The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.',
-					'w3-total-cache' ),
+				// Translators: 1 object cache flush button.
+				__(
+					'The setting change(s) made either invalidate the cached data or modify the behavior of the site. %1$s now to provide a consistent user experience.',
+					'w3-total-cache'
+				),
 				Util_Ui::button_link(
 					__( 'Empty the object cache', 'w3-total-cache' ),
-					Util_Ui::url( array( 'w3tc_flush_objectcache' => 'y' ) ) ) );
+					Util_Ui::url( array( 'w3tc_flush_objectcache' => 'y' ) )
+				)
+			);
 		}
 
 		return $notes;
 	}
 
-
-
+	/**
+	 * Summarizes usage statistics for object cache from history data.
+	 *
+	 * @param array $summary Current summary of usage statistics.
+	 * @param array $history Array containing historical usage data.
+	 *
+	 * @return array Modified summary with object cache usage data.
+	 */
 	public function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
-		// counters
+		// counters.
 		$get_total = Util_UsageStatistics::sum( $history, 'objectcache_get_total' );
-		$get_hits = Util_UsageStatistics::sum( $history, 'objectcache_get_hits' );
-		$sets = Util_UsageStatistics::sum( $history, 'objectcache_sets' );
+		$get_hits  = Util_UsageStatistics::sum( $history, 'objectcache_get_hits' );
+		$sets      = Util_UsageStatistics::sum( $history, 'objectcache_sets' );
 
 		$c = Dispatcher::config();
 		$e = $c->get_string( 'objectcache.engine' );
 
 		$summary['objectcache'] = array(
-			'get_total' => Util_UsageStatistics::integer( $get_total ),
-			'get_hits' => Util_UsageStatistics::integer( $get_hits ),
-			'sets' => Util_UsageStatistics::integer( $sets ),
-			'flushes' => Util_UsageStatistics::integer(
-				Util_UsageStatistics::sum( $history, 'objectcache_flushes' ) ),
-			'time_ms' => Util_UsageStatistics::integer(
-				Util_UsageStatistics::sum( $history, 'objectcache_time_ms' ) ),
-			'calls_per_second' => Util_UsageStatistics::value_per_period_seconds(
-				$get_total + $sets, $summary ),
-			'hit_rate' => Util_UsageStatistics::percent(
-				$get_hits, $get_total ),
-			'engine_name' => Cache::engine_name( $e )
+			'get_total'        => Util_UsageStatistics::integer( $get_total ),
+			'get_hits'         => Util_UsageStatistics::integer( $get_hits ),
+			'sets'             => Util_UsageStatistics::integer( $sets ),
+			'flushes'          => Util_UsageStatistics::integer( Util_UsageStatistics::sum( $history, 'objectcache_flushes' ) ),
+			'time_ms'          => Util_UsageStatistics::integer( Util_UsageStatistics::sum( $history, 'objectcache_time_ms' ) ),
+			'calls_per_second' => Util_UsageStatistics::value_per_period_seconds( $get_total + $sets, $summary ),
+			'hit_rate'         => Util_UsageStatistics::percent( $get_hits, $get_total ),
+			'engine_name'      => Cache::engine_name( $e ),
 		);
 
 		return $summary;
diff --git a/ObjectCache_WpObjectCache.php b/ObjectCache_WpObjectCache.php
index a5b6981f2..52bc2a090 100644
--- a/ObjectCache_WpObjectCache.php
+++ b/ObjectCache_WpObjectCache.php
@@ -4,7 +4,8 @@
  *
  * @package W3TC
  *
- * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore, PSR2.Methods.MethodDeclaration.Underscore
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
  */
 
 namespace W3TC;
@@ -62,7 +63,9 @@ class ObjectCache_WpObjectCache {
 	);
 
 	/**
-	 * PHP5 style constructor
+	 * Constructor for the ObjectCache_WpObjectCache class.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$this->_config        = Dispatcher::config();
@@ -71,11 +74,12 @@ public function __construct() {
 	}
 
 	/**
-	 * Registers cache object so that its used for specific groups of
-	 * object cache instead of default cache
+	 * Registers a new cache engine to be used for object groups.
+	 *
+	 * @param object $cache                 The cache engine to register.
+	 * @param array  $use_for_object_groups Array of object groups this cache should be used for.
 	 *
-	 * @param object $cache                 Cache.
-	 * @param array  $use_for_object_groups Use for object groups.
+	 * @return void
 	 */
 	public function register_cache( $cache, $use_for_object_groups ) {
 		$this->_caches[] = $cache;
@@ -86,14 +90,14 @@ public function register_cache( $cache, $use_for_object_groups ) {
 	}
 
 	/**
-	 * Get from the cache
+	 * Retrieves a cached value by its ID from the specified group.
 	 *
-	 * @param string    $id    ID.
-	 * @param string    $group Group.
-	 * @param bool      $force Force.
-	 * @param bool|null $found Found.
+	 * @param string $id    The cache key.
+	 * @param string $group The cache group.
+	 * @param bool   $force Whether to force a cache retrieval, bypassing the cache expiration.
+	 * @param mixed  $found A reference to the variable that will store whether the value was found.
 	 *
-	 * @return mixed
+	 * @return mixed The cached value if found, otherwise false.
 	 */
 	public function get( $id, $group = 'default', $force = false, &$found = null ) {
 		$cache = $this->_get_engine( $group );
@@ -101,17 +105,15 @@ public function get( $id, $group = 'default', $force = false, &$found = null ) {
 	}
 
 	/**
-	 * Retrieves multiple values from the cache in one call.
+	 * Retrieves multiple cached values by their IDs from the specified group.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $ids  Array of keys under which the cache contents are stored.
-	 * @param string $group Optional. Where the cache contents are grouped. Default 'default'.
-	 * @param bool   $force Optional. Whether to force an update of the local cache
-	 *                      from the persistent cache. Default false.
+	 * @param array  $ids    The cache keys.
+	 * @param string $group  The cache group.
+	 * @param bool   $force  Whether to force a cache retrieval, bypassing the cache expiration.
 	 *
-	 * @return array Array of return values, grouped by key. Each value is either
-	 *               the cache contents on success, or false on failure.
+	 * @return array An array of cached values, indexed by their respective IDs.
 	 */
 	public function get_multiple( $ids, $group = 'default', $force = false ) {
 		$cache = $this->_get_engine( $group );
@@ -119,14 +121,14 @@ public function get_multiple( $ids, $group = 'default', $force = false ) {
 	}
 
 	/**
-	 * Set to the cache
+	 * Sets a cache value for a given ID and group.
 	 *
-	 * @param string  $id     ID.
-	 * @param mixed   $data   Data.
-	 * @param string  $group  Group.
-	 * @param integer $expire Expire.
+	 * @param string $id     The cache key.
+	 * @param mixed  $data   The data to store in the cache.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The cache expiration time in seconds.
 	 *
-	 * @return boolean
+	 * @return bool True if the data was successfully cached, otherwise false.
 	 */
 	public function set( $id, $data, $group = 'default', $expire = 0 ) {
 		$cache = $this->_get_engine( $group );
@@ -134,16 +136,15 @@ public function set( $id, $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Sets multiple values to the cache in one call.
+	 * Sets multiple cache values for their respective IDs and groups.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $data   Array of key and value to be set.
-	 * @param string $group  Optional. Where the cache contents are grouped. Default empty.
-	 * @param int    $expire Optional. When to expire the cache contents, in seconds.
-	 *                       Default 0 (no expiration).
+	 * @param array  $data   An array of data indexed by cache key.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The cache expiration time in seconds.
 	 *
-	 * @return bool[] Array of return values, grouped by key. Each value is always true.
+	 * @return bool True if the data was successfully cached, otherwise false.
 	 */
 	public function set_multiple( $data, $group = 'default', $expire = 0 ) {
 		$cache = $this->_get_engine( $group );
@@ -151,13 +152,13 @@ public function set_multiple( $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Delete from the cache
+	 * Deletes a cached value by its ID from the specified group.
 	 *
-	 * @param string $id    ID.
-	 * @param string $group Group.
-	 * @param bool   $force Force.
+	 * @param string $id    The cache key.
+	 * @param string $group The cache group.
+	 * @param bool   $force Whether to forcefully delete the cache.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was successfully deleted, otherwise false.
 	 */
 	public function delete( $id, $group = 'default', $force = false ) {
 		$cache = $this->_get_engine( $group );
@@ -165,30 +166,30 @@ public function delete( $id, $group = 'default', $force = false ) {
 	}
 
 	/**
-	 * Deletes multiple values from the cache in one call.
+	 * Deletes multiple cached values by their IDs from the specified group.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $keys  Array of keys to be deleted.
-	 * @param string $group Optional. Where the cache contents are grouped. Default empty.
+	 * @param array  $keys  The cache keys.
+	 * @param string $group The cache group.
 	 *
-	 * @return bool[] Array of return values, grouped by key. Each value is either
-	 *                true on success, or false if the contents were not deleted.
+	 * @return bool True if the caches were successfully deleted, otherwise false.
 	 */
 	public function delete_multiple( $keys, $group = 'default' ) {
 		$cache = $this->_get_engine( $group );
 		return $cache->delete_multiple( $keys, $group );
 	}
 
+
 	/**
-	 * Add to the cache
+	 * Adds a new value to the cache if it does not already exist for the given ID and group.
 	 *
-	 * @param string  $id     ID.
-	 * @param mixed   $data   Data.
-	 * @param string  $group  Group.
-	 * @param integer $expire Expire.
+	 * @param string $id     The cache key.
+	 * @param mixed  $data   The data to store in the cache.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The cache expiration time in seconds.
 	 *
-	 * @return boolean
+	 * @return bool True if the data was added, otherwise false.
 	 */
 	public function add( $id, $data, $group = 'default', $expire = 0 ) {
 		$cache = $this->_get_engine( $group );
@@ -196,17 +197,15 @@ public function add( $id, $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Adds multiple values to the cache in one call.
+	 * Adds multiple new values to the cache, ensuring they do not overwrite existing data.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $data   Array of keys and values to be added.
-	 * @param string $group  Optional. Where the cache contents are grouped. Default empty.
-	 * @param int    $expire Optional. When to expire the cache contents, in seconds.
-	 *                       Default 0 (no expiration).
+	 * @param array  $data   An array of data indexed by cache key.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The cache expiration time in seconds.
 	 *
-	 * @return bool[] Array of return values, grouped by key. Each value is either
-	 *                true on success, or false if cache key and group already exist.
+	 * @return bool True if the data was successfully added, otherwise false.
 	 */
 	public function add_multiple( array $data, $group = '', $expire = 0 ) {
 		$cache = $this->_get_engine( $group );
@@ -214,14 +213,14 @@ public function add_multiple( array $data, $group = '', $expire = 0 ) {
 	}
 
 	/**
-	 * Replace in the cache
+	 * Replaces a cache value for the given ID and group.
 	 *
-	 * @param string  $id     ID.
-	 * @param mixed   $data   Data.
-	 * @param string  $group  Group.
-	 * @param integer $expire Expire.
+	 * @param string $id     The cache key.
+	 * @param mixed  $data   The data to store in the cache.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The cache expiration time in seconds.
 	 *
-	 * @return boolean
+	 * @return bool True if the data was successfully replaced, otherwise false.
 	 */
 	public function replace( $id, $data, $group = 'default', $expire = 0 ) {
 		$cache = $this->_get_engine( $group );
@@ -229,9 +228,9 @@ public function replace( $id, $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Reset keys
+	 * Resets the cache, clearing all stored data.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was successfully reset, otherwise false.
 	 */
 	public function reset() {
 		$result = true;
@@ -244,9 +243,9 @@ public function reset() {
 	}
 
 	/**
-	 * Flush cache
+	 * Flushes all cached data across all cache engines.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was successfully flushed, otherwise false.
 	 */
 	public function flush() {
 		$result = true;
@@ -259,11 +258,11 @@ public function flush() {
 	}
 
 	/**
-	 * Flush group.
+	 * Flushes the cached data for a specific group.
 	 *
-	 * @param string $group Group.
+	 * @param string $group  The cache group.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache for the group was successfully flushed, otherwise false.
 	 */
 	public function flush_group( $group ) {
 		$result = true;
@@ -276,9 +275,9 @@ public function flush_group( $group ) {
 	}
 
 	/**
-	 * Flush runtime.
+	 * Flushes runtime cache data that is temporary and non-persistent.
 	 *
-	 * @return boolean
+	 * @return bool True if the runtime cache was successfully flushed, otherwise false.
 	 */
 	public function flush_runtime() {
 		$result = true;
@@ -291,20 +290,20 @@ public function flush_runtime() {
 	}
 
 	/**
-	 * Check supported features.
+	 * Checks if a given cache feature is supported.
 	 *
-	 * @param string $feature Feature.
+	 * @param string $feature The feature to check.
 	 *
-	 * @return boolean
+	 * @return bool True if the feature is supported, otherwise false.
 	 */
 	public function supports( string $feature ) {
 		return in_array( $feature, $this->supported_features, true );
 	}
 
 	/**
-	 * Add global groups
+	 * Adds global cache groups to the cache engine.
 	 *
-	 * @param array $groups Groups.
+	 * @param mixed $groups An array or string of cache groups to add as global.
 	 *
 	 * @return void
 	 */
@@ -320,9 +319,9 @@ public function add_global_groups( $groups ) {
 	}
 
 	/**
-	 * Add non-persistent groups
+	 * Adds non-persistent cache groups to the cache engine.
 	 *
-	 * @param array $groups Groups.
+	 * @param mixed $groups An array or string of cache groups to add as non-persistent.
 	 *
 	 * @return void
 	 */
@@ -338,11 +337,11 @@ public function add_nonpersistent_groups( $groups ) {
 	}
 
 	/**
-	 * Return engine based on which group the OC value belongs to.
+	 * Retrieves the appropriate cache engine based on the group.
 	 *
-	 * @param string $group Group.
+	 * @param string $group The cache group.
 	 *
-	 * @return mixed
+	 * @return object The cache engine for the specified group.
 	 */
 	private function _get_engine( $group = '' ) {
 		if ( isset( $this->_cache_by_group[ $group ] ) ) {
@@ -353,13 +352,13 @@ private function _get_engine( $group = '' ) {
 	}
 
 	/**
-	 * Decrement numeric cache item's value
+	 * Decreases the cached value of a given ID by a specified offset.
 	 *
-	 * @param int|string $id     The cache key to increment.
-	 * @param int        $offset The amount by which to decrement the item's value. Default is 1.
-	 * @param string     $group  The group the key is in.
+	 * @param string $id     The cache key.
+	 * @param int    $offset The value to decrease by.
+	 * @param string $group  The cache group.
 	 *
-	 * @return bool|int False on failure, the item's new value on success.
+	 * @return mixed The updated value if successful, otherwise false.
 	 */
 	public function decr( $id, $offset = 1, $group = 'default' ) {
 		$cache = $this->_get_engine( $group );
@@ -367,13 +366,13 @@ public function decr( $id, $offset = 1, $group = 'default' ) {
 	}
 
 	/**
-	 * Increment numeric cache item's value
+	 * Increases the cached value of a given ID by a specified offset.
 	 *
-	 * @param int|string $id     The cache key to increment.
-	 * @param int        $offset The amount by which to increment the item's value. Default is 1.
-	 * @param string     $group  The group the key is in.
+	 * @param string $id     The cache key.
+	 * @param int    $offset The value to increase by.
+	 * @param string $group  The cache group.
 	 *
-	 * @return false|int False on failure, the item's new value on success.
+	 * @return mixed The updated value if successful, otherwise false.
 	 */
 	public function incr( $id, $offset = 1, $group = 'default' ) {
 		$cache = $this->_get_engine( $group );
@@ -381,9 +380,9 @@ public function incr( $id, $offset = 1, $group = 'default' ) {
 	}
 
 	/**
-	 * Switch to blog
+	 * Switches to a different blog context in a multisite environment.
 	 *
-	 * @param int $blog_id Blog ID.
+	 * @param int $blog_id The blog ID to switch to.
 	 *
 	 * @return void
 	 */
diff --git a/ObjectCache_WpObjectCache_Regular.php b/ObjectCache_WpObjectCache_Regular.php
index fc448e366..d8317bcc9 100644
--- a/ObjectCache_WpObjectCache_Regular.php
+++ b/ObjectCache_WpObjectCache_Regular.php
@@ -4,7 +4,9 @@
  *
  * @package W3TC
  *
- * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore, PSR2.Methods.MethodDeclaration.Underscore
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 
 namespace W3TC;
@@ -153,7 +155,9 @@ class ObjectCache_WpObjectCache_Regular {
 	);
 
 	/**
-	 * PHP5 style constructor
+	 * Constructs the object cache instance and initializes various settings.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$this->_config              = Dispatcher::config();
@@ -168,14 +172,14 @@ public function __construct() {
 	}
 
 	/**
-	 * Get from the cache
+	 * Retrieves a cached object from the object cache.
 	 *
-	 * @param string    $id    ID.
-	 * @param string    $group Group.
-	 * @param bool      $force Force.
-	 * @param bool|null $found Found.
+	 * @param string $id    The cache key.
+	 * @param string $group The cache group.
+	 * @param bool   $force Whether to force a cache refresh.
+	 * @param bool   $found A reference to a boolean variable indicating whether the cache was found.
 	 *
-	 * @return mixed
+	 * @return mixed The cached object or false if not found.
 	 */
 	public function get( $id, $group = 'default', $force = false, &$found = null ) {
 		// Abort if this is a WP-CLI call, objectcache engine is set to Disk, and is disabled for WP-CLI.
@@ -260,9 +264,7 @@ public function get( $id, $group = 'default', $force = false, &$found = null ) {
 			$this->cache[ $key ] = $value;
 		}
 
-		/**
-		 * Add debug info
-		 */
+		// Add debug info.
 		if ( ! $in_incall_cache ) {
 			$this->cache_total += $cache_total_inc;
 			$this->cache_hits  += $cache_hits_inc;
@@ -309,15 +311,15 @@ public function get( $id, $group = 'default', $force = false, &$found = null ) {
 	}
 
 	/**
-	 * Get multiple from the cache
+	 * Retrieves multiple cached objects.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $ids   IDs.
-	 * @param string $group Group.
-	 * @param bool   $force Force flag.
+	 * @param array  $ids    An array of cache keys.
+	 * @param string $group  The cache group.
+	 * @param bool   $force  Whether to force a cache refresh.
 	 *
-	 * @return mixed
+	 * @return array An associative array of cached objects, indexed by cache key.
 	 */
 	public function get_multiple( $ids, $group = 'default', $force = false ) {
 		$found_cache = array();
@@ -330,14 +332,14 @@ public function get_multiple( $ids, $group = 'default', $force = false ) {
 	}
 
 	/**
-	 * Set to the cache
+	 * Sets a cached object in the object cache.
 	 *
-	 * @param string  $id     ID.
-	 * @param mixed   $data   Data.
-	 * @param string  $group  Group.
-	 * @param integer $expire Expire.
+	 * @param string $id      The cache key.
+	 * @param mixed  $data    The data to cache.
+	 * @param string $group   The cache group.
+	 * @param int    $expire  The expiration time, in seconds.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was set successfully, false otherwise.
 	 */
 	public function set( $id, $data, $group = 'default', $expire = 0 ) {
 		// Abort if this is a WP-CLI call, objectcache engine is set to Disk, and is disabled for WP-CLI.
@@ -432,17 +434,15 @@ public function set( $id, $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Sets multiple values to the cache in one call.
+	 * Sets multiple cached objects.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $data   Array of keys and values to be set.
-	 * @param string $group  Optional. Where the cache contents are grouped. Default empty.
-	 * @param int    $expire Optional. When to expire the cache contents, in seconds.
-	 *                       Default 0 (no expiration).
+	 * @param array  $data   An associative array of data to cache, indexed by cache key.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The expiration time, in seconds.
 	 *
-	 * @return bool[] Array of return values, grouped by key. Each value is either
-	 *                true on success, or false on failure.
+	 * @return array An associative array of cache set results, indexed by cache key.
 	 */
 	public function set_multiple( array $data, $group = '', $expire = 0 ) {
 		$values = array();
@@ -453,13 +453,13 @@ public function set_multiple( array $data, $group = '', $expire = 0 ) {
 	}
 
 	/**
-	 * Delete from the cache
+	 * Deletes a cached object from the object cache.
 	 *
-	 * @param string $id    ID.
-	 * @param string $group Group.
-	 * @param bool   $force Force.
+	 * @param string $id    The cache key.
+	 * @param string $group The cache group.
+	 * @param bool   $force Whether to force a cache deletion.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was deleted, false otherwise.
 	 */
 	public function delete( $id, $group = 'default', $force = false ) {
 		if ( ! $force && $this->get( $id, $group ) === false ) {
@@ -499,15 +499,14 @@ public function delete( $id, $group = 'default', $force = false ) {
 	}
 
 	/**
-	 * Deletes multiple values from the cache in one call.
+	 * Deletes multiple cached objects.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $keys  Array of keys under which the cache to deleted.
-	 * @param string $group Optional. Where the cache contents are grouped. Default empty.
+	 * @param array  $keys   An array of cache keys to delete.
+	 * @param string $group  The cache group.
 	 *
-	 * @return bool[] Array of return values, grouped by key. Each value is either
-	 *                true on success, or false if the contents were not deleted.
+	 * @return array An associative array of cache delete results, indexed by cache key.
 	 */
 	public function delete_multiple( array $keys, $group = '' ) {
 		$values = array();
@@ -518,14 +517,14 @@ public function delete_multiple( array $keys, $group = '' ) {
 	}
 
 	/**
-	 * Add to the cache
+	 * Adds a cached object to the object cache if it doesn't already exist.
 	 *
-	 * @param string  $id     ID.
-	 * @param mixed   $data   Data.
-	 * @param string  $group  Group.
-	 * @param integer $expire Expire.
+	 * @param string $id     The cache key.
+	 * @param mixed  $data   The data to cache.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The expiration time, in seconds.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was added, false otherwise.
 	 */
 	public function add( $id, $data, $group = 'default', $expire = 0 ) {
 		if ( $this->get( $id, $group ) !== false ) {
@@ -536,17 +535,15 @@ public function add( $id, $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Add multiple to the cache
+	 * Adds multiple cached objects to the object cache if they don't already exist.
 	 *
 	 * @since 2.2.8
 	 *
-	 * @param array  $data   Array of keys and values to be added.
-	 * @param string $group  Optional. Where the cache contents are grouped. Default empty.
-	 * @param int    $expire Optional. When to expire the cache contents, in seconds.
-	 *                       Default 0 (no expiration).
+	 * @param array  $data   An associative array of data to cache, indexed by cache key.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The expiration time, in seconds.
 	 *
-	 * @return bool[] Array of return values, grouped by key. Each value is either
-	 *                true on success, or false if cache key and group already exist.
+	 * @return array An associative array of cache add results, indexed by cache key.
 	 */
 	public function add_multiple( array $data, $group = '', $expire = 0 ) {
 		$values = array();
@@ -557,14 +554,14 @@ public function add_multiple( array $data, $group = '', $expire = 0 ) {
 	}
 
 	/**
-	 * Replace in the cache
+	 * Replaces a cached object in the object cache if it already exists.
 	 *
-	 * @param string  $id     ID.
-	 * @param mixed   $data   Data.
-	 * @param string  $group  Group.
-	 * @param integer $expire Expire.
+	 * @param string $id     The cache key.
+	 * @param mixed  $data   The data to cache.
+	 * @param string $group  The cache group.
+	 * @param int    $expire The expiration time, in seconds.
 	 *
-	 * @return boolean
+	 * @return bool True if the cache was replaced, false otherwise.
 	 */
 	public function replace( $id, $data, $group = 'default', $expire = 0 ) {
 		if ( $this->get( $id, $group ) === false ) {
@@ -575,7 +572,7 @@ public function replace( $id, $data, $group = 'default', $expire = 0 ) {
 	}
 
 	/**
-	 * Reset keys
+	 * Resets the cache by flushing runtime data.
 	 *
 	 * @return void
 	 */
@@ -584,11 +581,11 @@ public function reset() {
 	}
 
 	/**
-	 * Flush cache
+	 * Flushes the entire object cache.
 	 *
-	 * @param string $reason Reason.
+	 * @param string $reason The reason for flushing the cache.
 	 *
-	 * @return boolean
+	 * @return bool Always returns true.
 	 */
 	public function flush( $reason = '' ) {
 		if ( $this->_debug || $this->stats_enabled ) {
@@ -638,9 +635,9 @@ public function flush( $reason = '' ) {
 	}
 
 	/**
-	 * Flush runtime.
+	 * Clears all cached data in runtime.
 	 *
-	 * @return boolean
+	 * @return bool Returns true on success.
 	 */
 	public function flush_runtime() {
 		$this->cache = array();
@@ -670,22 +667,22 @@ public function flush_runtime() {
 	}
 
 	/**
-	 * Check supported features.
+	 * Checks if a specific feature is supported.
 	 *
-	 * @param string $feature Feature.
+	 * @param string $feature Feature to check for.
 	 *
-	 * @return boolean
+	 * @return bool Returns true if the feature is supported.
 	 */
 	public function supports( string $feature ) {
 		return in_array( $feature, $this->supported_features, true );
 	}
 
 	/**
-	 * Flush group.
+	 * Clears the cache for a specific group.
 	 *
-	 * @param string $group Group.
+	 * @param string $group The cache group to flush.
 	 *
-	 * @return boolean
+	 * @return bool Returns true on success.
 	 */
 	public function flush_group( $group ) {
 		if ( $this->_debug || $this->stats_enabled ) {
@@ -741,9 +738,9 @@ public function flush_group( $group ) {
 	}
 
 	/**
-	 * Add global groups
+	 * Adds global groups to be cached.
 	 *
-	 * @param array $groups Groups.
+	 * @param array|string $groups Groups to be added.
 	 *
 	 * @return void
 	 */
@@ -757,9 +754,9 @@ public function add_global_groups( $groups ) {
 	}
 
 	/**
-	 * Add non-persistent groups
+	 * Adds non-persistent groups to be cached.
 	 *
-	 * @param array $groups Groups.
+	 * @param array|string $groups Groups to be added.
 	 *
 	 * @return void
 	 */
@@ -773,13 +770,13 @@ public function add_nonpersistent_groups( $groups ) {
 	}
 
 	/**
-	 * Increment numeric cache item's value
+	 * Increments the value of a cached key.
 	 *
-	 * @param int|string $key    The cache key to increment.
-	 * @param int        $offset The amount by which to increment the item's value. Default is 1.
-	 * @param string     $group  The group the key is in.
+	 * @param string $key    The cache key to increment.
+	 * @param int    $offset The value to increment by.
+	 * @param string $group  The group the cache belongs to.
 	 *
-	 * @return bool|int False on failure, the item's new value on success.
+	 * @return int|false Returns the new value on success, or false if the key does not exist.
 	 */
 	public function incr( $key, $offset = 1, $group = 'default' ) {
 		$value = $this->get( $key, $group );
@@ -805,13 +802,13 @@ public function incr( $key, $offset = 1, $group = 'default' ) {
 	}
 
 	/**
-	 * Decrement numeric cache item's value
+	 * Decrements the value of a cached key.
 	 *
-	 * @param int|string $key    The cache key to increment.
-	 * @param int        $offset The amount by which to decrement the item's value. Default is 1.
-	 * @param string     $group  The group the key is in.
+	 * @param string $key    The cache key to decrement.
+	 * @param int    $offset The value to decrement by.
+	 * @param string $group  The group the cache belongs to.
 	 *
-	 * @return bool|int False on failure, the item's new value on success.
+	 * @return int|false Returns the new value on success, or false if the key does not exist.
 	 */
 	public function decr( $key, $offset = 1, $group = 'default' ) {
 		$value = $this->get( $key, $group );
@@ -837,12 +834,12 @@ public function decr( $key, $offset = 1, $group = 'default' ) {
 	}
 
 	/**
-	 * Get transient fallback
+	 * Fallback function to retrieve transient data.
 	 *
-	 * @param string $transient Transient key.
-	 * @param string $group     The group the key is in.
+	 * @param string $transient The transient key.
+	 * @param string $group     The cache group.
 	 *
-	 * @return bool|int False on failure, the item's new value on success.
+	 * @return mixed|null The cached value, or null if not found.
 	 */
 	private function _transient_fallback_get( $transient, $group ) {
 		if ( 'transient' === $group ) {
@@ -894,10 +891,10 @@ private function _transient_fallback_get( $transient, $group ) {
 	}
 
 	/**
-	 * Delete transient fallback
+	 * Fallback function to delete transient data.
 	 *
-	 * @param string $transient Transient key.
-	 * @param string $group     The group the key is in.
+	 * @param string $transient The transient key.
+	 * @param string $group     The cache group.
 	 *
 	 * @return void
 	 */
@@ -921,12 +918,12 @@ private function _transient_fallback_delete( $transient, $group ) {
 	}
 
 	/**
-	 * Set transient fallback
+	 * Fallback function to set transient data.
 	 *
-	 * @param string    $transient Transient key.
-	 * @param mixed     $value     Transient value.
-	 * @param string    $group     The group the key is in.
-	 * @param bool|null $expiration Expiration.
+	 * @param string $transient  The transient key.
+	 * @param mixed  $value      The value to store.
+	 * @param string $group      The cache group.
+	 * @param int    $expiration The expiration time in seconds.
 	 *
 	 * @return void
 	 */
@@ -980,9 +977,9 @@ private function _transient_fallback_set( $transient, $value, $group, $expiratio
 	}
 
 	/**
-	 * Switches context to another blog
+	 * Switches the blog context for caching.
 	 *
-	 * @param integer $blog_id Blog ID.
+	 * @param int $blog_id The blog ID to switch to.
 	 *
 	 * @return void
 	 */
@@ -992,11 +989,11 @@ public function switch_blog( $blog_id ) {
 	}
 
 	/**
-	 * Global key fetch.
+	 * Retrieves the version number for all keys in the cache.
 	 *
-	 * @param integer $blog_id Blog ID.
+	 * @param int|null $blog_id The blog ID to get the version for.
 	 *
-	 * @return string
+	 * @return int The version number.
 	 */
 	private function key_version_all_get( $blog_id = null ) {
 		if ( is_null( $this->key_version_all ) ) {
@@ -1010,9 +1007,9 @@ private function key_version_all_get( $blog_id = null ) {
 	}
 
 	/**
-	 * Global key increment.
+	 * Increments the version number for all keys in the cache.
 	 *
-	 * @param integer $blog_id Blog ID.
+	 * @param int|null $blog_id The blog ID to increment the version for.
 	 *
 	 * @return void
 	 */
@@ -1027,12 +1024,12 @@ private function key_version_all_increment( $blog_id = null ) {
 	}
 
 	/**
-	 * Returns cache key
+	 * Retrieves the cache key for a given ID and group.
 	 *
-	 * @param string $id    ID.
-	 * @param string $group Group.
+	 * @param string $id    The cache ID.
+	 * @param string $group The cache group.
 	 *
-	 * @return string
+	 * @return string The generated cache key.
 	 */
 	private function _get_cache_key( $id, $group = 'default' ) {
 		if ( ! $group ) {
@@ -1049,9 +1046,9 @@ private function _get_cache_key( $id, $group = 'default' ) {
 	}
 
 	/**
-	 * Get usage statistics cache config.
+	 * Retrieves the cache configuration for usage statistics.
 	 *
-	 * @return array
+	 * @return array The cache configuration.
 	 */
 	public function get_usage_statistics_cache_config() {
 		$engine = $this->_config->get_string( 'objectcache.engine' );
@@ -1091,12 +1088,12 @@ public function get_usage_statistics_cache_config() {
 	}
 
 	/**
-	 * Returns cache object
+	 * Retrieves the cache instance for a given blog ID and group.
 	 *
-	 * @param int|null $blog_id Blog ID.
-	 * @param string   $group   Group.
+	 * @param int|null $blog_id The blog ID.
+	 * @param string   $group   The cache group.
 	 *
-	 * @return W3_Cache_Base
+	 * @return Cache The cache instance.
 	 */
 	private function _get_cache( $blog_id = null, $group = '' ) {
 		static $cache = array();
@@ -1159,23 +1156,19 @@ private function _get_cache( $blog_id = null, $group = '' ) {
 	}
 
 	/**
-	 * Check if caching allowed on init
+	 * Determines whether caching is enabled based on configuration.
 	 *
-	 * @return boolean
+	 * @return bool Returns true if caching is enabled, false otherwise.
 	 */
 	private function _can_cache() {
-		/**
-		 * Skip if disabled
-		 */
+		// Skip if disabled.
 		if ( ! $this->_config->getf_boolean( 'objectcache.enabled' ) ) {
 			$this->cache_reject_reason = 'objectcache.disabled';
 
 			return false;
 		}
 
-		/**
-		 * Check for DONOTCACHEOBJECT constant
-		 */
+		// Check for DONOTCACHEOBJECT constant.
 		if ( defined( 'DONOTCACHEOBJECT' ) && DONOTCACHEOBJECT ) {
 			$this->cache_reject_reason = 'DONOTCACHEOBJECT';
 
@@ -1186,11 +1179,11 @@ private function _can_cache() {
 	}
 
 	/**
-	 * Returns if we can cache, that condition can change in runtime
+	 * Checks if caching is allowed for runtime based on the group.
 	 *
-	 * @param unknown $group Group.
+	 * @param string $group The cache group to check.
 	 *
-	 * @return boolean
+	 * @return bool Returns true if caching is allowed for the group.
 	 */
 	private function _check_can_cache_runtime( $group ) {
 		// Need to be handled in wp admin as well as frontend.
@@ -1221,22 +1214,22 @@ private function _check_can_cache_runtime( $group ) {
 	}
 
 	/**
-	 * Is transient group.
+	 * Determines whether the specified group is a transient group.
 	 *
-	 * @param unknown $group Group.
+	 * @param string $group The cache group to check.
 	 *
-	 * @return boolean
+	 * @return bool Returns true if the group is transient.
 	 */
 	private function _is_transient_group( $group ) {
 		return in_array( $group, array( 'transient', 'site-transient' ), true );
 	}
 
 	/**
-	 * Modify footer comment.
+	 * Appends information about object cache usage to the footer comment.
 	 *
-	 * @param array $strings Strings.
+	 * @param array $strings The array of strings to append the data to.
 	 *
-	 * @return array
+	 * @return array The modified array of strings.
 	 */
 	public function w3tc_footer_comment( $strings ) {
 		$reason = $this->get_reject_reason();
@@ -1264,9 +1257,9 @@ public function w3tc_footer_comment( $strings ) {
 	}
 
 	/**
-	 * Usage statistics of request.
+	 * Tracks object cache usage statistics.
 	 *
-	 * @param object $storage Storage.
+	 * @param Storage $storage The storage instance to track statistics in.
 	 *
 	 * @return void
 	 */
@@ -1278,10 +1271,11 @@ public function w3tc_usage_statistics_of_request( $storage ) {
 		$storage->counter_add( 'objectcache_time_ms', (int) ( $this->time_total * 1000 ) );
 	}
 
+
 	/**
-	 * Get reject reason.
+	 * Retrieves the reason why the cache is being rejected.
 	 *
-	 * @return string
+	 * @return string The rejection reason.
 	 */
 	public function get_reject_reason() {
 		if ( is_null( $this->cache_reject_reason ) ) {
@@ -1292,11 +1286,11 @@ public function get_reject_reason() {
 	}
 
 	/**
-	 * Get reject reason message.
+	 * Retrieves a rejection message based on a given key.
 	 *
-	 * @param unknown $key Key.
+	 * @param string $key The rejection key.
 	 *
-	 * @return string
+	 * @return string The rejection message.
 	 */
 	private function _get_reject_reason_message( $key ) {
 		if ( ! function_exists( '__' ) ) {
@@ -1313,10 +1307,12 @@ private function _get_reject_reason_message( $key ) {
 		}
 	}
 
+
 	/**
-	 * Log call.
+	 * Logs cache-related calls for debugging purposes.
+	 *
+	 * @param array $data The data to log.
 	 *
-	 * @param  array $data Log data.
 	 * @return void
 	 */
 	private function log_call( array $data ): void {
@@ -1330,9 +1326,8 @@ private function log_call( array $data ): void {
 	 * Check if this is a WP-CLI call and objectcache.engine is using Disk and disabled for WP-CLI.
 	 *
 	 * @since  2.8.1
-	 * @access private
 	 *
-	 * @return bool
+	 * @return bool True if running WP-CLI with a file-based object cache, false otherwise.
 	 */
 	private function is_wpcli_disk(): bool {
 		$is_engine_disk = 'file' === $this->_config->get_string( 'objectcache.engine' );
diff --git a/PgCache_ConfigLabels.php b/PgCache_ConfigLabels.php
index 4f60760fb..b4cb4b57a 100644
--- a/PgCache_ConfigLabels.php
+++ b/PgCache_ConfigLabels.php
@@ -1,61 +1,80 @@
 <?php
+/**
+ * File: PgCache_ConfigLabels.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class PgCache_ConfigLabels
+ */
 class PgCache_ConfigLabels {
+	/**
+	 * Merges and returns the configuration labels for the page cache.
+	 *
+	 * @param array $config_labels The configuration labels to merge.
+	 *
+	 * @return array The merged configuration labels.
+	 */
 	public function config_labels( $config_labels ) {
-		return array_merge( $config_labels, array(
-				'pgcache.engine' => __( 'Page Cache Method:', 'w3-total-cache' ),
-				'pgcache.enabled' => __( 'Page Cache:', 'w3-total-cache' ),
-				'pgcache.debug' =>  __( 'Page Cache', 'w3-total-cache' ),
-				'pgcache.cache.home' => get_option( 'show_on_front' ) == 'posts' ? __( 'Cache front page', 'w3-total-cache' ): __( 'Cache posts page', 'w3-total-cache' ),
-				'pgcache.reject.front_page' => __( 'Don\'t cache front page', 'w3-total-cache' ),
-				'pgcache.cache.feed' => __( 'Cache feeds: site, categories, tags, comments', 'w3-total-cache' ),
-				'pgcache.cache.ssl' => __( 'Cache <acronym title="Secure Socket Layer">SSL</acronym> (<acronym title="HyperText Transfer Protocol over SSL">HTTPS</acronym>) requests', 'w3-total-cache' ),
-				'pgcache.cache.query' =>  __( 'Cache <acronym title="Uniform Resource Identifier">URI</acronym>s with query string variables', 'w3-total-cache' ),
-				'pgcache.cache.404' => __( 'Cache 404 (not found) pages', 'w3-total-cache' ),
-				'pgcache.reject.logged'  => __( 'Don\'t cache pages for logged in users', 'w3-total-cache' ),
-				'pgcache.reject.logged_roles' =>  __( 'Don\'t cache pages for following user roles', 'w3-total-cache' ),
-				'pgcache.prime.enabled' => __( 'Automatically prime the page cache', 'w3-total-cache' ),
-				'pgcache.prime.interval' => __( 'Update interval:', 'w3-total-cache' ),
-				'pgcache.prime.limit' => __( 'Pages per interval:', 'w3-total-cache' ),
-				'pgcache.prime.sitemap' =>__( 'Sitemap <acronym title="Uniform Resource Indicator">URL</acronym>:', 'w3-total-cache' ),
-				'pgcache.prime.post.enabled' => __( 'Preload cache upon publishing a post', 'w3-total-cache' ),
+		return array_merge(
+			$config_labels,
+			array(
+				'pgcache.engine'                    => __( 'Page Cache Method:', 'w3-total-cache' ),
+				'pgcache.enabled'                   => __( 'Page Cache:', 'w3-total-cache' ),
+				'pgcache.debug'                     => __( 'Page Cache', 'w3-total-cache' ),
+				'pgcache.cache.home'                => 'posts' === get_option( 'show_on_front' ) ? __( 'Cache front page', 'w3-total-cache' ) : __( 'Cache posts page', 'w3-total-cache' ),
+				'pgcache.reject.front_page'         => __( 'Don\'t cache front page', 'w3-total-cache' ),
+				'pgcache.cache.feed'                => __( 'Cache feeds: site, categories, tags, comments', 'w3-total-cache' ),
+				'pgcache.cache.ssl'                 => __( 'Cache <acronym title="Secure Socket Layer">SSL</acronym> (<acronym title="HyperText Transfer Protocol over SSL">HTTPS</acronym>) requests', 'w3-total-cache' ),
+				'pgcache.cache.query'               => __( 'Cache <acronym title="Uniform Resource Identifier">URI</acronym>s with query string variables', 'w3-total-cache' ),
+				'pgcache.cache.404'                 => __( 'Cache 404 (not found) pages', 'w3-total-cache' ),
+				'pgcache.reject.logged'             => __( 'Don\'t cache pages for logged in users', 'w3-total-cache' ),
+				'pgcache.reject.logged_roles'       => __( 'Don\'t cache pages for following user roles', 'w3-total-cache' ),
+				'pgcache.prime.enabled'             => __( 'Automatically prime the page cache', 'w3-total-cache' ),
+				'pgcache.prime.interval'            => __( 'Update interval:', 'w3-total-cache' ),
+				'pgcache.prime.limit'               => __( 'Pages per interval:', 'w3-total-cache' ),
+				'pgcache.prime.sitemap'             => __( 'Sitemap <acronym title="Uniform Resource Indicator">URL</acronym>:', 'w3-total-cache' ),
+				'pgcache.prime.post.enabled'        => __( 'Preload cache upon publishing a post', 'w3-total-cache' ),
 				'pgcache.prime.post.update.enabled' => __( 'Preload cache upon updating a post', 'w3-total-cache' ),
-				'pgcache.purge.front_page' => __( 'Front page', 'w3-total-cache' ),
-				'pgcache.purge.home' => get_option( 'show_on_front' ) == 'posts' ? __( 'Front page', 'w3-total-cache' ): __( 'Posts page', 'w3-total-cache' ),
-				'pgcache.purge.post' => __( 'Post page', 'w3-total-cache' ),
-				'pgcache.purge.feed.blog' => __( 'Blog feed', 'w3-total-cache' ),
-				'pgcache.purge.comments' => __( 'Post comments pages', 'w3-total-cache' ),
-				'pgcache.purge.author' => __( 'Post author pages', 'w3-total-cache' ),
-				'pgcache.purge.terms' => __( 'Post terms pages', 'w3-total-cache' ),
-				'pgcache.purge.feed.comments' => __( 'Post comments feed', 'w3-total-cache' ),
-				'pgcache.purge.feed.author' => __( 'Post author feed', 'w3-total-cache' ),
-				'pgcache.purge.feed.terms' => __( 'Post terms feeds', 'w3-total-cache' ),
-				'pgcache.purge.archive.daily' => __( 'Daily archive pages', 'w3-total-cache' ),
-				'pgcache.purge.archive.monthly' => __( 'Monthly archive pages', 'w3-total-cache' ),
-				'pgcache.purge.archive.yearly' => __( 'Yearly archive pages', 'w3-total-cache' ),
-				'pgcache.purge.feed.types' =>  __( 'Specify the feed types to purge:', 'w3-total-cache' ),
-				'pgcache.purge.postpages_limit' =>  __( 'Purge limit:', 'w3-total-cache' ),
-				'pgcache.purge.pages' =>  __( 'Additional pages:', 'w3-total-cache' ),
-				'pgcache.purge.sitemap_regex' =>  __( 'Purge sitemaps:', 'w3-total-cache' ),
-				'pgcache.compatibility' => __( 'Enable', 'w3-total-cache' ),
-				'pgcache.remove_charset' =>  __( 'Disable <acronym title="Unicode Transformation Format">UTF</acronym>-8 blog charset support' , 'w3-total-cache' ),
-				'pgcache.reject.request_head' => __( ' Disable caching of HEAD <acronym title="Hypertext Transfer Protocol">HTTP</acronym> requests', 'w3-total-cache' ),
-				'pgcache.lifetime' =>  __( 'Maximum lifetime of cache objects:', 'w3-total-cache' ),
-				'pgcache.file.gc' =>  __( 'Garbage collection interval:', 'w3-total-cache' ),
-				'pgcache.comment_cookie_ttl' => __( 'Comment cookie lifetime:', 'w3-total-cache' ),
-				'pgcache.accept.qs' =>  __( 'Accepted query strings:', 'w3-total-cache' ),
-				'pgcache.reject.ua' =>  __( 'Rejected user agents:', 'w3-total-cache' ),
-				'pgcache.reject.cookie' => __( 'Rejected cookies:', 'w3-total-cache' ),
-				'pgcache.reject.uri' =>  __( 'Never cache the following pages:', 'w3-total-cache' ),
-				'pgcache.reject.categories' =>  __( 'Never cache pages associated with these categories:', 'w3-total-cache' ),
-				'pgcache.reject.tags' =>  __( 'Never cache pages that use these tags:', 'w3-total-cache' ),
-				'pgcache.reject.authors' =>  __( 'Never cache pages by these authors:', 'w3-total-cache' ),
-				'pgcache.reject.custom' =>  __( 'Never cache pages that use these custom fields:', 'w3-total-cache' ),
-				'pgcache.accept.files' =>  __( 'Cache exception list:', 'w3-total-cache' ),
-				'pgcache.accept.uri' =>  __( 'Non-trailing slash pages:', 'w3-total-cache' ),
-				'pgcache.cache.headers' =>  __( 'Specify page headers:', 'w3-total-cache' ),
-				'pgcache.cache.nginx_handle_xml' => __( 'Handle <acronym title="Extensible Markup Language">XML</acronym> mime type', 'w3-total-cache' ),
-			) );
+				'pgcache.purge.front_page'          => __( 'Front page', 'w3-total-cache' ),
+				'pgcache.purge.home'                => 'posts' === get_option( 'show_on_front' ) ? __( 'Front page', 'w3-total-cache' ) : __( 'Posts page', 'w3-total-cache' ),
+				'pgcache.purge.post'                => __( 'Post page', 'w3-total-cache' ),
+				'pgcache.purge.feed.blog'           => __( 'Blog feed', 'w3-total-cache' ),
+				'pgcache.purge.comments'            => __( 'Post comments pages', 'w3-total-cache' ),
+				'pgcache.purge.author'              => __( 'Post author pages', 'w3-total-cache' ),
+				'pgcache.purge.terms'               => __( 'Post terms pages', 'w3-total-cache' ),
+				'pgcache.purge.feed.comments'       => __( 'Post comments feed', 'w3-total-cache' ),
+				'pgcache.purge.feed.author'         => __( 'Post author feed', 'w3-total-cache' ),
+				'pgcache.purge.feed.terms'          => __( 'Post terms feeds', 'w3-total-cache' ),
+				'pgcache.purge.archive.daily'       => __( 'Daily archive pages', 'w3-total-cache' ),
+				'pgcache.purge.archive.monthly'     => __( 'Monthly archive pages', 'w3-total-cache' ),
+				'pgcache.purge.archive.yearly'      => __( 'Yearly archive pages', 'w3-total-cache' ),
+				'pgcache.purge.feed.types'          => __( 'Specify the feed types to purge:', 'w3-total-cache' ),
+				'pgcache.purge.postpages_limit'     => __( 'Purge limit:', 'w3-total-cache' ),
+				'pgcache.purge.pages'               => __( 'Additional pages:', 'w3-total-cache' ),
+				'pgcache.purge.sitemap_regex'       => __( 'Purge sitemaps:', 'w3-total-cache' ),
+				'pgcache.compatibility'             => __( 'Enable', 'w3-total-cache' ),
+				'pgcache.remove_charset'            => __( 'Disable <acronym title="Unicode Transformation Format">UTF</acronym>-8 blog charset support', 'w3-total-cache' ),
+				'pgcache.reject.request_head'       => __( ' Disable caching of HEAD <acronym title="Hypertext Transfer Protocol">HTTP</acronym> requests', 'w3-total-cache' ),
+				'pgcache.lifetime'                  => __( 'Maximum lifetime of cache objects:', 'w3-total-cache' ),
+				'pgcache.file.gc'                   => __( 'Garbage collection interval:', 'w3-total-cache' ),
+				'pgcache.comment_cookie_ttl'        => __( 'Comment cookie lifetime:', 'w3-total-cache' ),
+				'pgcache.accept.qs'                 => __( 'Accepted query strings:', 'w3-total-cache' ),
+				'pgcache.reject.ua'                 => __( 'Rejected user agents:', 'w3-total-cache' ),
+				'pgcache.reject.cookie'             => __( 'Rejected cookies:', 'w3-total-cache' ),
+				'pgcache.reject.uri'                => __( 'Never cache the following pages:', 'w3-total-cache' ),
+				'pgcache.reject.categories'         => __( 'Never cache pages associated with these categories:', 'w3-total-cache' ),
+				'pgcache.reject.tags'               => __( 'Never cache pages that use these tags:', 'w3-total-cache' ),
+				'pgcache.reject.authors'            => __( 'Never cache pages by these authors:', 'w3-total-cache' ),
+				'pgcache.reject.custom'             => __( 'Never cache pages that use these custom fields:', 'w3-total-cache' ),
+				'pgcache.accept.files'              => __( 'Cache exception list:', 'w3-total-cache' ),
+				'pgcache.accept.uri'                => __( 'Non-trailing slash pages:', 'w3-total-cache' ),
+				'pgcache.cache.headers'             => __( 'Specify page headers:', 'w3-total-cache' ),
+				'pgcache.cache.nginx_handle_xml'    => __( 'Handle <acronym title="Extensible Markup Language">XML</acronym> mime type', 'w3-total-cache' ),
+			)
+		);
 	}
 }
diff --git a/PgCache_ContentGrabber.php b/PgCache_ContentGrabber.php
index e19ab36fb..f5e26b839 100644
--- a/PgCache_ContentGrabber.php
+++ b/PgCache_ContentGrabber.php
@@ -1,57 +1,68 @@
 <?php
+/**
+ * File: PgCache_ConfigLabels.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
-// To support legacy updates with old add-ins
-if ( class_exists( 'PgCache_ContentGrabber' ) )
+// To support legacy updates with old add-ins.
+if ( class_exists( 'PgCache_ContentGrabber' ) ) {
 	return;
+}
 
 /**
- * W3 PgCache
- */
-
-/**
- * class PgCache
+ * Class PgCache_ContentGrabber
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
+ * phpcs:disable WordPress.Security.ValidatedSanitizedInput
  */
 class PgCache_ContentGrabber {
 	/**
 	 * Advanced cache config
+	 *
+	 * @var Config
 	 */
-	var $_config = null;
+	private $_config = null;
 
 	/**
 	 * Caching flag
 	 *
 	 * @var boolean
 	 */
-	var $_caching = false;
+	private $_caching = false;
 
 	/**
 	 * Time start
 	 *
 	 * @var double
 	 */
-	var $_time_start = 0;
+	private $_time_start = 0;
 
 	/**
 	 * Lifetime
 	 *
 	 * @var integer
 	 */
-	var $_lifetime = 0;
+	private $_lifetime = 0;
 
 	/**
 	 * Enhanced mode flag
 	 *
 	 * @var boolean
 	 */
-	var $_enhanced_mode = false;
+	private $_enhanced_mode = false;
 
 	/**
 	 * Debug flag
 	 *
 	 * @var boolean
 	 */
-	var $_debug = false;
+	private $_debug = false;
 
 	/**
 	 * Request URI
@@ -60,8 +71,14 @@ class PgCache_ContentGrabber {
 	 */
 	private $_request_uri;
 
-	// filled by _preprocess_request_uri
-	// - ['host' => 'path' => , 'querystring' => ]
+	/**
+	 * Request URL fragments
+	 *
+	 * Filled by _preprocess_request_uri
+	 * - ['host' => 'path' => , 'querystring' => ]
+	 *
+	 * @var array
+	 */
 	private $_request_url_fragments;
 
 	/**
@@ -69,7 +86,13 @@ class PgCache_ContentGrabber {
 	 *
 	 * @var string
 	 */
-	var $_page_key = '';
+	private $_page_key = '';
+
+	/**
+	 * Page key extension
+	 *
+	 * @var string
+	 */
 	private $_page_key_extension;
 
 	/**
@@ -77,76 +100,108 @@ class PgCache_ContentGrabber {
 	 *
 	 * @var string
 	 */
-	var $_shutdown_buffer = '';
+	private $_shutdown_buffer = '';
 
 	/**
 	 * Mobile object
 	 *
 	 * @var W3_Mobile
 	 */
-	var $_mobile = null;
+	private $_mobile = null;
 
 	/**
 	 * Referrer object
 	 *
 	 * @var W3_Referrer
 	 */
-	var $_referrer = null;
+	private $_referrer = null;
 
 	/**
 	 * Cache reject reason
 	 *
 	 * @var string
 	 */
-	var $cache_reject_reason = '';
+	private $cache_reject_reason = '';
 
+	/**
+	 * Process status
+	 *
+	 * @var string
+	 */
 	private $process_status = '';
+
+	/**
+	 * Output size
+	 *
+	 * @var int
+	 */
 	private $output_size = 0;
 
 	/**
+	 * Late init flag
+	 *
 	 * @var bool If cached page should be displayed after init
 	 */
-	var $_late_init = false;
+	private $_late_init = false;
 
 	/**
+	 * Late caching flag
+	 *
 	 * @var bool late caching
 	 */
-	var $_late_caching = false;
+	private $_late_caching = false;
 
-	var $_cached_data = null;
+	/**
+	 * Cached data
+	 *
+	 * @var array
+	 */
+	private $_cached_data = null;
 
-	var $_old_exists = false;
+	/**
+	 * Old exists flag
+	 *
+	 * @var bool
+	 */
+	private $_old_exists = false;
 
 	/**
+	 * Nginx/Memcached flag
+	 *
 	 * @var bool Nginx memcached flag
 	 */
-	var $_nginx_memcached = false;
+	private $_nginx_memcached = false;
 
 	/**
+	 * Page group
+	 *
 	 * @var string
 	 */
-	var $_page_group;
+	private $_page_group;
 
 	/**
-	 * PHP5 Constructor
+	 * Constructs the PgCache_ContentGrabber instance.
+	 *
+	 * Initializes configuration, debug settings, and request URL fragments.
+	 *
+	 * @return void
 	 */
-	function __construct() {
+	public function __construct() {
 		$this->_config = Dispatcher::config();
-		$this->_debug = $this->_config->get_boolean( 'pgcache.debug' );
+		$this->_debug  = $this->_config->get_boolean( 'pgcache.debug' );
 
 		$this->_request_url_fragments = array(
-			'host' => Util_Environment::host_port()
+			'host' => Util_Environment::host_port(),
 		);
 
-		$this->_request_uri = isset( $_SERVER['REQUEST_URI'] ) ?
-			filter_var( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ) : ''; // phpcs:ignore
-		$this->_lifetime = $this->_config->get_integer( 'pgcache.lifetime' );
-		$this->_late_init = $this->_config->get_boolean( 'pgcache.late_init' );
+		$this->_request_uri  = isset( $_SERVER['REQUEST_URI'] ) ? filter_var( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ) : '';
+		$this->_lifetime     = $this->_config->get_integer( 'pgcache.lifetime' );
+		$this->_late_init    = $this->_config->get_boolean( 'pgcache.late_init' );
 		$this->_late_caching = $this->_config->get_boolean( 'pgcache.late_caching' );
 
-		$engine = $this->_config->get_string( 'pgcache.engine' );
-		$this->_enhanced_mode = ( $engine == 'file_generic' );
-		$this->_nginx_memcached = ( $engine == 'nginx_memcached' );
+		$engine                 = $this->_config->get_string( 'pgcache.engine' );
+		$this->_enhanced_mode   = 'file_generic' === $engine;
+		$this->_nginx_memcached = 'nginx_memcached' === $engine;
 
 		if ( $this->_config->get_boolean( 'mobile.enabled' ) ) {
 			$this->_mobile = Dispatcher::component( 'Mobile_UserAgent' );
@@ -158,80 +213,78 @@ function __construct() {
 	}
 
 	/**
-	 * Do cache logic
+	 * Processes the page cache logic.
+	 *
+	 * Handles caching based on conditions and outputs the cached or generated content.
+	 *
+	 * @return void
 	 */
-	function process() {
+	public function process() {
 		$this->run_extensions_dropin();
 
-		/**
-		 * Skip caching for some pages
-		 */
+		// Skip caching for some pages.
 		switch ( true ) {
-		case defined( 'DONOTCACHEPAGE' ):
-			$this->process_status = 'miss_third_party';
-			$this->cache_reject_reason = 'DONOTCACHEPAGE defined';
-			if ( $this->_debug ) {
-				self::log( 'skip processing because of DONOTCACHEPAGE constant' );
-			}
-			return;
-		case defined( 'DOING_AJAX' ):
-			$this->process_status = 'miss_ajax';
-			$this->cache_reject_reason = 'AJAX request';
-			if ( $this->_debug ) {
-				self::log( 'skip processing because of AJAX constant' );
-			}
-			return;
+			case defined( 'DONOTCACHEPAGE' ):
+				$this->process_status      = 'miss_third_party';
+				$this->cache_reject_reason = 'DONOTCACHEPAGE defined';
+				if ( $this->_debug ) {
+					self::log( 'skip processing because of DONOTCACHEPAGE constant' );
+				}
+				return;
 
-		case defined( 'APP_REQUEST' ):
-		case defined( 'XMLRPC_REQUEST' ):
-			$this->cache_reject_reason = 'API call constant defined';
-			$this->process_status = 'miss_api_call';
-			if ( $this->_debug ) {
-				self::log( 'skip processing because of API call constant' );
-			}
-			return;
+			case defined( 'DOING_AJAX' ):
+				$this->process_status      = 'miss_ajax';
+				$this->cache_reject_reason = 'AJAX request';
+				if ( $this->_debug ) {
+					self::log( 'skip processing because of AJAX constant' );
+				}
+				return;
 
-		case defined( 'DOING_CRON' ):
-		case defined( 'WP_ADMIN' ):
-		case ( defined( 'SHORTINIT' ) && SHORTINIT ):
-			$this->cache_reject_reason = 'WP_ADMIN defined';
-			$this->process_status = 'miss_wp_admin';
-			if ( $this->_debug ) {
-				self::log( 'skip processing because of generic constant' );
-			}
-			return;
+			case defined( 'APP_REQUEST' ):
+			case defined( 'XMLRPC_REQUEST' ):
+				$this->cache_reject_reason = 'API call constant defined';
+				$this->process_status      = 'miss_api_call';
+				if ( $this->_debug ) {
+					self::log( 'skip processing because of API call constant' );
+				}
+				return;
+
+			case defined( 'DOING_CRON' ):
+			case defined( 'WP_ADMIN' ):
+			case ( defined( 'SHORTINIT' ) && SHORTINIT ):
+				$this->cache_reject_reason = 'WP_ADMIN defined';
+				$this->process_status      = 'miss_wp_admin';
+				if ( $this->_debug ) {
+					self::log( 'skip processing because of generic constant' );
+				}
+				return;
 		}
 
-		/**
-		 * Do page cache logic
-		 */
+		// Do page cache logic.
 		if ( $this->_debug ) {
 			$this->_time_start = Util_Debug::microtime();
 		}
 
-		// TODO: call modifies object state, rename method at least
+		// TODO: call modifies object state, rename method at least.
 		$this->_caching = $this->_can_read_cache();
 		global $w3_late_init;
 
 		if ( $this->_debug ) {
-			self::log( 'start, can_cache: ' .
-				( $this->_caching ? 'true' : 'false' ) .
-				 ', reject reason: ' . $this->cache_reject_reason );
+			self::log( 'start, can_cache: ' . ( $this->_caching ? 'true' : 'false' ) . ', reject reason: ' . $this->cache_reject_reason );
 		}
 
 		$this->_page_key_extension = $this->_get_key_extension();
 
-		if ( !$this->_page_key_extension['cache'] ) {
-			$this->_caching = false;
-			$this->cache_reject_reason =
-				$this->_page_key_extension['cache_reject_reason'];
+		if ( ! $this->_page_key_extension['cache'] ) {
+			$this->_caching            = false;
+			$this->cache_reject_reason = $this->_page_key_extension['cache_reject_reason'];
 		}
 
 		if ( ! empty( $_SERVER['HTTP_W3TCALWAYSCACHED'] ) ) {
 			$this->_page_key_extension['alwayscached'] = true;
 		}
 
-		if ( $this->_caching && !$this->_late_caching ) {
+		if ( $this->_caching && ! $this->_late_caching ) {
 			$this->_cached_data = $this->_extract_cached_page( false );
 			if ( $this->_cached_data ) {
 				if ( $this->_late_init ) {
@@ -240,92 +293,96 @@ function process() {
 				} else {
 					$this->process_status = 'hit';
 					$this->process_cached_page_and_exit( $this->_cached_data );
-					// if is passes here - exit is not possible now and
-					// will happen on init
+					// if is passes here - exit is not possible now and will happen on init.
 					return;
 				}
-			} else
+			} else {
 				$this->_late_init = false;
+			}
 		} else {
 			$this->_late_init = false;
 		}
+
 		$w3_late_init = $this->_late_init;
-		/**
-		 * Start output buffering
-		 */
+		// Start output buffering.
 
 		Util_Bus::add_ob_callback( 'pagecache', array( $this, 'ob_callback' ) );
 	}
 
-
-
+	/**
+	 * Executes the extensions drop-in logic.
+	 *
+	 * Includes active extensions defined in the configuration.
+	 *
+	 * @return void
+	 */
 	private function run_extensions_dropin() {
-		$c = $this->_config;
+		$c          = $this->_config;
 		$extensions = $c->get_array( 'extensions.active' );
 
 		$dropin = $c->get_array( 'extensions.active_dropin' );
 		foreach ( $dropin as $extension => $nothing ) {
-			if ( isset( $extensions[$extension] ) ) {
-				$path = $extensions[$extension];
+			if ( isset( $extensions[ $extension ] ) ) {
+				$path     = $extensions[ $extension ];
 				$filename = W3TC_EXTENSION_DIR . '/' .
 					str_replace( '..', '', trim( $path, '/' ) );
 
 				if ( file_exists( $filename ) ) {
-					include_once( $filename );
+					include_once $filename;
 				}
 			}
 		}
 	}
 
-
-
 	/**
-	 * Extracts page from cache
+	 * Extracts a cached page from storage.
+	 *
+	 * @param bool $with_filter Whether to apply filters to the cache keys.
 	 *
-	 * @return boolean
+	 * @return array|null An array of cached page data or null if not found.
 	 */
-	function _extract_cached_page( $with_filter ) {
+	public function _extract_cached_page( $with_filter ) {
 		if ( ! empty( $this->_page_key_extension['alwayscached'] ) ) {
 			return null;
 		}
 
 		$cache = $this->_get_cache( $this->_page_key_extension['group'] );
 
-		$mobile_group = $this->_page_key_extension['useragent'];
+		$mobile_group   = $this->_page_key_extension['useragent'];
 		$referrer_group = $this->_page_key_extension['referrer'];
-		$encryption = $this->_page_key_extension['encryption'];
-		$compression = $this->_page_key_extension['compression'];
+		$encryption     = $this->_page_key_extension['encryption'];
+		$compression    = $this->_page_key_extension['compression'];
 
-		/**
-		 * Check if page is cached
-		 */
-		if ( !$this->_set_extract_page_key( $this->_page_key_extension, $with_filter ) ) {
+		// Check if page is cached.
+		if ( ! $this->_set_extract_page_key( $this->_page_key_extension, $with_filter ) ) {
 			$data = null;
 		} else {
-			$data = $cache->get_with_old( $this->_page_key, $this->_page_group );
+			$data                             = $cache->get_with_old( $this->_page_key, $this->_page_group );
 			list( $data, $this->_old_exists ) = $data;
 		}
 
-		/**
-		 * Try to get uncompressed version of cache
-		 */
-		if ( $compression && !$data ) {
-			if ( !$this->_set_extract_page_key(
-					array_merge( $this->_page_key_extension,
-						array( 'compression' => '') ), $with_filter ) ) {
+		// Try to get uncompressed version of cache.
+		if ( $compression && ! $data ) {
+			if (
+				! $this->_set_extract_page_key(
+					array_merge(
+						$this->_page_key_extension,
+						array( 'compression' => '' )
+					),
+					$with_filter
+				)
+			) {
 				$data = null;
 			} else {
-				$data = $cache->get_with_old( $this->_page_key, $this->_page_group );
+				$data                             = $cache->get_with_old( $this->_page_key, $this->_page_group );
 				list( $data, $this->_old_exists ) = $data;
-				$compression = false;
+				$compression                      = false;
 			}
 		}
 
-		if ( !$data ) {
+		if ( ! $data ) {
 			if ( $this->_debug ) {
-				self::log( 'no cache entry for ' .
-					$this->_request_url_fragments['host'] . $this->_request_uri . ' ' .
-					$this->_page_key );
+				self::log( 'no cache entry for ' . $this->_request_url_fragments['host'] . $this->_request_uri . ' ' . $this->_page_key );
 			}
 
 			return null;
@@ -336,26 +393,36 @@ function _extract_cached_page( $with_filter ) {
 		return $data;
 	}
 
-
-
+	/**
+	 * Sets the page key and group for cache extraction.
+	 *
+	 * @param array $page_key_extension Cache key extension data.
+	 * @param bool  $with_filter        Whether to apply filters to the cache keys.
+	 *
+	 * @return bool True if the page key was set successfully, false otherwise.
+	 */
 	private function _set_extract_page_key( $page_key_extension, $with_filter ) {
-		// set page group
+		// set page group.
 		$this->_page_group = $page_key_extension['group'];
 		if ( $with_filter ) {
-			// return empty value if caching should not happen
-			$this->_page_group = apply_filters( 'w3tc_page_extract_group',
+			// return empty value if caching should not happen.
+			$this->_page_group = apply_filters(
+				'w3tc_page_extract_group',
 				$page_key_extension['group'],
 				$this->_request_url_fragments['host'] . $this->_request_uri,
-				$page_key_extension );
+				$page_key_extension
+			);
+
 			$page_key_extension['group'] = $this->_page_group;
 		}
 
-		// set page key
+		// set page key.
 		$this->_page_key = $this->_get_page_key( $page_key_extension );
 
 		if ( $with_filter ) {
-			// return empty value if caching should not happen
-			$this->_page_key = apply_filters( 'w3tc_page_extract_key',
+			// return empty value if caching should not happen.
+			$this->_page_key = apply_filters(
+				'w3tc_page_extract_key',
 				$this->_page_key,
 				$page_key_extension['useragent'],
 				$page_key_extension['referrer'],
@@ -363,56 +430,53 @@ private function _set_extract_page_key( $page_key_extension, $with_filter ) {
 				$page_key_extension['compression'],
 				$page_key_extension['content_type'],
 				$this->_request_url_fragments['host'] . $this->_request_uri,
-				$page_key_extension );
+				$page_key_extension
+			);
 		}
 
-		if ( !empty( $this->_page_key ) )
+		if ( ! empty( $this->_page_key ) ) {
 			return true;
+		}
 
-		$this->caching = false;
-		$this->cache_reject_reason =
-			'w3tc_page_extract_key filter result forced not to cache';
+		$this->caching             = false;
+		$this->cache_reject_reason = 'w3tc_page_extract_key filter result forced not to cache';
 
 		return false;
 	}
 
-
-
 	/**
-	 * Process extracted cached pages
+	 * Processes the cached page and terminates execution.
 	 *
-	 * @param unknown $data
+	 * @param array $data Cached page data.
+	 *
+	 * @return void
 	 */
 	private function process_cached_page_and_exit( $data ) {
-		/**
-		 * Do Bad Behavior check
-		 */
+		// Do Bad Behavior check.
 		$this->_bad_behavior();
 
-		$is_404 = isset( $data['404'] ) ? $data['404'] : false;
-		$headers = isset( $data['headers'] ) ? $data['headers'] : array();
-		$content = $data['content'];
+		$is_404      = isset( $data['404'] ) ? $data['404'] : false;
+		$headers     = isset( $data['headers'] ) ? $data['headers'] : array();
+		$content     = $data['content'];
 		$has_dynamic = isset( $data['has_dynamic'] ) && $data['has_dynamic'];
-		$etag = md5( $content );
+		$etag        = md5( $content );
 
 		if ( $has_dynamic ) {
-			// its last modification date is now, and any compression
-			// browser wants cant be used, since its compressed now
-			$time = time();
+			// its last modification date is now, and any compression browser wants cant be used, since its compressed now.
+			$time        = time();
 			$compression = $this->_page_key_extension['compression'];
 		} else {
-			$time = isset( $data['time'] ) ? $data['time'] : time();
+			$time        = isset( $data['time'] ) ? $data['time'] : time();
 			$compression = $data['compression'];
 		}
 
-		/**
-		 * Send headers
-		 */
+		// Send headers.
 		$this->_send_headers( $is_404, $time, $etag, $compression, $headers );
-		if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'HEAD' )
+		if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'HEAD' === $_SERVER['REQUEST_METHOD'] ) {
 			return;
+		}
 
-		// parse dynamic content and compress if it's dynamic page with mfuncs
+		// parse dynamic content and compress if it's dynamic page with mfuncs.
 		if ( $has_dynamic ) {
 			$content = $this->_parse_dynamic( $content );
 			$content = $this->_compress( $content, $compression );
@@ -420,62 +484,71 @@ private function process_cached_page_and_exit( $data ) {
 
 		echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
 
-		Dispatcher::usage_statistics_apply_before_init_and_exit( array( $this,
-				'w3tc_usage_statistics_of_request' ) );
+		Dispatcher::usage_statistics_apply_before_init_and_exit(
+			array(
+				$this,
+				'w3tc_usage_statistics_of_request',
+			)
+		);
 	}
 
 	/**
-	 * Output buffering callback
+	 * Output buffering callback for caching.
+	 *
+	 * @param string $buffer The current output buffer.
 	 *
-	 * @param string  $buffer
-	 * @return string
+	 * @return string Processed buffer to be output.
 	 */
-	function ob_callback( $buffer ) {
+	public function ob_callback( $buffer ) {
 		$this->output_size = strlen( $buffer );
 
-		if ( !$this->_is_cacheable_content_type() ) {
-			if ( $this->_debug )
+		if ( ! $this->_is_cacheable_content_type() ) {
+			if ( $this->_debug ) {
 				self::log( 'storing cached page - not a cached content' );
+			}
 
 			return $buffer;
 		}
 
-		$compression = false;
-		$has_dynamic = $this->_has_dynamic( $buffer );
+		$compression      = false;
+		$has_dynamic      = $this->_has_dynamic( $buffer );
 		$response_headers = $this->_get_response_headers();
 
-		// TODO: call modifies object state, rename method at least
+		// TODO: call modifies object state, rename method at least.
 		$original_can_cache = $this->_can_write_cache( $buffer, $response_headers );
-		$can_cache = apply_filters( 'w3tc_can_cache', $original_can_cache, $this, $buffer );
-		if ( $can_cache != $original_can_cache ) {
+		$can_cache          = apply_filters( 'w3tc_can_cache', $original_can_cache, $this, $buffer );
+		if ( $can_cache !== $original_can_cache ) {
 			$this->cache_reject_reason = 'Third-party plugin has modified caching activity';
 		}
 
 		if ( $this->_debug ) {
-			self::log( 'storing cached page: ' .
-				( $can_cache ? 'true' : 'false' ) .
-				' original ' . ( $this->_caching ? ' true' : 'false' ) .
-				' reason ' . $this->cache_reject_reason );
+			self::log(
+				'storing cached page: ' . ( $can_cache ? 'true' : 'false' ) . ' original ' .
+				( $this->_caching ? ' true' : 'false' ) . ' reason ' . $this->cache_reject_reason
+			);
 		}
 
-		$buffer = str_replace('{w3tc_pagecache_reject_reason}',
-			( $this->cache_reject_reason != '' ? sprintf( ' (%s)', $this->cache_reject_reason )
-				: '' ),
-			$buffer );
+		$buffer = str_replace(
+			'{w3tc_pagecache_reject_reason}',
+			( '' !== $this->cache_reject_reason ? sprintf( ' (%s)', $this->cache_reject_reason ) : '' ),
+			$buffer
+		);
 
 		if ( $can_cache ) {
 			$buffer = $this->_maybe_save_cached_result( $buffer, $response_headers, $has_dynamic );
 		} else {
 			if ( $has_dynamic ) {
-				// send common headers since output will be compressed
+				// send common headers since output will be compressed.
 				$compression_header = $this->_page_key_extension['compression'];
-				if ( defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) )
+				if ( defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) ) {
 					$compression_header = false;
+				}
+
 				$headers = $this->_get_common_headers( $compression_header );
 				$this->_headers( $headers );
 			}
 
-			// remove cached entries if its not cached anymore
+			// remove cached entries if its not cached anymore.
 			if ( $this->cache_reject_reason ) {
 				if ( $this->_old_exists ) {
 					$cache = $this->_get_cache( $this->_page_key_extension['group'] );
@@ -484,34 +557,36 @@ function ob_callback( $buffer ) {
 
 					foreach ( $compressions_to_store as $_compression ) {
 						$_page_key = $this->_get_page_key(
-							array_merge( $this->_page_key_extension,
-								array( 'compression' => $_compression ) ) );
+							array_merge(
+								$this->_page_key_extension,
+								array( 'compression' => $_compression )
+							)
+						);
 						$cache->hard_delete( $_page_key );
 					}
 				}
 			}
 		}
 
-		/**
-		 * We can't capture output in ob_callback
-		 * so we use shutdown function
-		 */
+		// We can't capture output in ob_callback so we use shutdown function.
 		if ( $has_dynamic ) {
 			$this->_shutdown_buffer = $buffer;
 
 			$buffer = '';
 
-			register_shutdown_function( array(
+			register_shutdown_function(
+				array(
 					$this,
-					'shutdown'
-				) );
+					'shutdown',
+				)
+			);
 		}
 
 		return $buffer;
 	}
 
 	/**
-	 * Shutdown callback
+	 * Handles the shutdown process for compressing and outputting the page buffer.
 	 *
 	 * @return void
 	 */
@@ -528,96 +603,79 @@ public function shutdown() {
 	}
 
 	/**
-	 * Checks if can we do cache logic
+	 * Determines if the cache can be read for the current request.
 	 *
-	 * @return boolean
+	 * @return bool True if cache can be read, false otherwise.
 	 */
 	private function _can_read_cache() {
-		/**
-		 * Don't cache in console mode
-		 */
+		// Don't cache in console mode.
 		if ( PHP_SAPI === 'cli' ) {
 			$this->cache_reject_reason = 'Console mode';
-
 			return false;
 		}
 
-		/**
-		 * Skip if session defined
-		 */
-		if ( defined( 'SID' ) && SID != '' ) {
+		// Skip if session defined.
+		if ( defined( 'SID' ) && SID !== '' ) {
 			$this->cache_reject_reason = 'Session started';
-
 			return false;
 		}
 
-		if ( !$this->_config->get_boolean('pgcache.cache.ssl') && Util_Environment::is_https() ) {
+		if ( ! $this->_config->get_boolean( 'pgcache.cache.ssl' ) && Util_Environment::is_https() ) {
 			$this->cache_reject_reason = 'SSL caching disabled';
-			$this->process_status = 'miss_configuration';
-
+			$this->process_status      = 'miss_configuration';
 			return false;
 		}
 
-		/**
-		 * Skip if posting
-		 */
-		$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ?
-			htmlspecialchars( stripslashes( $_SERVER['REQUEST_METHOD'] ) ) : ''; // phpcs:ignore
+		// Skip if posting.
+		$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? htmlspecialchars( stripslashes( $_SERVER['REQUEST_METHOD'] ) ) : '';
 
 		if ( in_array( strtoupper( $request_method ), array( 'DELETE', 'PUT', 'OPTIONS', 'TRACE', 'CONNECT', 'POST' ), true ) ) {
 			$this->cache_reject_reason = sprintf( 'Requested method is %s', $request_method );
-
 			return false;
 		}
 
-		/**
-		 * Skip if HEAD request.
-		 */
-		if ( isset( $_SERVER['REQUEST_METHOD'] ) &&
-			strtoupper( $_SERVER['REQUEST_METHOD'] ) === 'HEAD' && // phpcs:ignore
-			( $this->_enhanced_mode || $this->_config->get_boolean( 'pgcache.reject.request_head' ) ) ) {
+		// Skip if HEAD request..
+		if (
+			isset( $_SERVER['REQUEST_METHOD'] ) &&
+			strtoupper( $_SERVER['REQUEST_METHOD'] ) === 'HEAD' &&
+			( $this->_enhanced_mode || $this->_config->get_boolean( 'pgcache.reject.request_head' ) )
+		) {
 			$this->cache_reject_reason = 'Requested method is HEAD';
-
 			return false;
 		}
 
-		/**
-		 * Skip if there is query in the request uri
-		 */
+		// Skip if there is query in the request uri.
 		$this->_preprocess_request_uri();
 
-		if ( !empty( $this->_request_url_fragments['querystring'] ) ) {
-			$should_reject_qs =
-				( !$this->_config->get_boolean( 'pgcache.cache.query' ) ||
-				$this->_config->get_string( 'pgcache.engine' ) == 'file_generic' );
+		if ( ! empty( $this->_request_url_fragments['querystring'] ) ) {
+			$should_reject_qs = (
+				! $this->_config->get_boolean( 'pgcache.cache.query' ) ||
+				'file_generic' === $this->_config->get_string( 'pgcache.engine' )
+			);
 
-			if ( $should_reject_qs &&
-				$this->_config->get_string( 'pgcache.rest' ) == 'cache' &&
-				Util_Environment::is_rest_request( $this->_request_uri ) ) {
+			if (
+				$should_reject_qs &&
+				'cache' === $this->_config->get_string( 'pgcache.rest' ) &&
+				Util_Environment::is_rest_request( $this->_request_uri )
+			) {
 				$should_reject_qs = false;
 			}
 
 			if ( $should_reject_qs ) {
 				$this->cache_reject_reason = 'Requested URI contains query';
-				$this->process_status = 'miss_query_string';
-
+				$this->process_status      = 'miss_query_string';
 				return false;
 			}
 		}
 
-		/**
-		 * Check request URI
-		 */
-		if ( !$this->_passed_accept_files() && !$this->_passed_reject_uri() ) {
+		// Check request URI.
+		if ( ! $this->_passed_accept_files() && ! $this->_passed_reject_uri() ) {
 			$this->cache_reject_reason = 'Requested URI is rejected';
-			$this->process_status = 'miss_configuration';
-
+			$this->process_status      = 'miss_configuration';
 			return false;
 		}
 
-		/**
-		 * Check User Agent
-		 */
+		// Check User Agent.
 		if ( ! $this->_check_ua() ) {
 			$this->cache_reject_reason = 'User agent is rejected';
 			if ( ! empty( Util_Request::get_string( 'w3tc_rewrite_test' ) ) ) {
@@ -630,30 +688,24 @@ private function _can_read_cache() {
 			return false;
 		}
 
-		/**
-		 * Check WordPress cookies
-		 */
-		if ( !$this->_check_cookies() ) {
+		// Check WordPress cookies.
+		if ( ! $this->_check_cookies() ) {
 			$this->cache_reject_reason = 'Cookie is rejected';
-			$this->process_status = 'miss_configuration';
-
+			$this->process_status      = 'miss_configuration';
 			return false;
 		}
 
-		/**
-		 * Skip if user is logged in or user role is logged in
-		 */
+		// Skip if user is logged in or user role is logged in.
 		if ( $this->_config->get_boolean( 'pgcache.reject.logged' ) ) {
-			if ( !$this->_check_logged_in() ) {
+			if ( ! $this->_check_logged_in() ) {
 				$this->cache_reject_reason = 'User is logged in';
-				$this->process_status = 'miss_logged_in';
-
+				$this->process_status      = 'miss_logged_in';
 				return false;
 			}
 		} else {
-			if ( !$this->_check_logged_in_role_allowed() ) {
+			if ( ! $this->_check_logged_in_role_allowed() ) {
 				$this->cache_reject_reason = 'Rejected user role is logged in';
-				$this->process_status = 'miss_logged_in';
+				$this->process_status      = 'miss_logged_in';
 				return false;
 			}
 		}
@@ -662,319 +714,310 @@ private function _can_read_cache() {
 	}
 
 	/**
-	 * Checks if can we do cache logic
+	 * Determines if the cache can be written for the given buffer and response headers.
+	 *
+	 * @param string $buffer           The content buffer to potentially cache.
+	 * @param array  $response_headers Response headers from the current request.
 	 *
-	 * @param string  $buffer
-	 * @return boolean
+	 * @return bool True if cache can be written, false otherwise.
 	 */
 	private function _can_write_cache( $buffer, $response_headers ) {
-		/**
-		 * Skip if caching is disabled
-		 */
-		if ( !$this->_caching ) {
+		// Skip if caching is disabled.
+		if ( ! $this->_caching ) {
 			return false;
 		}
 
-		/**
-		 * Check for DONOTCACHEPAGE constant
-		 */
+		// Check for DONOTCACHEPAGE constant.
 		if ( defined( 'DONOTCACHEPAGE' ) && DONOTCACHEPAGE ) {
 			$this->cache_reject_reason = 'DONOTCACHEPAGE constant is defined';
-			$this->process_status = 'miss_third_party';
+			$this->process_status      = 'miss_third_party';
 			return false;
 		}
 
-		if ( $this->_config->get_string( 'pgcache.rest' ) != 'cache' ) {
+		if ( 'cache' !== $this->_config->get_string( 'pgcache.rest' ) ) {
 			if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
 				$this->cache_reject_reason = 'REST request';
-				$this->process_status = 'miss_api_call';
-
+				$this->process_status      = 'miss_api_call';
 				return false;
 			}
 		}
 
-		/**
-		 * Don't cache 404 pages
-		 */
-		if ( !$this->_config->get_boolean( 'pgcache.cache.404' ) && function_exists( 'is_404' ) && is_404() ) {
+		// Don't cache 404 pages.
+		if ( ! $this->_config->get_boolean( 'pgcache.cache.404' ) && function_exists( 'is_404' ) && is_404() ) {
 			$this->cache_reject_reason = 'Page is 404';
-			$this->process_status = 'miss_404';
-
+			$this->process_status      = 'miss_404';
 			return false;
 		}
 
-		/**
-		 * Don't cache homepage
-		 */
-		if ( !$this->_config->get_boolean( 'pgcache.cache.home' ) && function_exists( 'is_home' ) && is_home() ) {
+		// Don't cache homepage.
+		if ( ! $this->_config->get_boolean( 'pgcache.cache.home' ) && function_exists( 'is_home' ) && is_home() ) {
 			$this->cache_reject_reason = is_front_page() && is_home() ? 'Page is front page' : 'Page is posts page';
-			$this->process_status = 'miss_configuration';
-
+			$this->process_status      = 'miss_configuration';
 			return false;
 		}
 
-		/**
-		 * Don't cache front page
-		 */
-		if ( $this->_config->get_boolean( 'pgcache.reject.front_page' ) && function_exists( 'is_front_page' ) && is_front_page() && !is_home() ) {
+		// Don't cache front page.
+		if ( $this->_config->get_boolean( 'pgcache.reject.front_page' ) && function_exists( 'is_front_page' ) && is_front_page() && ! is_home() ) {
 			$this->cache_reject_reason = 'Page is front page';
-			$this->process_status = 'miss_configuration';
-
+			$this->process_status      = 'miss_configuration';
 			return false;
 		}
 
-		/**
-		 * Don't cache feed
-		 */
-		if ( !$this->_config->get_boolean( 'pgcache.cache.feed' ) && function_exists( 'is_feed' ) && is_feed() ) {
+		// Don't cache feed.
+		if ( ! $this->_config->get_boolean( 'pgcache.cache.feed' ) && function_exists( 'is_feed' ) && is_feed() ) {
 			$this->cache_reject_reason = 'Page is feed';
-			$this->process_status = 'miss_configuration';
-
+			$this->process_status      = 'miss_configuration';
 			return false;
 		}
 
-		/**
-		 * Check if page contains dynamic tags
-		 */
+		// Check if page contains dynamic tags.
 		if ( $this->_enhanced_mode && $this->_has_dynamic( $buffer ) ) {
 			$this->cache_reject_reason = 'Page contains dynamic tags (mfunc or mclude) can not be cached in enhanced mode';
-			$this->process_status = 'miss_mfunc';
-
+			$this->process_status      = 'miss_mfunc';
 			return false;
 		}
 
-		if ( !$this->_passed_accept_files() ) {
+		if ( ! $this->_passed_accept_files() ) {
 			if ( is_single() ) {
-				/**
-				 * Don't cache pages associated with categories
-				 */
+				// Don't cache pages associated with categories.
 				if ( $this->_passed_reject_categories() ) {
 					$this->cache_reject_reason = 'Page associated with a rejected category';
-					$this->process_status = 'miss_configuration';
+					$this->process_status      = 'miss_configuration';
 					return false;
 				}
-				/**
-				 * Don't cache pages that use tags
-				 */
+
+				// Don't cache pages that use tags.
 				if ( $this->_passed_reject_tags() ) {
 					$this->cache_reject_reason = 'Page using a rejected tag';
-					$this->process_status = 'miss_configuration';
+					$this->process_status      = 'miss_configuration';
 					return false;
 				}
 			}
-			/**
-			 * Don't cache pages by these authors
-			 */
+
+			// Don't cache pages by these authors.
 			if ( $this->_passed_reject_authors() ) {
 				$this->cache_reject_reason = 'Page written by a rejected author';
-				$this->process_status = 'miss_configuration';
+				$this->process_status      = 'miss_configuration';
 				return false;
 			}
-			/**
-			 * Don't cache pages using custom fields
-			 */
+
+			// Don't cache pages using custom fields.
 			if ( $this->_passed_reject_custom_fields() ) {
 				$this->cache_reject_reason = 'Page using a rejected custom field';
-				$this->process_status = 'miss_configuration';
+				$this->process_status      = 'miss_configuration';
 				return false;
 			}
 		}
 
-		if ( !empty( $response_headers['kv']['content-encoding'] ) ) {
+		if ( ! empty( $response_headers['kv']['content-encoding'] ) ) {
 			$this->cache_reject_reason = 'Response is compressed';
-			$this->process_status = 'miss_compressed';
+			$this->process_status      = 'miss_compressed';
 			return false;
 		}
 
 		if ( empty( $buffer ) && empty( $response_headers['kv']['location'] ) ) {
 			$this->cache_reject_reason = 'Empty response';
-			$this->process_status = 'miss_empty_response';
+			$this->process_status      = 'miss_empty_response';
 			return false;
 		}
 
 		if ( isset( $response_headers['kv']['location'] ) ) {
-			// dont cache query-string normalization redirects
-			// (e.g. from wp core)
-			// when cache key is normalized, since that cause redirect loop
-
-			if ( $this->_get_page_key( $this->_page_key_extension ) ==
-					$this->_get_page_key( $this->_page_key_extension, $response_headers['kv']['location'] ) ) {
+			// dont cache query-string normalization redirects (e.g. from wp core) when cache key is normalized,
+			// since that cause redirect loop.
+
+			if (
+				$this->_get_page_key( $this->_page_key_extension ) === $this->_get_page_key(
+					$this->_page_key_extension,
+					$response_headers['kv']['location']
+				)
+			) {
 				$this->cache_reject_reason = 'Normalization redirect';
-				$this->process_status = 'miss_normalization_redirect';
+				$this->process_status      = 'miss_normalization_redirect';
 				return false;
 			}
 		}
 
-		if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
+		if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'HEAD' === $_SERVER['REQUEST_METHOD'] ) {
 			$this->cache_reject_reason = 'HEAD request';
-			$this->process_status = 'miss_request_method';
+			$this->process_status      = 'miss_request_method';
 			return;
 		}
 
 		return true;
 	}
 
+	/**
+	 * Retrieves the size of cache statistics.
+	 *
+	 * @param int $timeout_time Timeout in seconds for the operation.
+	 *
+	 * @return int|null The size of the cache statistics, or null if unavailable.
+	 */
 	public function get_cache_stats_size( $timeout_time ) {
 		$cache = $this->_get_cache();
-		if ( method_exists( $cache, 'get_stats_size' ) )
+		if ( method_exists( $cache, 'get_stats_size' ) ) {
 			return $cache->get_stats_size( $timeout_time );
+		}
 
 		return null;
 	}
 
+	/**
+	 * Retrieves usage statistics and configuration for the cache engine.
+	 *
+	 * @return array Configuration data for the cache engine.
+	 */
 	public function get_usage_statistics_cache_config() {
 		$engine = $this->_config->get_string( 'pgcache.engine' );
 
 		switch ( $engine ) {
-		case 'memcached':
-		case 'nginx_memcached':
-			$engineConfig = array(
-				'servers' => $this->_config->get_array( 'pgcache.memcached.servers' ),
-				'persistent' => $this->_config->get_boolean( 'pgcache.memcached.persistent' ),
-				'aws_autodiscovery' => $this->_config->get_boolean( 'pgcache.memcached.aws_autodiscovery' ),
-				'username' => $this->_config->get_string( 'pgcache.memcached.username' ),
-				'password' => $this->_config->get_string( 'pgcache.memcached.password' ),
-				'binary_protocol' => $this->_config->get_boolean( 'pgcache.memcached.binary_protocol' )
-			);
-			break;
-
-		case 'redis':
-			$engineConfig = array(
-				'servers' => $this->_config->get_array( 'pgcache.redis.servers' ),
-				'verify_tls_certificates' => $this->_config->get_boolean( 'pgcache.redis.verify_tls_certificates' ),
-				'persistent' => $this->_config->get_boolean( 'pgcache.redis.persistent' ),
-				'timeout' => $this->_config->get_integer( 'pgcache.redis.timeout' ),
-				'retry_interval' => $this->_config->get_integer( 'pgcache.redis.retry_interval' ),
-				'read_timeout' => $this->_config->get_integer( 'pgcache.redis.read_timeout' ),
-				'dbid' => $this->_config->get_integer( 'pgcache.redis.dbid' ),
-				'password' => $this->_config->get_string( 'pgcache.redis.password' )
-			);
-			break;
+			case 'memcached':
+			case 'nginx_memcached':
+				$engine_config = array(
+					'servers'           => $this->_config->get_array( 'pgcache.memcached.servers' ),
+					'persistent'        => $this->_config->get_boolean( 'pgcache.memcached.persistent' ),
+					'aws_autodiscovery' => $this->_config->get_boolean( 'pgcache.memcached.aws_autodiscovery' ),
+					'username'          => $this->_config->get_string( 'pgcache.memcached.username' ),
+					'password'          => $this->_config->get_string( 'pgcache.memcached.password' ),
+					'binary_protocol'   => $this->_config->get_boolean( 'pgcache.memcached.binary_protocol' ),
+				);
+				break;
 
-		case 'file_generic':
-			$engine = 'file';
-			break;
+			case 'redis':
+				$engine_config = array(
+					'servers'                 => $this->_config->get_array( 'pgcache.redis.servers' ),
+					'verify_tls_certificates' => $this->_config->get_boolean( 'pgcache.redis.verify_tls_certificates' ),
+					'persistent'              => $this->_config->get_boolean( 'pgcache.redis.persistent' ),
+					'timeout'                 => $this->_config->get_integer( 'pgcache.redis.timeout' ),
+					'retry_interval'          => $this->_config->get_integer( 'pgcache.redis.retry_interval' ),
+					'read_timeout'            => $this->_config->get_integer( 'pgcache.redis.read_timeout' ),
+					'dbid'                    => $this->_config->get_integer( 'pgcache.redis.dbid' ),
+					'password'                => $this->_config->get_string( 'pgcache.redis.password' ),
+				);
+				break;
+
+			case 'file_generic':
+				$engine = 'file';
+				break;
 
-		default:
-			$engineConfig = array();
+			default:
+				$engine_config = array();
 		}
 
-		$engineConfig['engine'] = $engine;
-		return $engineConfig;
+		$engine_config['engine'] = $engine;
+
+		return $engine_config;
 	}
 
 	/**
-	 * Returns cache object
+	 * Retrieves the cache instance for a specific group.
+	 *
+	 * @param string $group Cache group name. Defaults to '*'.
 	 *
-	 * @return W3_Cache_Base
+	 * @return mixed Cache instance.
 	 */
-	function _get_cache( $group = '*' ) {
+	public function _get_cache( $group = '*' ) {
 		static $caches = array();
 
 		if ( empty( $group ) ) {
 			$group = '*';
 		}
 
-		if ( empty( $caches[$group] ) ) {
+		if ( empty( $caches[ $group ] ) ) {
 			$engine = $this->_config->get_string( 'pgcache.engine' );
 
 			switch ( $engine ) {
-			case 'memcached':
-			case 'nginx_memcached':
-				$engineConfig = array(
-					'servers' => $this->_config->get_array( 'pgcache.memcached.servers' ),
-					'persistent' => $this->_config->get_boolean( 'pgcache.memcached.persistent' ),
-					'aws_autodiscovery' => $this->_config->get_boolean( 'pgcache.memcached.aws_autodiscovery' ),
-					'username' => $this->_config->get_string( 'pgcache.memcached.username' ),
-					'password' => $this->_config->get_string( 'pgcache.memcached.password' ),
-					'binary_protocol' => $this->_config->get_boolean( 'pgcache.memcached.binary_protocol' ),
-					'host' => Util_Environment::host(),
-				);
-				break;
-
-			case 'redis':
-				$engineConfig = array(
-					'servers' => $this->_config->get_array( 'pgcache.redis.servers' ),
-					'verify_tls_certificates' => $this->_config->get_boolean( 'pgcache.redis.verify_tls_certificates' ),
-					'persistent' => $this->_config->get_boolean( 'pgcache.redis.persistent' ),
-					'timeout' => $this->_config->get_integer( 'pgcache.redis.timeout' ),
-					'retry_interval' => $this->_config->get_integer( 'pgcache.redis.retry_interval' ),
-					'read_timeout' => $this->_config->get_integer( 'pgcache.redis.read_timeout' ),
-					'dbid' => $this->_config->get_integer( 'pgcache.redis.dbid' ),
-					'password' => $this->_config->get_string( 'pgcache.redis.password' )
-				);
-				break;
+				case 'memcached':
+				case 'nginx_memcached':
+					$engine_config = array(
+						'servers'           => $this->_config->get_array( 'pgcache.memcached.servers' ),
+						'persistent'        => $this->_config->get_boolean( 'pgcache.memcached.persistent' ),
+						'aws_autodiscovery' => $this->_config->get_boolean( 'pgcache.memcached.aws_autodiscovery' ),
+						'username'          => $this->_config->get_string( 'pgcache.memcached.username' ),
+						'password'          => $this->_config->get_string( 'pgcache.memcached.password' ),
+						'binary_protocol'   => $this->_config->get_boolean( 'pgcache.memcached.binary_protocol' ),
+						'host'              => Util_Environment::host(),
+					);
+					break;
 
-			case 'file':
-				$engineConfig = array(
-					'section' => 'page',
-					'flush_parent' => ( Util_Environment::blog_id() == 0 ),
-					'locking' => $this->_config->get_boolean( 'pgcache.file.locking' ),
-					'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' )
-				);
-				break;
+				case 'redis':
+					$engine_config = array(
+						'servers'                 => $this->_config->get_array( 'pgcache.redis.servers' ),
+						'verify_tls_certificates' => $this->_config->get_boolean( 'pgcache.redis.verify_tls_certificates' ),
+						'persistent'              => $this->_config->get_boolean( 'pgcache.redis.persistent' ),
+						'timeout'                 => $this->_config->get_integer( 'pgcache.redis.timeout' ),
+						'retry_interval'          => $this->_config->get_integer( 'pgcache.redis.retry_interval' ),
+						'read_timeout'            => $this->_config->get_integer( 'pgcache.redis.read_timeout' ),
+						'dbid'                    => $this->_config->get_integer( 'pgcache.redis.dbid' ),
+						'password'                => $this->_config->get_string( 'pgcache.redis.password' ),
+					);
+					break;
 
-			case 'file_generic':
-				if ( $group != '*' ) {
-					$engine = 'file';
-
-					$engineConfig = array(
-						'section' => 'page',
-						'cache_dir' =>
-							W3TC_CACHE_PAGE_ENHANCED_DIR .
-							DIRECTORY_SEPARATOR .
-							Util_Environment::host_port(),
-						'flush_parent' => ( Util_Environment::blog_id() == 0 ),
-						'locking' => $this->_config->get_boolean( 'pgcache.file.locking' ),
-						'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' )
+				case 'file':
+					$engine_config = array(
+						'section'         => 'page',
+						'flush_parent'    => ( Util_Environment::blog_id() === 0 ),
+						'locking'         => $this->_config->get_boolean( 'pgcache.file.locking' ),
+						'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' ),
 					);
 					break;
-				}
 
-				if ( Util_Environment::blog_id() == 0 ) {
-					$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
-				} else {
-					$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR .
-						DIRECTORY_SEPARATOR .
-						Util_Environment::host();
-				}
+				case 'file_generic':
+					if ( '*' !== $group ) {
+						$engine = 'file';
 
-				$engineConfig = array(
-					'exclude' => array(
-						'.htaccess'
-					),
-					'expire' => $this->_lifetime,
-					'cache_dir' => W3TC_CACHE_PAGE_ENHANCED_DIR,
-					'locking' => $this->_config->get_boolean( 'pgcache.file.locking' ),
-					'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' ),
-					'flush_dir' => $flush_dir,
-				);
-				break;
+						$engine_config = array(
+							'section'         => 'page',
+							'cache_dir'       => W3TC_CACHE_PAGE_ENHANCED_DIR . DIRECTORY_SEPARATOR . Util_Environment::host_port(),
+							'flush_parent'    => ( Util_Environment::blog_id() === 0 ),
+							'locking'         => $this->_config->get_boolean( 'pgcache.file.locking' ),
+							'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' ),
+						);
+						break;
+					}
 
-			default:
-				$engineConfig = array();
+					if ( 0 === Util_Environment::blog_id() ) {
+						$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
+					} else {
+						$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . DIRECTORY_SEPARATOR . Util_Environment::host();
+					}
+
+					$engine_config = array(
+						'exclude'         => array(
+							'.htaccess',
+						),
+						'expire'          => $this->_lifetime,
+						'cache_dir'       => W3TC_CACHE_PAGE_ENHANCED_DIR,
+						'locking'         => $this->_config->get_boolean( 'pgcache.file.locking' ),
+						'flush_timelimit' => $this->_config->get_integer( 'timelimit.cache_flush' ),
+						'flush_dir'       => $flush_dir,
+					);
+					break;
+
+				default:
+					$engine_config = array();
 			}
 
-			$engineConfig['use_expired_data'] = true;
-			$engineConfig['module']           = 'pgcache';
-			$engineConfig['host']             = '';
-			$engineConfig['instance_id']      = Util_Environment::instance_id();
+			$engine_config['use_expired_data'] = true;
+			$engine_config['module']           = 'pgcache';
+			$engine_config['host']             = '';
+			$engine_config['instance_id']      = Util_Environment::instance_id();
 
-			$caches[$group] = Cache::instance( $engine, $engineConfig );
+			$caches[ $group ] = Cache::instance( $engine, $engine_config );
 		}
 
-		return $caches[$group];
+		return $caches[ $group ];
 	}
 
 	/**
-	 * Checks request URI
+	 * Determines if the current request passes the reject URI conditions.
 	 *
-	 * @return boolean
+	 * @return bool True if the request passes the reject URI conditions, false otherwise.
 	 */
-	function _passed_reject_uri() {
+	public function _passed_reject_uri() {
 		$auto_reject_uri = array(
 			'wp-login',
-			'wp-register'
+			'wp-register',
 		);
 
 		foreach ( $auto_reject_uri as $uri ) {
@@ -988,7 +1031,7 @@ function _passed_reject_uri() {
 
 		foreach ( $reject_uri as $expr ) {
 			$expr = trim( $expr );
-			if ( $expr != '' && preg_match( '~' . $expr . '~i', $this->_request_uri ) ) {
+			if ( '' !== $expr && preg_match( '~' . $expr . '~i', $this->_request_uri ) ) {
 				return false;
 			}
 		}
@@ -997,90 +1040,114 @@ function _passed_reject_uri() {
 	}
 
 	/**
-	 * Check if in the cache exception list
+	 * Determines if the current request passes the accept files conditions.
 	 *
-	 * @return boolean
+	 * @return bool True if the request passes the accept files conditions, false otherwise.
 	 */
-	function _passed_accept_files() {
+	public function _passed_accept_files() {
 		$accept_uri = $this->_config->get_array( 'pgcache.accept.files' );
 		$accept_uri = array_map( array( '\W3TC\Util_Environment', 'parse_path' ), $accept_uri );
-		foreach ( $accept_uri as &$val ) $val = trim( str_replace( "~", "\~", $val ) );
-		$accept_uri = array_filter( $accept_uri, function( $val ){ return $val != ""; } );
-		if ( !empty( $accept_uri ) && @preg_match( '~' . implode( "|", $accept_uri ) . '~i', $this->_request_uri ) ) {
+
+		foreach ( $accept_uri as &$val ) {
+			$val = trim( str_replace( '~', '\~', $val ) );
+		}
+
+		$accept_uri = array_filter(
+			$accept_uri,
+			function( $val ) {
+				return '' !== $val;
+			}
+		);
+
+		if ( ! empty( $accept_uri ) && @preg_match( '~' . implode( '|', $accept_uri ) . '~i', $this->_request_uri ) ) {
 			return true;
 		}
+
 		return false;
 	}
+
 	/**
-	 * Checks page against rejected categories
+	 * Determines if the current request is rejected based on categories.
 	 *
-	 * @return boolean
+	 * @return bool True if the request is rejected due to categories, false otherwise.
 	 */
-	function _passed_reject_categories() {
+	public function _passed_reject_categories() {
 		$reject_categories = $this->_config->get_array( 'pgcache.reject.categories' );
-		if ( !empty( $reject_categories ) ) {
-			if ( $cats = get_the_category() ) {
-			   foreach( $cats as $cat ) {
-				  if ( in_array( $cat->slug, $reject_categories ) ) {
+		if ( ! empty( $reject_categories ) ) {
+			$cats = get_the_category();
+			if ( $cats ) {
+				foreach ( $cats as $cat ) {
+					if ( in_array( $cat->slug, $reject_categories, true ) ) {
 						return true;
-				  }
-			   }
+					}
+				}
 			}
 		}
+
 		return false;
 	}
+
 	/**
-	 * Checks page against rejected tags
+	 * Determines if the current request is rejected based on tags.
 	 *
-	 * @return boolean
+	 * @return bool True if the request is rejected due to tags, false otherwise.
 	 */
-	function _passed_reject_tags() {
+	public function _passed_reject_tags() {
 		$reject_tags = $this->_config->get_array( 'pgcache.reject.tags' );
-		if ( !empty( $reject_tags ) ) {
-			if ( $tags = get_the_tags() ) {
-			   foreach( $tags as $tag ) {
-				  if ( in_array( $tag->slug,$reject_tags ) ) {
+		if ( ! empty( $reject_tags ) ) {
+			$tags = get_the_tags();
+			if ( $tags ) {
+				foreach ( $tags as $tag ) {
+					if ( in_array( $tag->slug, $reject_tags, true ) ) {
 						return true;
-				  }
-			   }
+					}
+				}
 			}
 		}
+
 		return false;
 	}
+
 	/**
-	 * Checks page against rejected authors
+	 * Determines if the current request is rejected based on authors.
 	 *
-	 * @return boolean
+	 * @return bool True if the request is rejected due to authors, false otherwise.
 	 */
-	function _passed_reject_authors() {
+	public function _passed_reject_authors() {
 		$reject_authors = $this->_config->get_array( 'pgcache.reject.authors' );
-		if ( !empty( $reject_authors ) ) {
-			if ( $author = get_the_author_meta( 'user_login' ) ) {
-				if ( in_array( $author, $reject_authors ) ) {
+		if ( ! empty( $reject_authors ) ) {
+			$author = get_the_author_meta( 'user_login' );
+			if ( $author ) {
+				if ( in_array( $author, $reject_authors, true ) ) {
 					return true;
 				}
 			}
 		}
+
 		return false;
 	}
+
 	/**
-	 * Checks page against rejected custom fields
+	 * Determines if the current request is rejected based on custom fields.
 	 *
-	 * @return boolean
+	 * @return bool True if the request is rejected due to custom fields, false otherwise.
 	 */
-	function _passed_reject_custom_fields() {
+	public function _passed_reject_custom_fields() {
 		$reject_custom = $this->_config->get_array( 'pgcache.reject.custom' );
-		if ( empty( $reject_custom ) )
+		if ( empty( $reject_custom ) ) {
 			return false;
+		}
 
 		foreach ( $reject_custom as &$val ) {
 			$val = preg_quote( trim( $val ), '~' );
 		}
+
 		$reject_custom = implode( '|', array_filter( $reject_custom ) );
-		if ( !empty( $reject_custom ) ) {
-			if ( $customs = get_post_custom() ) {
+		if ( ! empty( $reject_custom ) ) {
+			$customs = get_post_custom();
+			if ( $customs ) {
 				foreach ( $customs as $key => $value ) {
-					if ( @preg_match( '~' . $reject_custom . '~i', $key . ( isset( $value[0] ) ? "={$value[0]}" : "" ) ) ) {
+					if ( @preg_match( '~' . $reject_custom . '~i', $key . ( isset( $value[0] ) ? "={$value[0]}" : '' ) ) ) {
 						return true;
 					}
 				}
@@ -1091,20 +1158,23 @@ function _passed_reject_custom_fields() {
 	}
 
 	/**
-	 * Checks User Agent
+	 * Validates the User-Agent against rejection rules.
 	 *
-	 * @return boolean
+	 * @return bool True if the User-Agent passes validation, false otherwise.
 	 */
-	function _check_ua() {
+	public function _check_ua() {
 		$uas = $this->_config->get_array( 'pgcache.reject.ua' );
 
 		$uas = array_merge( $uas, array( W3TC_POWERED_BY ) );
 
 		foreach ( $uas as $ua ) {
-			if ( !empty( $ua ) ) {
-				if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
-					stristr( htmlspecialchars( stripslashes( $_SERVER['HTTP_USER_AGENT'] ) ), $ua ) !== false ) // phpcs:ignore
+			if ( ! empty( $ua ) ) {
+				if (
+					isset( $_SERVER['HTTP_USER_AGENT'] ) &&
+					stristr( htmlspecialchars( stripslashes( $_SERVER['HTTP_USER_AGENT'] ) ), $ua ) !== false
+				) {
 					return false;
+				}
 			}
 		}
 
@@ -1112,22 +1182,23 @@ function _check_ua() {
 	}
 
 	/**
-	 * Checks WordPress cookies
+	 * Checks if the current request passes the cookie rejection rules.
 	 *
-	 * @return boolean
+	 * @return bool True if the request passes cookie validation, false otherwise.
 	 */
-	function _check_cookies() {
+	public function _check_cookies() {
 		foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
-			if ( $cookie_name == 'wordpress_test_cookie' ) {
+			if ( 'wordpress_test_cookie' === $cookie_name ) {
 				continue;
 			}
+
 			if ( preg_match( '/^(wp-postpass|comment_author)/', $cookie_name ) ) {
 				return false;
 			}
 		}
 
 		foreach ( $this->_config->get_array( 'pgcache.reject.cookie' ) as $reject_cookie ) {
-			if ( !empty( $reject_cookie ) ) {
+			if ( ! empty( $reject_cookie ) ) {
 				foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
 					if ( strstr( $cookie_name, $reject_cookie ) !== false ) {
 						return false;
@@ -1140,37 +1211,43 @@ function _check_cookies() {
 	}
 
 	/**
-	 * Check if user is logged in
+	 * Checks if the user is logged in and rejects the request if true.
 	 *
-	 * @return boolean
+	 * @return bool True if the user is not logged in, false otherwise.
 	 */
-	function _check_logged_in() {
+	public function _check_logged_in() {
 		foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
-			if ( strpos( $cookie_name, 'wordpress_logged_in' ) === 0 )
+			if ( strpos( $cookie_name, 'wordpress_logged_in' ) === 0 ) {
 				return false;
+			}
 		}
 
 		return true;
 	}
 
+
 	/**
-	 * Check if logged in user role is allwed to be cached
+	 * Validates if a logged-in user's role is allowed.
 	 *
-	 * @return boolean
+	 * @return bool True if the logged-in user's role is allowed, false otherwise.
 	 */
-	function _check_logged_in_role_allowed() {
-		if ( !$this->_config->get_boolean( 'pgcache.reject.logged_roles' ) )
+	public function _check_logged_in_role_allowed() {
+		if ( ! $this->_config->get_boolean( 'pgcache.reject.logged_roles' ) ) {
 			return true;
+		}
+
 		$roles = $this->_config->get_array( 'pgcache.reject.roles' );
 
-		if ( empty( $roles ) )
+		if ( empty( $roles ) ) {
 			return true;
+		}
 
 		foreach ( array_keys( $_COOKIE ) as $cookie_name ) {
 			if ( strpos( $cookie_name, 'w3tc_logged_' ) === 0 ) {
 				foreach ( $roles as $role ) {
-					if ( strstr( $cookie_name, md5( NONCE_KEY . $role ) ) )
+					if ( strstr( $cookie_name, md5( NONCE_KEY . $role ) ) ) {
 						return false;
+					}
 				}
 			}
 		}
@@ -1179,101 +1256,124 @@ function _check_logged_in_role_allowed() {
 	}
 
 	/**
-	 * Checks if rules file present and creates it if not
+	 * Ensures that the required cache rules are present.
+	 *
+	 * @return void
 	 */
-	function _check_rules_present() {
-		if ( Util_Environment::is_nginx() )
-			return;   // nginx store it in a single file
+	public function _check_rules_present() {
+		if ( Util_Environment::is_nginx() ) {
+			return; // nginx store it in a single file.
+		}
 
 		$filename = Util_Rule::get_pgcache_rules_cache_path();
-		if ( file_exists( $filename ) )
+		if ( file_exists( $filename ) ) {
 			return;
+		}
 
-		// we call it as little times as possible
-		// its expensive, but have to restore lost .htaccess file
+		// we call it as little times as possible its expensive, but have to restore lost .htaccess file.
 		$e = Dispatcher::component( 'PgCache_Environment' );
 		try {
 			$e->fix_on_wpadmin_request( $this->_config, true );
-		} catch ( \Exception $ex ) {
+		} catch ( \Exception $ex ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
+			// Exception.
 		}
 	}
 
 	/**
-	 * Compress data
+	 * Compresses the given data using the specified compression method.
+	 *
+	 * @param string $data        The data to be compressed.
+	 * @param string $compression The compression method ('gzip', 'deflate', 'br').
 	 *
-	 * @param string  $data
-	 * @param string  $compression
-	 * @return string
+	 * @return string The compressed data.
 	 */
-	function _compress( $data, $compression ) {
+	public function _compress( $data, $compression ) {
 		switch ( $compression ) {
-		case 'gzip':
-			$data = gzencode( $data );
-			break;
+			case 'gzip':
+				$data = gzencode( $data );
+				break;
 
-		case 'deflate':
-			$data = gzdeflate( $data );
-			break;
+			case 'deflate':
+				$data = gzdeflate( $data );
+				break;
 
-		case 'br':
-			$data = brotli_compress( $data );
-			break;
+			case 'br':
+				$data = brotli_compress( $data );
+				break;
 		}
 
 		return $data;
 	}
 
 	/**
-	 * Returns page key extension for current request
+	 * Retrieves the key extension used for cache identification.
 	 *
-	 * @return string
+	 * @return array An associative array representing the key extension.
 	 */
 	private function _get_key_extension() {
 		$extension = array(
-			'useragent' => '',
-			'referrer' => '',
-			'cookie' => '',
-			'encryption' => '',
-			'compression' => $this->_get_compression(),
-			'content_type' => '',
-			'cache' => true,
+			'useragent'           => '',
+			'referrer'            => '',
+			'cookie'              => '',
+			'encryption'          => '',
+			'compression'         => $this->_get_compression(),
+			'content_type'        => '',
+			'cache'               => true,
 			'cache_reject_reason' => '',
-			'group' => ''
+			'group'               => '',
 		);
 
-		if ( $this->_mobile )
+		if ( $this->_mobile ) {
 			$extension['useragent'] = $this->_mobile->get_group();
-		if ( $this->_referrer )
+		}
+
+		if ( $this->_referrer ) {
 			$extension['referrer'] = $this->_referrer->get_group();
-		if ( Util_Environment::is_https() )
+		}
+
+		if ( Util_Environment::is_https() ) {
 			$extension['encryption'] = 'ssl';
+		}
 
 		$this->_fill_key_extension_cookie( $extension );
 
-		// fill group
+		// fill group.
 		$extension['group'] = $this->get_cache_group_by_uri( $this->_request_uri );
-		$extension = w3tc_apply_filters( 'pagecache_key_extension', $extension,
-			$this->_request_url_fragments['host'], $this->_request_uri );
+		$extension          = w3tc_apply_filters(
+			'pagecache_key_extension',
+			$extension,
+			$this->_request_url_fragments['host'],
+			$this->_request_uri
+		);
 
 		return $extension;
 	}
 
+	/**
+	 * Fills the key extension with cookie-related information.
+	 *
+	 * @param array $extension Reference to the key extension array.
+	 *
+	 * @return void
+	 */
 	private function _fill_key_extension_cookie( &$extension ) {
-		if ( !$this->_config->get_boolean( 'pgcache.cookiegroups.enabled' ) )
+		if ( ! $this->_config->get_boolean( 'pgcache.cookiegroups.enabled' ) ) {
 			return;
+		}
 
 		$groups = $this->_config->get_array( 'pgcache.cookiegroups.groups' );
 		foreach ( $groups as $group_name => $g ) {
 			if ( isset( $g['enabled'] ) && $g['enabled'] ) {
-
 				$cookies = array();
-				foreach ($g['cookies'] as $cookie ) {
+				foreach ( $g['cookies'] as $cookie ) {
 					$cookie = trim( $cookie );
-					if ( !empty( $cookie ) ) {
+					if ( ! empty( $cookie ) ) {
 						$cookie = str_replace( '+', ' ', $cookie );
 						$cookie = Util_Environment::preg_quote( $cookie );
-						if ( strpos( $cookie, '=') === false )
+						if ( strpos( $cookie, '=' ) === false ) {
 							$cookie .= '=.*';
+						}
+
 						$cookies[] = $cookie;
 					}
 				}
@@ -1284,10 +1384,11 @@ private function _fill_key_extension_cookie( &$extension ) {
 					foreach ( $_COOKIE as $key => $value ) {
 						if ( @preg_match( $cookies_regexp, $key . '=' . $value ) ) {
 							$extension['cookie'] = $group_name;
-							if ( !$g['cache'] ) {
-								$extension['cache'] = false;
+							if ( ! $g['cache'] ) {
+								$extension['cache']               = false;
 								$extension['cache_reject_reason'] = 'cookiegroup ' . $group_name;
 							}
+
 							return;
 						}
 					}
@@ -1296,24 +1397,28 @@ private function _fill_key_extension_cookie( &$extension ) {
 		}
 	}
 
+	/**
+	 * Determines the cache group based on the provided URI.
+	 *
+	 * @param string $uri The URI to analyze.
+	 *
+	 * @return string The cache group name.
+	 */
 	protected function get_cache_group_by_uri( $uri ) {
-		// "!$this->_enhanced_mode" in condition above
-		// prevents usage of separate group under disk-enhanced
-		// so that rewrite rules still work.
-		// flushing is handled by workaround in this case
-		if ( !$this->_enhanced_mode ) {
-			$sitemap_regex = $this->_config->get_string(
-				'pgcache.purge.sitemap_regex' );
-
-			if ( $sitemap_regex && preg_match( '~' . $sitemap_regex . '~',
-					basename( $uri ) ) ) {
+		// "!$this->_enhanced_mode" in condition above prevents usage of separate group under disk-enhanced
+		// so that rewrite rules still work. Flushing is handled by workaround in this case.
+		if ( ! $this->_enhanced_mode ) {
+			$sitemap_regex = $this->_config->get_string( 'pgcache.purge.sitemap_regex' );
+			if ( $sitemap_regex && preg_match( '~' . $sitemap_regex . '~', basename( $uri ) ) ) {
 				return 'sitemaps';
 			}
 		}
 
-		if ( $this->_config->get_string( 'pgcache.rest' ) == 'cache' &&
-				Util_Environment::is_rest_request( $uri ) &&
-				Util_Environment::is_w3tc_pro( $this->_config ) ) {
+		if (
+			'cache' === $this->_config->get_string( 'pgcache.rest' ) &&
+			Util_Environment::is_rest_request( $uri ) &&
+			Util_Environment::is_w3tc_pro( $this->_config )
+		) {
 			return 'rest';
 		}
 
@@ -1321,21 +1426,23 @@ protected function get_cache_group_by_uri( $uri ) {
 	}
 
 	/**
-	 * Returns current compression
+	 * Retrieves the compression type supported by the server.
 	 *
-	 * @return boolean
+	 * @return string The supported compression type ('gzip', 'br', or empty string).
 	 */
-	function _get_compression() {
-		if ( $this->_debug )   // cannt generate/use compressed files during debug mode
+	public function _get_compression() {
+		if ( $this->_debug ) { // Can't generate/use compressed files during debug mode.
 			return '';
+		}
 
-		if ( !Util_Environment::is_zlib_enabled() && !$this->_is_buggy_ie() ) {
+		if ( ! Util_Environment::is_zlib_enabled() && ! $this->_is_buggy_ie() ) {
 			$compressions = $this->_get_compressions();
-
 			foreach ( $compressions as $compression ) {
-				if ( is_string( $compression ) &&
+				if (
+					is_string( $compression ) &&
 					isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) &&
-					stristr( htmlspecialchars( stripslashes( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ), $compression ) !== false ) { // phpcs:ignore
+					stristr( htmlspecialchars( stripslashes( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ), $compression ) !== false
+				) {
 					return $compression;
 				}
 			}
@@ -1345,28 +1452,32 @@ function _get_compression() {
 	}
 
 	/**
-	 * Returns array of compressions
+	 * Retrieves the list of supported compression methods.
 	 *
-	 * @return array
+	 * @return array An array of supported compression methods.
 	 */
-	function _get_compressions() {
+	public function _get_compressions() {
 		$compressions = array(
-			false
+			false,
 		);
 
 		if ( defined( 'W3TC_PAGECACHE_STORE_COMPRESSION_OFF' ) ) {
 			return $compressions;
 		}
 
-		if ( $this->_config->get_boolean( 'browsercache.enabled' ) &&
+		if (
+			$this->_config->get_boolean( 'browsercache.enabled' ) &&
 			$this->_config->get_boolean( 'browsercache.html.compression' ) &&
-			function_exists( 'gzencode' ) ) {
+			function_exists( 'gzencode' )
+		) {
 			$compressions[] = 'gzip';
 		}
 
-		if ( $this->_config->get_boolean( 'browsercache.enabled' ) &&
+		if (
+			$this->_config->get_boolean( 'browsercache.enabled' ) &&
 			$this->_config->get_boolean( 'browsercache.html.brotli' ) &&
-			function_exists( 'brotli_compress' ) ) {
+			function_exists( 'brotli_compress' )
+		) {
 			$compressions[] = 'br';
 		}
 
@@ -1374,12 +1485,12 @@ function_exists( 'brotli_compress' ) ) {
 	}
 
 	/**
-	 * Returns array of response headers
+	 * Retrieves the response headers sent by the server.
 	 *
-	 * @return array
+	 * @return array An associative array containing 'kv' and 'plain' header representations.
 	 */
-	function _get_response_headers() {
-		$headers_kv = array();
+	public function _get_response_headers() {
+		$headers_kv    = array();
 		$headers_plain = array();
 
 		if ( function_exists( 'headers_list' ) ) {
@@ -1388,40 +1499,41 @@ function _get_response_headers() {
 				foreach ( $headers_list as $header ) {
 					$pos = strpos( $header, ':' );
 					if ( $pos ) {
-						$header_name = trim( substr( $header, 0, $pos ) );
+						$header_name  = trim( substr( $header, 0, $pos ) );
 						$header_value = trim( substr( $header, $pos + 1 ) );
 					} else {
-						$header_name = $header;
+						$header_name  = $header;
 						$header_value = '';
 					}
-					$headers_kv[strtolower($header_name)] = $header_value;
-					$headers_plain[] = array(
-						'name' => $header_name,
-						'value' => $header_value
+
+					$headers_kv[ strtolower( $header_name ) ] = $header_value;
+					$headers_plain[]                          = array(
+						'name'  => $header_name,
+						'value' => $header_value,
 					);
 				}
 			}
 		}
 
 		return array(
-			'kv' => $headers_kv,
-			'plain' => $headers_plain
+			'kv'    => $headers_kv,
+			'plain' => $headers_plain,
 		);
 	}
 
 	/**
-	 * Checks for buggy IE6 that doesn't support compression
+	 * Checks if the user is using a buggy version of Internet Explorer.
 	 *
-	 * @return boolean
+	 * @return bool True if a buggy version of Internet Explorer is detected, false otherwise.
 	 */
-	function _is_buggy_ie() {
+	public function _is_buggy_ie() {
 		if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
 			$ua = htmlspecialchars( stripslashes( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore
 
 			if ( strpos( $ua, 'Mozilla/4.0 (compatible; MSIE ' ) === 0 && strpos( $ua, 'Opera' ) === false ) {
 				$version = (float) substr( $ua, 30 );
 
-				return $version < 6 || ( $version == 6 && strpos( $ua, 'SV1' ) === false );
+				return $version < 6 || ( 6 === $version && false === strpos( $ua, 'SV1' ) );
 			}
 		}
 
@@ -1429,44 +1541,45 @@ function _is_buggy_ie() {
 	}
 
 	/**
-	 * Returns array of data headers
+	 * Filters and retrieves cached headers from the response.
 	 *
-	 * @return array
+	 * @param array $response_headers An array of response headers.
+	 *
+	 * @return array An array of cached headers.
 	 */
-	function _get_cached_headers( $response_headers ) {
-		$data_headers = array();
+	public function _get_cached_headers( $response_headers ) {
+		$data_headers  = array();
 		$cache_headers = array_merge(
 			array( 'Location', 'X-WP-Total', 'X-WP-TotalPages' ),
 			$this->_config->get_array( 'pgcache.cache.headers' )
 		);
 
-		if ( function_exists( 'http_response_code' ) ) {   // php5.3 compatibility
+		if ( function_exists( 'http_response_code' ) ) { // php5.3 compatibility.
 			$data_headers['Status-Code'] = http_response_code();
 		}
 
 		$repeating_headers = array(
 			'link',
 			'cookie',
-			'set-cookie'
+			'set-cookie',
 		);
-		$repeating_headers = apply_filters( 'w3tc_repeating_headers',
-			$repeating_headers );
+		$repeating_headers = apply_filters( 'w3tc_repeating_headers', $repeating_headers );
 
 		foreach ( $response_headers as $i ) {
-			$header_name = $i['name'];
+			$header_name  = $i['name'];
 			$header_value = $i['value'];
 
 			foreach ( $cache_headers as $cache_header_name ) {
-				if ( strcasecmp( $header_name, $cache_header_name ) == 0 ) {
+				if ( strcasecmp( $header_name, $cache_header_name ) === 0 ) {
 					$header_name_lo = strtolower( $header_name );
-					if ( in_array($header_name_lo, $repeating_headers) ) {
-						// headers may repeat
+					if ( in_array( $header_name_lo, $repeating_headers, true ) ) {
+						// headers may repeat.
 						$data_headers[] = array(
 							'n' => $header_name,
-							'v' => $header_value
+							'v' => $header_value,
 						);
 					} else {
-						$data_headers[$header_name] = $header_value;
+						$data_headers[ $header_name ] = $header_value;
 					}
 				}
 			}
@@ -1476,116 +1589,127 @@ function _get_cached_headers( $response_headers ) {
 	}
 
 	/**
-	 * Returns page key
+	 * Constructs a unique cache key for the page.
+	 *
+	 * @param array  $page_key_extension An array of page key extensions.
+	 * @param string $request_url        Optional. The request URL.
 	 *
-	 * @return string
+	 * @return string The constructed cache key.
 	 */
-	function _get_page_key( $page_key_extension, $request_url = '' ) {
-		// key url part
+	public function _get_page_key( $page_key_extension, $request_url = '' ) {
+		// key url part.
 		if ( empty( $request_url ) ) {
 			$request_url_fragments = $this->_request_url_fragments;
 		} else {
 			$request_url_fragments = array();
 
-			$parts = parse_url( $request_url );
+			$parts = wp_parse_url( $request_url );
 
 			if ( isset( $parts['host'] ) ) {
-				$request_url_fragments['host'] = $parts['host'] .
-					( isset( $parts['port'] ) ? ':' . $parts['port'] : '' );
+				$request_url_fragments['host'] = $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' );
 			} else {
 				$request_url_fragments['host'] = $this->_request_url_fragments['host'];
 			}
 
-			$request_url_fragments['path'] =
-				( isset( $parts['path'] ) ? $parts['path'] : '' );
-			$request_url_fragments['querystring'] =
-				( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
-			$request_url_fragments = $this->_normalize_url_fragments(
-				$request_url_fragments );
+			$request_url_fragments['path']        = ( isset( $parts['path'] ) ? $parts['path'] : '' );
+			$request_url_fragments['querystring'] = ( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
+			$request_url_fragments                = $this->_normalize_url_fragments( $request_url_fragments );
 		}
 
-		$key_urlpart =
-			$request_url_fragments['host'] .
-			( $request_url_fragments['path'] ?? '' ) .
+		$key_urlpart = $request_url_fragments['host'] . ( $request_url_fragments['path'] ?? '' ) .
 			( $request_url_fragments['querystring'] ?? '' );
 
 		$key_urlpart = $this->_get_page_key_urlpart( $key_urlpart, $page_key_extension );
 
-		// key extension
+		// key extension.
 		$key_extension = '';
-		$extensions = array( 'useragent', 'referrer', 'cookie', 'encryption' );
+		$extensions    = array( 'useragent', 'referrer', 'cookie', 'encryption' );
 		foreach ( $extensions as $e ) {
-			if ( !empty( $page_key_extension[$e] ) ) {
-				$key_extension .= '_' . $page_key_extension[$e];
+			if ( ! empty( $page_key_extension[ $e ] ) ) {
+				$key_extension .= '_' . $page_key_extension[ $e ];
 			}
 		}
+
 		if ( Util_Environment::is_preview_mode() ) {
 			$key_extension .= '_preview';
 		}
 
-		// key postfix
+		// key postfix.
 		$key_postfix = '';
 		if ( $this->_enhanced_mode && empty( $page_key_extension['group'] ) ) {
 			$key_postfix = '.html';
 			if ( $this->_config->get_boolean( 'pgcache.cache.nginx_handle_xml' ) ) {
-				$content_type = isset( $page_key_extension['content_type'] ) ?
-					$page_key_extension['content_type'] : '';
+				$content_type = isset( $page_key_extension['content_type'] ) ? $page_key_extension['content_type'] : '';
 
-				if ( @preg_match( "~(text/xml|text/xsl|application/xhtml\+xml|application/rdf\+xml|application/rss\+xml|application/atom\+xml|application/xml)~i", $content_type ) ||
-				preg_match( W3TC_FEED_REGEXP, $request_url_fragments['path'] ) ||
-					strpos( $request_url_fragments['path'], ".xsl" ) !== false ) {
+				if (
+					@preg_match( '~(text/xml|text/xsl|application/xhtml\+xml|application/rdf\+xml|application/rss\+xml|application/atom\+xml|application/xml)~i', $content_type ) ||
+					preg_match( W3TC_FEED_REGEXP, $request_url_fragments['path'] ) ||
+					false !== strpos( $request_url_fragments['path'], '.xsl' )
+				) {
 					$key_postfix = '.xml';
 				}
 			}
 		}
 
-		// key compression
+		// key compression.
 		$key_compression = '';
 		if ( $page_key_extension['compression'] ) {
 			$key_compression = '_' . $page_key_extension['compression'];
 		}
 
-		$key = w3tc_apply_filters( 'pagecache_page_key', array(
-				'key' => array(
+		$key = w3tc_apply_filters(
+			'pagecache_page_key',
+			array(
+				'key'                => array(
 					$key_urlpart,
 					$key_extension,
 					$key_postfix,
-					$key_compression
+					$key_compression,
 				),
 				'page_key_extension' => $page_key_extension,
-				'url_fragments' => $this->_request_url_fragments
-			) );
+				'url_fragments'      => $this->_request_url_fragments,
+			)
+		);
 
 		return implode( '', $key['key'] );
 	}
 
+	/**
+	 * Normalizes and modifies the URL part of the page key.
+	 *
+	 * @param string $key               The URL part of the cache key.
+	 * @param array  $page_key_extension An array of page key extensions.
+	 *
+	 * @return string The normalized URL part of the cache key.
+	 */
 	private function _get_page_key_urlpart( $key, $page_key_extension ) {
-		// remove fragments
+		// remove fragments.
 		$key = preg_replace( '~#.*$~', '', $key );
 
-		// host/uri in different cases means the same page in wp
+		// host/uri in different cases means the same page in wp.
 		$key = strtolower( $key );
 
 		if ( empty( $page_key_extension['group'] ) ) {
 			if ( $this->_enhanced_mode || $this->_nginx_memcached ) {
 				$extra = '';
 
-				// URL decode
+				// URL decode.
 				$key = urldecode( $key );
 
-				// replace double slashes
+				// replace double slashes.
 				$key = preg_replace( '~[/\\\]+~', '/', $key );
 
-				// replace index.php
+				// replace index.php.
 				$key = str_replace( '/index.php', '/', $key );
 
-				// remove querystring
+				// remove querystring.
 				$key = preg_replace( '~\?.*$~', '', $key );
 
-				// make sure one slash is at the end
-				if (substr($key, strlen($key) - 1, 1) == '/') {
+				// make sure one slash is at the end.
+				if ( '/' === substr( $key, strlen( $key ) - 1, 1 ) ) {
 					$extra = '_slash';
 				}
+
 				$key = trim( $key, '/' ) . '/';
 
 				if ( $this->_nginx_memcached ) {
@@ -1600,13 +1724,11 @@ private function _get_page_key_urlpart( $key, $page_key_extension ) {
 	}
 
 	/**
-	 * Returns debug info
+	 * Appends debugging information to the footer comment.
 	 *
-	 * @param boolean $cache
-	 * @param string  $reason
-	 * @param boolean $status
-	 * @param double  $time
-	 * @return string
+	 * @param array $strings An array of strings to append debugging information to.
+	 *
+	 * @return array The modified array of footer comment strings.
 	 */
 	public function w3tc_footer_comment( $strings ) {
 		$strings[] = sprintf(
@@ -1617,26 +1739,27 @@ public function w3tc_footer_comment( $strings ) {
 			isset( $this->_page_key_extension['cookie'] ) ? ' ' . $this->_page_key_extension['cookie'] : ''
 		);
 
-
 		if ( $this->_debug ) {
 			$time_total = Util_Debug::microtime() - $this->_time_start;
-			$engine = $this->_config->get_string( 'pgcache.engine' );
-			$strings[] = '';
-			$strings[] = 'Page cache debug info:';
-			$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ), Cache::engine_name( $engine ) );
-			$strings[] = sprintf( "%s%s", str_pad( 'Cache key: ', 20 ), $this->_page_key );
+			$engine     = $this->_config->get_string( 'pgcache.engine' );
+			$strings[]  = '';
+			$strings[]  = 'Page cache debug info:';
+			$strings[]  = sprintf( '%s%s', str_pad( 'Engine: ', 20 ), Cache::engine_name( $engine ) );
+			$strings[]  = sprintf( '%s%s', str_pad( 'Cache key: ', 20 ), $this->_page_key );
 
-			$strings[] = sprintf( "%s%.3fs", str_pad( 'Creation Time: ', 20 ), time() );
+			$strings[] = sprintf( '%s%.3fs', str_pad( 'Creation Time: ', 20 ), time() );
 
 			$headers = $this->_get_response_headers();
 
 			if ( count( $headers['plain'] ) ) {
-				$strings[] = "Header info:";
+				$strings[] = 'Header info:';
 
 				foreach ( $headers['plain'] as $i ) {
-					$strings[] = sprintf( "%s%s",
+					$strings[] = sprintf(
+						'%s%s',
 						str_pad( $i['name'] . ': ', 20 ),
-						Util_Content::escape_comment( $i['value'] ) );
+						Util_Content::escape_comment( $i['value'] )
+					);
 				}
 			}
 
@@ -1647,35 +1770,37 @@ public function w3tc_footer_comment( $strings ) {
 	}
 
 	/**
-	 * Sends headers
+	 * Sends the provided headers.
 	 *
-	 * @param array   $headers
-	 * @return boolean
+	 * @param array $headers An associative array of headers to send.
+	 *
+	 * @return bool True on success, false if headers were already sent.
 	 */
-	function _headers( $headers ) {
-		if ( headers_sent() )
+	public function _headers( $headers ) {
+		if ( headers_sent() ) {
 			return false;
+		}
 
 		$repeating = array();
-		// headers are sent as name->value and array(n=>, v=>)
-		// to support repeating headers
+		// headers are sent as name->value and array(n=>, v=>) to support repeating headers.
 		foreach ( $headers as $name0 => $value0 ) {
 			if ( is_array( $value0 ) && isset( $value0['n'] ) ) {
-				$name = $value0['n'];
+				$name  = $value0['n'];
 				$value = $value0['v'];
 			} else {
-				$name = $name0;
+				$name  = $name0;
 				$value = $value0;
 			}
 
-			if ( $name == 'Status' ) {
+			if ( 'Status' === $name ) {
 				@header( $headers['Status'] );
-			} elseif ( $name == 'Status-Code' ) {
-				if ( function_exists( 'http_response_code' ) )   // php5.3 compatibility)
+			} elseif ( 'Status-Code' === $name ) {
+				if ( function_exists( 'http_response_code' ) ) { // php5.3 compatibility.
 					@http_response_code( $headers['Status-Code'] );
-			} elseif ( !empty( $name ) && !empty( $value ) ) {
-				@header( $name . ': ' . $value, !isset( $repeating[$name] ) );
-				$repeating[$name] = true;
+				}
+			} elseif ( ! empty( $name ) && ! empty( $value ) ) {
+				@header( $name . ': ' . $value, ! isset( $repeating[ $name ] ) );
+				$repeating[ $name ] = true;
 			}
 		}
 
@@ -1683,45 +1808,38 @@ function _headers( $headers ) {
 	}
 
 	/**
-	 * Sends headers
+	 * Sends caching-related headers.
 	 *
-	 * @param boolean $is_404
-	 * @param string  $etag
-	 * @param integer $time
-	 * @param string  $compression
-	 * @param array   $custom_headers
-	 * @return boolean
+	 * @param bool   $is_404         Whether the current request is a 404 error.
+	 * @param int    $time           The cache creation time.
+	 * @param string $etag           The ETag value.
+	 * @param string $compression    The compression method used.
+	 * @param array  $custom_headers Optional. Custom headers to include.
+	 *
+	 * @return void|bool True on success, false if headers were already sent, void if not modified.
 	 */
-	function _send_headers( $is_404, $time, $etag, $compression, $custom_headers = array() ) {
-		$exit = false;
-		$headers = ( is_array( $custom_headers ) ? $custom_headers : array() );
+	public function _send_headers( $is_404, $time, $etag, $compression, $custom_headers = array() ) {
+		$exit      = false;
+		$headers   = ( is_array( $custom_headers ) ? $custom_headers : array() );
 		$curr_time = time();
 
-		$bc_lifetime = $this->_config->get_integer(
-			'browsercache.html.lifetime' );
+		$bc_lifetime = $this->_config->get_integer( 'browsercache.html.lifetime' );
 
 		$expires = ( is_null( $time ) ? $curr_time : $time ) + $bc_lifetime;
 		$max_age = ( $expires > $curr_time ? $expires - $curr_time : 0 );
 
 		if ( $is_404 ) {
-			/**
-			 * Add 404 header
-			 */
+			// Add 404 header.
 			$headers['Status'] = 'HTTP/1.1 404 Not Found';
-		} elseif ( ( !is_null( $time ) && $this->_check_modified_since( $time ) ) || $this->_check_match( $etag ) ) {
-			/**
-			 * Add 304 header
-			 */
+		} elseif ( ( ! is_null( $time ) && $this->_check_modified_since( $time ) ) || $this->_check_match( $etag ) ) {
+			// Add 304 header.
 			$headers['Status'] = 'HTTP/1.1 304 Not Modified';
 
-			/**
-			 * Don't send content if it isn't modified
-			 */
+			// Don't send content if it isn't modified.
 			$exit = true;
 		}
 
 		if ( $this->_config->get_boolean( 'browsercache.enabled' ) ) {
-
 			if ( $this->_config->get_boolean( 'browsercache.html.last_modified' ) ) {
 				$headers['Last-Modified'] = Util_Content::http_date( $time );
 			}
@@ -1732,40 +1850,40 @@ function _send_headers( $is_404, $time, $etag, $compression, $custom_headers = a
 
 			if ( $this->_config->get_boolean( 'browsercache.html.cache.control' ) ) {
 				switch ( $this->_config->get_string( 'browsercache.html.cache.policy' ) ) {
-				case 'cache':
-					$headers['Pragma'] = 'public';
-					$headers['Cache-Control'] = 'public';
-					break;
-
-				case 'cache_public_maxage':
-					$headers['Pragma'] = 'public';
-					$headers['Cache-Control'] = sprintf( 'max-age=%d, public', $max_age );
-					break;
-
-				case 'cache_validation':
-					$headers['Pragma'] = 'public';
-					$headers['Cache-Control'] = 'public, must-revalidate, proxy-revalidate';
-					break;
-
-				case 'cache_noproxy':
-					$headers['Pragma'] = 'public';
-					$headers['Cache-Control'] = 'private, must-revalidate';
-					break;
-
-				case 'cache_maxage':
-					$headers['Pragma'] = 'public';
-					$headers['Cache-Control'] = sprintf( 'max-age=%d, public, must-revalidate, proxy-revalidate', $max_age );
-					break;
-
-				case 'no_cache':
-					$headers['Pragma'] = 'no-cache';
-					$headers['Cache-Control'] = 'private, no-cache';
-					break;
-
-				case 'no_store':
-					$headers['Pragma'] = 'no-store';
-					$headers['Cache-Control'] = 'no-store';
-					break;
+					case 'cache':
+						$headers['Pragma']        = 'public';
+						$headers['Cache-Control'] = 'public';
+						break;
+
+					case 'cache_public_maxage':
+						$headers['Pragma']        = 'public';
+						$headers['Cache-Control'] = sprintf( 'max-age=%d, public', $max_age );
+						break;
+
+					case 'cache_validation':
+						$headers['Pragma']        = 'public';
+						$headers['Cache-Control'] = 'public, must-revalidate, proxy-revalidate';
+						break;
+
+					case 'cache_noproxy':
+						$headers['Pragma']        = 'public';
+						$headers['Cache-Control'] = 'private, must-revalidate';
+						break;
+
+					case 'cache_maxage':
+						$headers['Pragma']        = 'public';
+						$headers['Cache-Control'] = sprintf( 'max-age=%d, public, must-revalidate, proxy-revalidate', $max_age );
+						break;
+
+					case 'no_cache':
+						$headers['Pragma']        = 'no-cache';
+						$headers['Cache-Control'] = 'private, no-cache';
+						break;
+
+					case 'no_store':
+						$headers['Pragma']        = 'no-store';
+						$headers['Cache-Control'] = 'no-store';
+						break;
 				}
 			}
 
@@ -1774,25 +1892,29 @@ function _send_headers( $is_404, $time, $etag, $compression, $custom_headers = a
 			}
 		}
 
+		$headers = array_merge(
+			$headers,
+			$this->_get_common_headers( $compression )
+		);
 
-		$headers = array_merge( $headers,
-			$this->_get_common_headers( $compression ) );
-
-		/**
-		 * Send headers to client
-		 */
+		// Send headers to client.
 		$result = $this->_headers( $headers );
 
-		if ( $exit )
+		if ( $exit ) {
 			exit();
+		}
 
 		return $result;
 	}
 
 	/**
-	 * Returns headers to send regardless is page caching is active
+	 * Retrieves common headers for caching purposes.
+	 *
+	 * @param string|null $compression The compression type to use, if any.
+	 *
+	 * @return array An associative array of headers to include.
 	 */
-	function _get_common_headers( $compression ) {
+	public function _get_common_headers( $compression ) {
 		$headers = array();
 
 		if ( $this->_config->get_boolean( 'browsercache.enabled' ) ) {
@@ -1802,38 +1924,36 @@ function _get_common_headers( $compression ) {
 		}
 
 		$vary = '';
-		//compressed && UAG
+		// compressed && UAG.
 		if ( $compression && $this->_page_key_extension['useragent'] ) {
-			$vary = 'Accept-Encoding,User-Agent,Cookie';
+			$vary                        = 'Accept-Encoding,User-Agent,Cookie';
 			$headers['Content-Encoding'] = $compression;
-			//compressed
+			// compressed.
 		} elseif ( $compression ) {
-			$vary = 'Accept-Encoding';
+			$vary                        = 'Accept-Encoding';
 			$headers['Content-Encoding'] = $compression;
-			//uncompressed && UAG
+			// uncompressed && UAG.
 		} elseif ( $this->_page_key_extension['useragent'] ) {
 			$vary = 'User-Agent,Cookie';
 		}
 
-		//Add Cookie to vary if user logged in and not previously set
-		if ( !$this->_check_logged_in() && strpos( $vary, 'Cookie' ) === false ) {
-			if ( $vary )
+		// Add Cookie to vary if user logged in and not previously set.
+		if ( ! $this->_check_logged_in() && strpos( $vary, 'Cookie' ) === false ) {
+			if ( $vary ) {
 				$vary .= ',Cookie';
-			else
+			} else {
 				$vary = 'Cookie';
+			}
 		}
 
-		/**
-		 * Add vary header
-		 */
-		if ( $vary )
+		// Add vary header.
+		if ( $vary ) {
 			$headers['Vary'] = $vary;
+		}
 
-		/**
-		 * Disable caching for preview mode
-		 */
+		// Disable caching for preview mode.
 		if ( Util_Environment::is_preview_mode() ) {
-			$headers['Pragma'] = 'private';
+			$headers['Pragma']        = 'private';
 			$headers['Cache-Control'] = 'private';
 		}
 
@@ -1841,41 +1961,44 @@ function _get_common_headers( $compression ) {
 	}
 
 	/**
-	 * Check if content was modified by time
+	 * Checks if the request's "If-Modified-Since" header matches the given time.
+	 *
+	 * @param int $time The timestamp to compare against.
 	 *
-	 * @param integer $time
-	 * @return boolean
+	 * @return bool True if the header matches the given time, false otherwise.
 	 */
-	function _check_modified_since( $time ) {
-		if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
-			$if_modified_since = htmlspecialchars( stripslashes( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ); // phpcs:ignore
+	public function _check_modified_since( $time ) {
+		if ( ! empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
+			$if_modified_since = htmlspecialchars( stripslashes( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) );
 
-			// IE has tacked on extra data to this header, strip it
-			if ( ( $semicolon = strrpos( $if_modified_since, ';' ) ) !== false ) {
+			// IE has tacked on extra data to this header, strip it.
+			$semicolon = strrpos( $if_modified_since, ';' );
+			if ( false !== $semicolon ) {
 				$if_modified_since = substr( $if_modified_since, 0, $semicolon );
 			}
 
-			return $time == strtotime( $if_modified_since );
+			return strtotime( $if_modified_since ) === $time;
 		}
 
 		return false;
 	}
 
 	/**
-	 * Check if content was modified by etag
+	 * Checks if the request's "If-None-Match" header matches the given ETag.
+	 *
+	 * @param string $etag The ETag to compare against.
 	 *
-	 * @param string  $etag
-	 * @return boolean
+	 * @return bool True if the ETag matches, false otherwise.
 	 */
-	function _check_match( $etag ) {
-		if ( !empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
+	public function _check_match( $etag ) {
+		if ( ! empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
 			$if_none_match = htmlspecialchars( stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) ); // phpcs:ignore
 			$client_etags  = explode( ',', $if_none_match );
 
 			foreach ( $client_etags as $client_etag ) {
 				$client_etag = trim( $client_etag );
 
-				if ( $etag == $client_etag ) {
+				if ( $etag === $client_etag ) {
 					return true;
 				}
 			}
@@ -1885,46 +2008,63 @@ function _check_match( $etag ) {
 	}
 
 	/**
-	 * Bad Behavior support
+	 * Executes bad behavior protection if configured.
 	 *
 	 * @return void
 	 */
-	function _bad_behavior() {
+	public function _bad_behavior() {
 		$bb_file = $this->_config->get_string( 'pgcache.bad_behavior_path' );
-		if ( $bb_file != '' )
+		if ( '' !== $bb_file ) {
 			require_once $bb_file;
+		}
 	}
 
 	/**
-	 * Parses dynamic tags
+	 * Parses dynamic content within the provided buffer.
+	 *
+	 * @param string $buffer The content buffer to parse.
+	 *
+	 * @return string The buffer with parsed dynamic content.
 	 */
-	function _parse_dynamic( $buffer ) {
-		if ( !defined( 'W3TC_DYNAMIC_SECURITY' ) )
+	public function _parse_dynamic( $buffer ) {
+		if ( ! defined( 'W3TC_DYNAMIC_SECURITY' ) ) {
 			return $buffer;
+		}
 
-		$buffer = preg_replace_callback( '~<!--\s*mfunc\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/mfunc\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis', array(
+		$buffer = preg_replace_callback(
+			'~<!--\s*mfunc\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/mfunc\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis',
+			array(
 				$this,
-				'_parse_dynamic_mfunc'
-			), $buffer );
+				'_parse_dynamic_mfunc',
+			),
+			$buffer
+		);
 
-		$buffer = preg_replace_callback( '~<!--\s*mclude\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/mclude\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis', array(
+		$buffer = preg_replace_callback(
+			'~<!--\s*mclude\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/mclude\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis',
+			array(
 				$this,
-				'_parse_dynamic_mclude'
-			), $buffer );
+				'_parse_dynamic_mclude',
+			),
+			$buffer
+		);
 
 		return $buffer;
 	}
 
 	/**
-	 * Parse dynamic mfunc callback
+	 * Executes a dynamic mfunc tag found in content.
 	 *
-	 * @param array   $matches
-	 * @return string
+	 * phpcs:disable Squiz.PHP.Eval.Discouraged
+	 *
+	 * @param array $matches The matches from the regular expression.
+	 *
+	 * @return string The result of executing the mfunc code.
 	 */
-	function _parse_dynamic_mfunc( $matches ) {
+	public function _parse_dynamic_mfunc( $matches ) {
 		$code1 = trim( $matches[1] );
 		$code2 = trim( $matches[2] );
-		$code = ( $code1 ? $code1 : $code2 );
+		$code  = ( $code1 ? $code1 : $code2 );
 
 		if ( $code ) {
 			$code = trim( $code, ';' ) . ';';
@@ -1938,7 +2078,7 @@ function _parse_dynamic_mfunc( $matches ) {
 				$result = false;
 			}
 
-			if ( $result === false ) {
+			if ( false === $result ) {
 				$output = sprintf( 'Unable to execute code: %s', htmlspecialchars( $code ) );
 			}
 		} else {
@@ -1949,12 +2089,13 @@ function _parse_dynamic_mfunc( $matches ) {
 	}
 
 	/**
-	 * Parse dynamic mclude callback
+	 * Includes a file based on a dynamic mclude tag found in content.
+	 *
+	 * @param array $matches The matches from the regular expression.
 	 *
-	 * @param array   $matches
-	 * @return string
+	 * @return string The content of the included file, or an error message.
 	 */
-	function _parse_dynamic_mclude( $matches ) {
+	public function _parse_dynamic_mclude( $matches ) {
 		$file1 = trim( $matches[1] );
 		$file2 = trim( $matches[2] );
 
@@ -1979,74 +2120,92 @@ function _parse_dynamic_mclude( $matches ) {
 	}
 
 	/**
-	 * Checks if buffer has dynamic tags
+	 * Checks if the buffer contains dynamic tags.
 	 *
-	 * @param string  $buffer
-	 * @return boolean
+	 * @param string $buffer The content buffer to check.
+	 *
+	 * @return bool True if dynamic tags are present, false otherwise.
 	 */
-	function _has_dynamic( $buffer ) {
-		if ( !defined( 'W3TC_DYNAMIC_SECURITY' ) )
+	public function _has_dynamic( $buffer ) {
+		if ( ! defined( 'W3TC_DYNAMIC_SECURITY' ) ) {
 			return false;
+		}
 
-		return preg_match( '~<!--\s*m(func|clude)\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/m(func|clude)\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis', $buffer );
+		return preg_match(
+			'~<!--\s*m(func|clude)\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/m(func|clude)\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis',
+			$buffer
+		);
 	}
 
 	/**
-	 * Check whether requested page has content type that can be cached
+	 * Determines if the content type is cacheable.
 	 *
-	 * @return bool
+	 * @return bool True if the content type is cacheable, false otherwise.
 	 */
 	private function _is_cacheable_content_type() {
 		$content_type = '';
-		$headers = headers_list();
+		$headers      = headers_list();
 		foreach ( $headers as $header ) {
 			$header = strtolower( $header );
-			$m = null;
+			$m      = null;
 			if ( preg_match( '~\s*content-type\s*:([^;]+)~', $header, $m ) ) {
 				$content_type = trim( $m[1] );
 			}
 		}
 
-		$cache_headers = apply_filters( 'w3tc_is_cacheable_content_type',
+		$cache_headers = apply_filters(
+			'w3tc_is_cacheable_content_type',
 			array(
-				'' /* redirects, they have only Location header set */,
-				'application/json', 'text/html', 'text/xml', 'text/xsl',
-				'application/xhtml+xml', 'application/rss+xml',
-				'application/atom+xml', 'application/rdf+xml',
-				'application/xml'
+				'', // redirects, they have only Location header set.
+				'application/json',
+				'text/html',
+				'text/xml',
+				'text/xsl',
+				'application/xhtml+xml',
+				'application/rss+xml',
+				'application/atom+xml',
+				'application/rdf+xml',
+				'application/xml',
 			)
 		);
-		return in_array( $content_type, $cache_headers );
+		return in_array( $content_type, $cache_headers, true );
 	}
 
 	/**
-	 * Fills $_request_url_fragments['path'], $_request_url_fragments['querystring']
-	 * with cache-related normalized values
+	 * Preprocesses the request URI into its components.
+	 *
+	 * @return void
 	 */
 	private function _preprocess_request_uri() {
 		$p = explode( '?', $this->_request_uri, 2 );
 
-		$this->_request_url_fragments['path'] = $p[0];
-		$this->_request_url_fragments['querystring'] =
-			( empty( $p[1] ) ? '' : '?' . $p[1] );
+		$this->_request_url_fragments['path']        = $p[0];
+		$this->_request_url_fragments['querystring'] = ( empty( $p[1] ) ? '' : '?' . $p[1] );
 
-		$this->_request_url_fragments = $this->_normalize_url_fragments(
-			$this->_request_url_fragments );
+		$this->_request_url_fragments = $this->_normalize_url_fragments( $this->_request_url_fragments );
 	}
 
-
-
+	/**
+	 * Normalizes URL fragments.
+	 *
+	 * @param array $fragments The URL fragments to normalize.
+	 *
+	 * @return array The normalized URL fragments.
+	 */
 	private function _normalize_url_fragments( $fragments ) {
-		$fragments = w3tc_apply_filters( 'pagecache_normalize_url_fragments',
-			$fragments );
-		$fragments['querystring'] = $this->_normalize_querystring(
-			$fragments['querystring'] );
+		$fragments                = w3tc_apply_filters( 'pagecache_normalize_url_fragments', $fragments );
+		$fragments['querystring'] = $this->_normalize_querystring( $fragments['querystring'] );
 
 		return $fragments;
 	}
 
-
-
+	/**
+	 * Normalizes the query string in a URL.
+	 *
+	 * @param string $querystring The query string to normalize.
+	 *
+	 * @return string The normalized query string.
+	 */
 	private function _normalize_querystring( $querystring ) {
 		$ignore_qs = $this->_config->get_array( 'pgcache.accept.qs' );
 		$ignore_qs = w3tc_apply_filters( 'pagecache_extract_accept_qs', $ignore_qs );
@@ -2081,19 +2240,21 @@ private function _normalize_querystring( $querystring ) {
 	}
 
 	/**
+	 * Handles delayed cache printing when applicable.
 	 *
+	 * @return void
 	 */
 	public function delayed_cache_print() {
 		if ( $this->_late_caching && $this->_caching ) {
 			$this->_cached_data = $this->_extract_cached_page( true );
 			if ( $this->_cached_data ) {
 				global $w3_late_caching_succeeded;
-				$w3_late_caching_succeeded  = true;
+				$w3_late_caching_succeeded = true;
 
 				$this->process_status = 'hit';
 				$this->process_cached_page_and_exit( $this->_cached_data );
-				// if is passes here - exit is not possible now and
-				// will happen on init
+
+				// if is passes here - exit is not possible now and will happen on init.
 				return;
 			}
 		}
@@ -2101,35 +2262,39 @@ public function delayed_cache_print() {
 		if ( $this->_late_init && $this->_caching ) {
 			$this->process_status = 'hit';
 			$this->process_cached_page_and_exit( $this->_cached_data );
-			// if is passes here - exit is not possible now and
-			// will happen on init
+
+			// if is passes here - exit is not possible now and will happen on init.
 			return;
 		}
 	}
 
+	/**
+	 * Conditionally saves the cached result with optional compression.
+	 *
+	 * @param string $buffer            The content buffer to cache.
+	 * @param array  $response_headers  The response headers to include in the cache.
+	 * @param bool   $has_dynamic       Whether the content includes dynamic tags.
+	 *
+	 * @return string The buffer, possibly modified for compression.
+	 */
 	private function _maybe_save_cached_result( $buffer, $response_headers, $has_dynamic ) {
-		$mobile_group = $this->_page_key_extension['useragent'];
-		$referrer_group = $this->_page_key_extension['referrer'];
-		$encryption = $this->_page_key_extension['encryption'];
-		$compression_header = $this->_page_key_extension['compression'];
+		$mobile_group          = $this->_page_key_extension['useragent'];
+		$referrer_group        = $this->_page_key_extension['referrer'];
+		$encryption            = $this->_page_key_extension['encryption'];
+		$compression_header    = $this->_page_key_extension['compression'];
 		$compressions_to_store = $this->_get_compressions();
 
-		/**
-		 * Don't compress here for debug mode or dynamic tags
-		 * because we need to modify buffer before send it to client
-		 */
+		// Don't compress here for debug mode or dynamic tags because we need to modify buffer before send it to client.
 		if ( $this->_debug || $has_dynamic ) {
 			$compressions_to_store = array( false );
 		}
 
-		// right now dont return compressed buffer if we are dynamic,
-		// that will happen on shutdown after processing dynamic stuff
-		$compression_of_returned_content =
-			( $has_dynamic ? false : $compression_header );
+		// Right now dont return compressed buffer if we are dynamic that will happen on shutdown after processing dynamic stuff.
+		$compression_of_returned_content = ( $has_dynamic ? false : $compression_header );
 
 		$headers = $this->_get_cached_headers( $response_headers['plain'] );
-		if ( !empty( $headers['Status-Code'] ) ) {
-			$is_404 = ( $headers['Status-Code'] == 404 );
+		if ( ! empty( $headers['Status-Code'] ) ) {
+			$is_404 = ( 404 === $headers['Status-Code'] );
 		} elseif ( function_exists( 'is_404' ) ) {
 			$is_404 = is_404();
 		} else {
@@ -2137,15 +2302,19 @@ private function _maybe_save_cached_result( $buffer, $response_headers, $has_dyn
 		}
 
 		if ( $this->_enhanced_mode ) {
-			// redirect issued, if we have some old cache entries
-			// they will be turned into fresh files and catch further requests
+			// Redirect issued, if we have some old cache entries they will be turned into fresh files and catch further requests.
 			if ( isset( $response_headers['kv']['location'] ) ) {
 				$cache = $this->_get_cache( $this->_page_key_extension['group'] );
 
 				foreach ( $compressions_to_store as $_compression ) {
 					$_page_key = $this->_get_page_key(
-						array_merge( $this->_page_key_extension,
-							array( 'compression' => $_compression ) ) );
+						array_merge(
+							$this->_page_key_extension,
+							array(
+								'compression' => $_compression,
+							)
+						)
+					);
 					$cache->hard_delete( $_page_key );
 				}
 
@@ -2154,62 +2323,72 @@ private function _maybe_save_cached_result( $buffer, $response_headers, $has_dyn
 		}
 
 		$content_type = '';
-		if ( $this->_enhanced_mode && !$this->_late_init ) {
-			register_shutdown_function( array(
+		if ( $this->_enhanced_mode && ! $this->_late_init ) {
+			register_shutdown_function(
+				array(
 					$this,
-					'_check_rules_present'
-				) );
+					'_check_rules_present',
+				)
+			);
 
 			if ( isset( $response_headers['kv']['content-type'] ) ) {
 				$content_type = $response_headers['kv']['content-type'];
 			}
 		}
 
-		$time = time();
+		$time  = time();
 		$cache = $this->_get_cache( $this->_page_key_extension['group'] );
 
-		/**
-		 * Store different versions of cache
-		 */
-		$buffers = array();
+		// Store different versions of cache.
+		$buffers           = array();
 		$something_was_set = false;
 
-		do_action( 'w3tc_pagecache_before_set', array(
+		do_action(
+			'w3tc_pagecache_before_set',
+			array(
 				'request_url_fragments' => $this->_request_url_fragments,
-				'page_key_extension' => $this->_page_key_extension
-			) );
+				'page_key_extension'    => $this->_page_key_extension,
+			)
+		);
 
 		foreach ( $compressions_to_store as $_compression ) {
 			$this->_set_extract_page_key(
-				array_merge( $this->_page_key_extension, [
-						'compression' => $_compression,
-						'content_type' => $content_type
-					] ),
-				true );
+				array_merge(
+					$this->_page_key_extension,
+					array(
+						'compression'  => $_compression,
+						'content_type' => $content_type,
+					)
+				),
+				true
+			);
+
 			if ( empty( $this->_page_key ) ) {
 				continue;
 			}
 
-			// Compress content
-			$buffers[$_compression] = $this->_compress( $buffer, $_compression );
+			// Compress content.
+			$buffers[ $_compression ] = $this->_compress( $buffer, $_compression );
 
-			// Store cache data
+			// Store cache data.
 			$_data = array(
-				'404' => $is_404,
+				'404'     => $is_404,
 				'headers' => $headers,
-				'time' => $time,
-				'content' => $buffers[$_compression]
+				'time'    => $time,
+				'content' => $buffers[ $_compression ],
 			);
-			if ( !empty( $_compression ) ) {
+
+			if ( ! empty( $_compression ) ) {
 				$_data['c'] = $_compression;
 			}
-			if ( $has_dynamic )
+
+			if ( $has_dynamic ) {
 				$_data['has_dynamic'] = true;
+			}
 
-			$_data = apply_filters( 'w3tc_pagecache_set', $_data, $this->_page_key,
-				$this->_page_group );
+			$_data = apply_filters( 'w3tc_pagecache_set', $_data, $this->_page_key, $this->_page_group );
 
-			if ( !empty( $_data ) ) {
+			if ( ! empty( $_data ) ) {
 				$cache->set( $this->_page_key, $_data, $this->_lifetime, $this->_page_group );
 				$something_was_set = true;
 			}
@@ -2221,52 +2400,63 @@ private function _maybe_save_cached_result( $buffer, $response_headers, $has_dyn
 			$this->process_status = 'miss_third_party';
 		}
 
-		// Change buffer if using compression
+		// Change buffer if using compression.
 		if ( defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) ) {
 			$compression_header = false;
 		} elseif ( $compression_of_returned_content &&
-			isset( $buffers[$compression_of_returned_content] ) ) {
-			$buffer = $buffers[$compression_of_returned_content];
+			isset( $buffers[ $compression_of_returned_content ] ) ) {
+			$buffer = $buffers[ $compression_of_returned_content ];
 		}
 
-		// Calculate content etag
+		// Calculate content etag.
 		$etag = md5( $buffer );
 
-		// Send headers
-		$this->_send_headers( $is_404, $time, $etag, $compression_header,
-			$headers );
+		// Send headers.
+		$this->_send_headers( $is_404, $time, $etag, $compression_header, $headers );
+
 		return $buffer;
 	}
 
+	/**
+	 * Collects usage statistics for the current request.
+	 *
+	 * @param object $storage The storage object for saving statistics.
+	 *
+	 * @return void
+	 */
 	public function w3tc_usage_statistics_of_request( $storage ) {
 		global $w3tc_start_microtime;
+
 		$time_ms = 0;
-		if ( !empty( $w3tc_start_microtime ) ) {
-			$time_ms = (int)( ( microtime( true ) - $w3tc_start_microtime ) * 1000 );
-			$storage->counter_add( 'pagecache_requests_time_10ms', (int)( $time_ms / 10 ) );
+		if ( ! empty( $w3tc_start_microtime ) ) {
+			$time_ms = (int) ( ( microtime( true ) - $w3tc_start_microtime ) * 1000 );
+			$storage->counter_add( 'pagecache_requests_time_10ms', (int) ( $time_ms / 10 ) );
 		}
 
-		if ( !empty( $this->process_status ) ) {
-			// see registered keys in PgCache_Plugin.w3tc_usage_statistics_metrics
+		if ( ! empty( $this->process_status ) ) {
+			// see registered keys in PgCache_Plugin.w3tc_usage_statistics_metrics.
 			$storage->counter_add( 'php_requests_pagecache_' . $this->process_status, 1 );
 
 			if ( $this->_debug ) {
-				self::log( 'finished in ' . $time_ms .
-					' size ' . $this->output_size .
-					' with process status ' .
-					$this->process_status .
-					' reason ' . $this->cache_reject_reason);
+				self::log(
+					'finished in ' . $time_ms . ' size ' . $this->output_size . ' with process status ' .
+						$this->process_status . ' reason ' . $this->cache_reject_reason
+				);
 			}
 		}
 	}
 
 	/**
-	 * Log.
+	 * Logs a message to the page cache log.
+	 *
+	 * @param string $msg The message to log.
+	 *
+	 * @return bool|int The number of bytes written, or false on failure.
 	 */
-	static protected function log( $msg ) {
+	protected static function log( $msg ) {
 		$data = sprintf(
 			'[%1$s] [%2$s] [%3$s] %4$s ' . "\n",
-			date( 'r' ),
+			gmdate( 'r' ),
 			isset( $_SERVER['REQUEST_URI'] ) ? filter_var( stripslashes( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '',
 			! empty( $_SERVER['HTTP_REFERER'] ) ? htmlspecialchars( $_SERVER['HTTP_REFERER'] ) : '-',
 			$msg
diff --git a/PgCache_Environment.php b/PgCache_Environment.php
index aa8249f1d..2caf28000 100644
--- a/PgCache_Environment.php
+++ b/PgCache_Environment.php
@@ -1,17 +1,29 @@
 <?php
+/**
+ * File: PgCache_Environment.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * class PgCache_Environment
+ * Class PgCache_Environment
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
+ * phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
  */
 class PgCache_Environment {
 	/**
-	 * Fixes environment in each wp-admin request
+	 * Fixes environment settings on WP admin request.
 	 *
-	 * @param Config $config           Config.
-	 * @param bool   $force_all_checks Force checks flag.
+	 * @param object $config         Configuration object containing environment settings.
+	 * @param bool   $force_all_checks Whether to force all checks regardless of current configuration.
 	 *
-	 * @throws Util_Environment_Exceptions Excpetions.
+	 * @return void
+	 *
+	 * @throws \Util_Environment_Exceptions If there are unresolved exceptions during the fixing process.
 	 */
 	public function fix_on_wpadmin_request( $config, $force_all_checks ) {
 		$exs             = new Util_Environment_Exceptions();
@@ -59,13 +71,13 @@ public function fix_on_wpadmin_request( $config, $force_all_checks ) {
 	}
 
 	/**
-	 * Fixes environment once event occurs
+	 * Adjusts settings based on a specific event.
 	 *
-	 * @param Config      $config     Config.
-	 * @param string      $event      Event.
-	 * @param null|Config $old_config Old Config.
+	 * @param object      $config     Configuration object with settings.
+	 * @param string      $event      The name of the event triggering the adjustment.
+	 * @param object|null $old_config Optional. Previous configuration object for comparison.
 	 *
-	 * @throws Util_Environment_Exceptions Exception.
+	 * @return void
 	 */
 	public function fix_on_event( $config, $event, $old_config = null ) {
 		$pgcache_enabled = $config->get_boolean( 'pgcache.enabled' );
@@ -105,11 +117,11 @@ public function fix_on_event( $config, $event, $old_config = null ) {
 	}
 
 	/**
-	 * Fixes environment after plugin deactivation
-	 *
-	 * @throws Util_Environment_Exceptions Exception.
+	 * Fixes the environment after plugin deactivation.
 	 *
 	 * @return void
+	 *
+	 * @throws \Util_Environment_Exceptions If exceptions occur during cleanup.
 	 */
 	public function fix_after_deactivation() {
 		$exs = new Util_Environment_Exceptions();
@@ -133,133 +145,135 @@ public function fix_after_deactivation() {
 	}
 
 	/**
-	 * Are rewrite rules required?.
+	 * Determines if rules are required for the configuration.
 	 *
 	 * @since 0.9.7.3
 	 *
-	 * @param  Config $c Configuration.
-	 * @return bool
+	 * @param object $c Configuration object.
+	 *
+	 * @return bool True if rules are required, false otherwise.
 	 */
 	private function is_rules_required( $c ) {
 		$e = $c->get_string( 'pgcache.engine' );
 
-		return $c->get_boolean( 'pgcache.enabled' ) &&
-			( 'file_generic' === $e || 'nginx_memcached' === $e );
+		return $c->get_boolean( 'pgcache.enabled' ) && ( 'file_generic' === $e || 'nginx_memcached' === $e );
 	}
 
 	/**
-	 * Returns required rules for module
+	 * Retrieves the required rules for the environment.
+	 *
+	 * @param object $config Configuration object.
 	 *
-	 * @param Config  $config
-	 * @return array
+	 * @return array|null Array of required rules or null if none are required.
 	 */
 	public function get_required_rules( $config ) {
-		if ( !$this->is_rules_required( $config ) ) {
+		if ( ! $this->is_rules_required( $config ) ) {
 			return null;
 		}
 
-		$rewrite_rules = array();
+		$rewrite_rules           = array();
 		$pgcache_rules_core_path = Util_Rule::get_pgcache_rules_core_path();
-		$rewrite_rules[] = array(
+		$rewrite_rules[]         = array(
 			'filename' => $pgcache_rules_core_path,
-			'content' => $this->rules_core_generate( $config ),
-			'priority' => 1000
+			'content'  => $this->rules_core_generate( $config ),
+			'priority' => 1000,
 		);
 
 		$pgcache_rules_cache_path = Util_Rule::get_pgcache_rules_cache_path();
-		$rewrite_rules[] = array(
+		$rewrite_rules[]          = array(
 			'filename' => $pgcache_rules_cache_path,
-			'content' => $this->rules_cache_generate( $config )
+			'content'  => $this->rules_cache_generate( $config ),
 		);
 
 		return $rewrite_rules;
 	}
 
-
-
 	/**
-	 * Fixes folders
+	 * Ensures folders meet the required settings for caching.
+	 *
+	 * @param object $config Configuration object.
+	 * @param object $exs    Exception handler object.
 	 *
-	 * @param Config  $config
-	 * @param Util_Environment_Exceptions $exs
+	 * @return void
 	 */
 	private function fix_folders( $config, $exs ) {
-		if ( !$config->get_boolean( 'pgcache.enabled' ) )
+		if ( ! $config->get_boolean( 'pgcache.enabled' ) ) {
 			return;
+		}
 
-		// folder that we delete if exists and not writeable
-		if ( $config->get_string( 'pgcache.engine' ) == 'file_generic' )
+		// folder that we delete if exists and not writeable.
+		if ( 'file_generic' === $config->get_string( 'pgcache.engine' ) ) {
 			$dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
-		else if ( $config->get_string( 'pgcache.engine' ) != 'file' )
-				$dir = W3TC_CACHE_DIR . '/page';
-			else
-				return;
+		} elseif ( 'file' !== $config->get_string( 'pgcache.engine' ) ) {
+			$dir = W3TC_CACHE_DIR . '/page';
+		} else {
+			return;
+		}
 
-			try{
-			if ( file_exists( $dir ) && !is_writeable( $dir ) )
+		try {
+			if ( file_exists( $dir ) && ! is_writeable( $dir ) ) {
 				Util_WpFile::delete_folder( $dir, '', isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '' );
+			}
 		} catch ( Util_WpFile_FilesystemRmdirException $ex ) {
 			$exs->push( $ex );
 		}
 	}
 
 	/**
-	 * Checks if mode can be used
+	 * Verifies compatibility for file-based generic caching.
+	 *
+	 * @return void
+	 *
+	 * @throws \Util_Environment_Exception If the permalink structure is incompatible.
 	 */
 	private function verify_file_generic_compatibility() {
 		$permalink_structure = get_option( 'permalink_structure' );
 
-		if ( $permalink_structure == '' ) {
-			throw new Util_Environment_Exception( 'Disk Enhanced mode ' .
-				'can\'t work with "Default" permalinks structure' );
+		if ( '' === $permalink_structure ) {
+			throw new Util_Environment_Exception( 'Disk Enhanced mode can\'t work with "Default" permalinks structure' );
 		}
 	}
 
 	/**
-	 * Fixes environment for enabled pgcache
+	 * Validates the functionality of file-based rewrite rules.
+	 *
+	 * @return void
 	 *
-	 * @throws Util_Environment_Exceptions
+	 * @throws \Util_Environment_Exception If rewrite rules are not functioning as expected.
 	 */
 	private function verify_file_generic_rewrite_working() {
-		$url = get_home_url() . '/w3tc_rewrite_test' . rand();
-		if ( !$this->test_rewrite( $url ) ) {
-			$key = sprintf( 'w3tc_rewrite_test_result_%s', substr( md5( $url ), 0, 16 ) );
+		$url = get_home_url() . '/w3tc_rewrite_test' . wp_rand();
+		if ( ! $this->test_rewrite( $url ) ) {
+			$key    = sprintf( 'w3tc_rewrite_test_result_%s', substr( md5( $url ), 0, 16 ) );
 			$result = get_transient( $key );
 
 			$home_url = get_home_url();
 
 			$tech_message =
 				( Util_Environment::is_nginx() ? 'nginx configuration file' : '.htaccess file' ) .
-				' contains rules to rewrite url ' .
-				$home_url . '/w3tc_rewrite_test into ' .
-				$home_url . '/?w3tc_rewrite_test which, if handled by ' .
-				'plugin, return "OK" message.<br/>';
-			$tech_message .= 'The plugin made a request to ' .
-				$home_url . '/w3tc_rewrite_test but received: <br />' .
-				$result . '<br />';
-			$tech_message .= 'instead of "OK" response. <br />';
-
-			$error = '<strong>W3 Total Cache error:</strong> ' .
-				'It appears Page Cache ' .
-				'<acronym title="Uniform Resource Locator">URL</acronym> ' .
-				'rewriting is not working. ';
+				' contains rules to rewrite url ' . $home_url . '/w3tc_rewrite_test into ' .
+				$home_url . '/?w3tc_rewrite_test which, if handled by plugin, return "OK" message.<br/>' .
+				'The plugin made a request to ' . $home_url . '/w3tc_rewrite_test but received: <br />' .
+				$result . '<br />instead of "OK" response. <br />';
+
+			$error = '<strong>W3 Total Cache error:</strong> It appears Page Cache ' .
+				'<acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. ';
+
 			if ( Util_Environment::is_preview_mode() ) {
-				$error .= ' This could be due to using Preview mode. <a href="' . $url . '">Click here</a> to manually verify its working. It should say OK. <br />';
+				$error .= ' This could be due to using Preview mode. <a href="' . $url .
+					'">Click here</a> to manually verify its working. It should say OK. <br />';
 			}
 
 			if ( Util_Environment::is_nginx() ) {
 				$error .= 'Please verify that all configuration files are ' .
-					'included in the configuration file ' .
-					'(and that you have reloaded / restarted nginx).';
+					'included in the configuration file (and that you have reloaded / restarted nginx).';
 			} else {
-				$error .= 'Please verify that the server configuration ' .
-					'allows .htaccess';
+				$error .= 'Please verify that the server configuration allows .htaccess';
 			}
 
 			$error .= '<br />Unfortunately disk enhanced page caching will ' .
 				'not function without custom rewrite rules. ' .
-				'Please ask your server administrator for assistance. ' .
-				'Also refer to <a href="' .
+				'Please ask your server administrator for assistance. Also refer to <a href="' .
 				admin_url( 'admin.php?page=w3tc_install' ) .
 				'">the install page</a>  for the rules for your server.';
 
@@ -268,36 +282,43 @@ private function verify_file_generic_rewrite_working() {
 	}
 
 	/**
-	 * Perform rewrite test
+	 * Tests the rewrite rule functionality.
 	 *
-	 * @param string  $url
-	 * @return boolean
+	 * @param string $url URL to test.
+	 *
+	 * @return bool True if the rewrite works, false otherwise.
 	 */
 	private function test_rewrite( $url ) {
-		$key = sprintf( 'w3tc_rewrite_test_%s', substr( md5( $url ), 0, 16 ) );
+		$key    = sprintf( 'w3tc_rewrite_test_%s', substr( md5( $url ), 0, 16 ) );
 		$result = get_transient( $key );
 
-		if ( $result === false ) {
+		if ( false === $result ) {
 
 			$response = Util_Http::get( $url );
 
-			$result = ( !is_wp_error( $response ) && $response['response']['code'] == 200 && trim( $response['body'] ) == 'OK' );
+			$result = (
+				! is_wp_error( $response ) &&
+				200 === $response['response']['code'] &&
+				'OK' === trim( $response['body'] )
+			);
 
 			if ( $result ) {
 				set_transient( $key, $result, 30 );
 			} else {
 				$key_result = sprintf( 'w3tc_rewrite_test_result_%s', substr( md5( $url ), 0, 16 ) );
-				set_transient( $key_result, is_wp_error( $response )? $response->get_error_message(): implode( ' ', $response['response'] ), 30 );
+				set_transient(
+					$key_result,
+					is_wp_error( $response ) ? $response->get_error_message() : implode( ' ', $response['response'] ),
+					30
+				);
 			}
 		}
 
 		return $result;
 	}
 
-
-
 	/**
-	 * Remove Garbage collection cron job.
+	 * Unschedules the garbage collection task.
 	 *
 	 * @return void
 	 */
@@ -308,7 +329,7 @@ private function unschedule_gc() {
 	}
 
 	/**
-	 * Remove Prime Cache cron job.
+	 * Unschedules the page cache priming task.
 	 *
 	 * @return void
 	 */
@@ -319,7 +340,7 @@ private function unschedule_prime() {
 	}
 
 	/**
-	 * Remove cron job for pagecache purge.
+	 * Unschedules the purge WP Cron task.
 	 *
 	 * @since 2.8.0
 	 *
@@ -331,203 +352,213 @@ private function unschedule_purge_wpcron() {
 		}
 	}
 
-	/*
-	 * wp-config modification
-	 */
-
 	/**
-	 * Enables WP_CACHE
+	 * Adds required directives to the wp-config.php file.
 	 *
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @return void
+	 *
+	 * @throws \Util_WpFile_FilesystemModifyException If modifications to the file fail.
 	 */
 	private function wp_config_add_directive() {
 		$config_path = Util_Environment::wp_config_path();
 
 		$config_data = @file_get_contents( $config_path );
-		if ( $config_data === false )
+		if ( false === $config_data ) {
 			return;
+		}
 
 		$new_config_data = $this->wp_config_remove_from_content( $config_data );
 		$new_config_data = preg_replace(
 			'~<\?(php)?~',
 			"\\0\r\n" . $this->wp_config_addon(),
 			$new_config_data,
-			1 );
+			1
+		);
 
-		if ( $new_config_data != $config_data ) {
+		if ( $new_config_data !== $config_data ) {
 			try {
 				Util_WpFile::write_to_file( $config_path, $new_config_data );
 			} catch ( Util_WpFile_FilesystemOperationException $ex ) {
 				throw new Util_WpFile_FilesystemModifyException(
-					$ex->getMessage(), $ex->credentials_form(),
-					'Edit file <strong>' . $config_path .
-					'</strong> and add next lines:', $config_path,
-					$this->wp_config_addon() );
+					$ex->getMessage(),
+					$ex->credentials_form(),
+					'Edit file <strong>' . $config_path . '</strong> and add next lines:',
+					$config_path,
+					$this->wp_config_addon()
+				);
 			}
 		}
 		// that file was in opcache for sure and it may take time to
-		// start execution of new modified now version
+		// start execution of new modified now version.
 		$o = Dispatcher::component( 'SystemOpCache_Core' );
 		$o->flush();
 	}
 
 	/**
-	 * Disables WP_CACHE
+	 * Removes added directives from the wp-config.php file.
+	 *
+	 * @return void
 	 *
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @throws \Util_WpFile_FilesystemModifyException If modifications to the file fail.
 	 */
 	private function wp_config_remove_directive() {
 		$config_path = Util_Environment::wp_config_path();
 
 		$config_data = @file_get_contents( $config_path );
-		if ( $config_data === false )
+		if ( false === $config_data ) {
 			return;
+		}
 
 		$new_config_data = $this->wp_config_remove_from_content( $config_data );
-		if ( $new_config_data != $config_data ) {
+		if ( $new_config_data !== $config_data ) {
 			try {
 				Util_WpFile::write_to_file( $config_path, $new_config_data );
 			} catch ( Util_WpFile_FilesystemOperationException $ex ) {
 				throw new Util_WpFile_FilesystemModifyException(
-					$ex->getMessage(), $ex->credentials_form(),
-					'Edit file <strong>' . $config_path .
-					'</strong> and remove next lines:',
-					$config_path,  $this->wp_config_addon() );
+					$ex->getMessage(),
+					$ex->credentials_form(),
+					'Edit file <strong>' . $config_path . '</strong> and remove next lines:',
+					$config_path,
+					$this->wp_config_addon()
+				);
 			}
 		}
 	}
 
 	/**
-	 * Returns string Addon required for plugin in wp-config
+	 * Generates the addon directive content for wp-config.php.
+	 *
+	 * @return string The directive content.
 	 */
 	private function wp_config_addon() {
-		return "/** Enable W3 Total Cache */\r\n" .
-			"define('WP_CACHE', true); // Added by W3 Total Cache\r\n";
+		return "/** Enable W3 Total Cache */\r\ndefine('WP_CACHE', true); // Added by W3 Total Cache\r\n";
 	}
 
 	/**
-	 * Disables WP_CACHE
+	 * Removes W3TC directives from wp-config.php content.
+	 *
+	 * @param string $config_data The content of wp-config.php.
 	 *
-	 * @param string  $config_data wp-config.php content
-	 * @return string
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @return string Modified content without W3TC directives.
 	 */
 	private function wp_config_remove_from_content( $config_data ) {
 		$config_data = preg_replace(
 			"~\\/\\*\\* Enable W3 Total Cache \\*\\*?\\/.*?\\/\\/ Added by W3 Total Cache(\r\n)*~s",
-			'', $config_data );
+			'',
+			$config_data
+		);
+
 		$config_data = preg_replace(
 			"~(\\/\\/\\s*)?define\\s*\\(\\s*['\"]?WP_CACHE['\"]?\\s*,.*?\\)\\s*;+\\r?\\n?~is",
-			'', $config_data );
+			'',
+			$config_data
+		);
 
 		return $config_data;
 	}
 
-
-
-	/**
-	 * rules core modification
-	 */
-
 	/**
-	 * Writes directives to WP .htaccess / nginx.conf
-	 * returns true if modifications has been made
+	 * Adds core rules to the configuration.
+	 *
+	 * @param object $config Configuration object.
+	 * @param object $exs    Exception handler object.
+	 *
+	 * @return void
 	 */
 	private function rules_core_add( $config, $exs ) {
-		Util_Rule::add_rules( $exs, Util_Rule::get_pgcache_rules_core_path(),
+		Util_Rule::add_rules(
+			$exs,
+			Util_Rule::get_pgcache_rules_core_path(),
 			$this->rules_core_generate( $config ),
 			W3TC_MARKER_BEGIN_PGCACHE_CORE,
 			W3TC_MARKER_END_PGCACHE_CORE,
 			array(
-				W3TC_MARKER_BEGIN_WORDPRESS => 0,
-				W3TC_MARKER_END_MINIFY_CORE =>
-					strlen( W3TC_MARKER_END_MINIFY_CORE ) + 1,
-				W3TC_MARKER_END_BROWSERCACHE_CACHE =>
-					strlen( W3TC_MARKER_END_BROWSERCACHE_CACHE ) + 1,
-				W3TC_MARKER_END_PGCACHE_CACHE =>
-					strlen( W3TC_MARKER_END_PGCACHE_CACHE ) + 1,
-				W3TC_MARKER_END_MINIFY_CACHE =>
-					strlen( W3TC_MARKER_END_MINIFY_CACHE ) + 1
+				W3TC_MARKER_BEGIN_WORDPRESS        => 0,
+				W3TC_MARKER_END_MINIFY_CORE        => strlen( W3TC_MARKER_END_MINIFY_CORE ) + 1,
+				W3TC_MARKER_END_BROWSERCACHE_CACHE => strlen( W3TC_MARKER_END_BROWSERCACHE_CACHE ) + 1,
+				W3TC_MARKER_END_PGCACHE_CACHE      => strlen( W3TC_MARKER_END_PGCACHE_CACHE ) + 1,
+				W3TC_MARKER_END_MINIFY_CACHE       => strlen( W3TC_MARKER_END_MINIFY_CACHE ) + 1,
 			),
 			true
 		);
 	}
 
 	/**
-	 * Removes Page Cache core directives
+	 * Removes core rules from the configuration.
 	 *
-	 * @param Util_Environment_Exceptions $exs
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @param object $exs Exception handler object.
+	 *
+	 * @return void
 	 */
 	private function rules_core_remove( $exs ) {
-		Util_Rule::remove_rules( $exs, Util_Rule::get_pgcache_rules_core_path(),
+		Util_Rule::remove_rules(
+			$exs,
+			Util_Rule::get_pgcache_rules_core_path(),
 			W3TC_MARKER_BEGIN_PGCACHE_CORE,
 			W3TC_MARKER_END_PGCACHE_CORE
 		);
 	}
 
 	/**
-	 * Generates rules for WP dir
+	 * Generates the core rules based on the server environment.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @param object $config Configuration object.
+	 *
+	 * @return string Generated rules as a string.
 	 */
 	private function rules_core_generate( $config ) {
 		switch ( true ) {
-		case Util_Environment::is_apache():
-		case Util_Environment::is_litespeed():
-			return $this->rules_core_generate_apache( $config );
+			case Util_Environment::is_apache():
+			case Util_Environment::is_litespeed():
+				return $this->rules_core_generate_apache( $config );
 
-		case Util_Environment::is_nginx():
-			return $this->rules_core_generate_nginx( $config );
+			case Util_Environment::is_nginx():
+				return $this->rules_core_generate_nginx( $config );
 		}
 
 		return '';
 	}
 
 	/**
-	 * Generates rules for WP dir
+	 * Generates Apache rewrite rules for page caching.
+	 *
+	 * @param \W3TC\Config $config Configuration object containing various settings for the cache.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string The generated Apache rewrite rules.
 	 */
 	private function rules_core_generate_apache( $config ) {
-		$rewrite_base = Util_Environment::network_home_url_uri();
-		$cache_dir = Util_Environment::normalize_path( W3TC_CACHE_PAGE_ENHANCED_DIR );
+		$rewrite_base        = Util_Environment::network_home_url_uri();
+		$cache_dir           = Util_Environment::normalize_path( W3TC_CACHE_PAGE_ENHANCED_DIR );
 		$permalink_structure = get_option( 'permalink_structure' );
 
 		$current_user = wp_get_current_user();
 
-		/**
-		 * Auto reject cookies
-		 */
+		// Auto reject cookies.
 		$reject_cookies = array(
 			'comment_author',
-			'wp-postpass'
+			'wp-postpass',
 		);
 
 		$reject_cookies[] = 'w3tc_logged_out';
 
-		/**
-		 * Reject cache for logged in users
-		 * OR
-		 * Reject cache for roles if any
-		 */
+		// Reject cache for logged in users OR Reject cache for roles if any.
 		if ( $config->get_boolean( 'pgcache.reject.logged' ) ) {
-			$reject_cookies = array_merge( $reject_cookies, array(
-					'wordpress_logged_in'
-				) );
+			$reject_cookies = array_merge(
+				$reject_cookies,
+				array(
+					'wordpress_logged_in',
+				)
+			);
 		} elseif ( $config->get_boolean( 'pgcache.reject.logged_roles' ) ) {
 			$new_cookies = array();
 			foreach ( $config->get_array( 'pgcache.reject.roles' ) as $role ) {
 				$new_cookies[] = 'w3tc_logged_' . md5( NONCE_KEY . $role );
 			}
+
 			$reject_cookies = array_merge( $reject_cookies, $new_cookies );
 		}
 
-		/**
-		 * Custom config
-		 */
+		// Custom config.
 		$reject_cookies = array_merge( $reject_cookies, $config->get_array( 'pgcache.reject.cookie' ) );
 		Util_Rule::array_trim( $reject_cookies );
 
@@ -538,36 +569,31 @@ private function rules_core_generate_apache( $config ) {
 
 		Util_Rule::array_trim( $reject_user_agents );
 
-		/**
-		 * Generate directives
-		 */
-		$env_W3TC_UA = '';
-		$env_W3TC_REF = '';
+		// Generate directives.
+		$env_W3TC_UA     = '';
+		$env_W3TC_REF    = '';
 		$env_W3TC_COOKIE = '';
-		$env_W3TC_SSL = '';
-		$env_W3TC_ENC = '';
+		$env_W3TC_SSL    = '';
+		$env_W3TC_ENC    = '';
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_PGCACHE_CORE . "\n";
 		$rules .= "<IfModule mod_rewrite.c>\n";
 		$rules .= "    RewriteEngine On\n";
-		$rules .= "    RewriteBase " . $rewrite_base . "\n";
-
+		$rules .= '    RewriteBase ' . $rewrite_base . "\n";
 
 		if ( $config->get_boolean( 'pgcache.debug' ) ) {
 			$rules .= "    RewriteRule ^(.*\\/)?w3tc_rewrite_test([0-9]+)/?$ $1?w3tc_rewrite_test=1 [L]\n";
 		}
 
-
-		/**
-		 * Set accept query strings
-		 */
+		// Set accept query strings.
 		$w3tc_query_strings = apply_filters(
 			'w3tc_pagecache_rules_apache_accept_qs',
-			$config->get_array( 'pgcache.accept.qs' ) );
+			$config->get_array( 'pgcache.accept.qs' )
+		);
 		Util_Rule::array_trim( $w3tc_query_strings );
 
-		if ( !empty( $w3tc_query_strings ) ) {
+		if ( ! empty( $w3tc_query_strings ) ) {
 			$w3tc_query_strings = str_replace( ' ', '+', $w3tc_query_strings );
 			$w3tc_query_strings = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $w3tc_query_strings );
 
@@ -575,7 +601,7 @@ private function rules_core_generate_apache( $config ) {
 
 			foreach ( $w3tc_query_strings as $query ) {
 				$query_rules = array();
-				if  ( strpos( $query, '=' ) === false ) {
+				if ( strpos( $query, '=' ) === false ) {
 					$query_rules[] = 'RewriteCond %{ENV:W3TC_QUERY_STRING} ^(.*?&|)' .
 						$query . '(=[^&]*)?(&.*|)$ [NC]';
 					$query_rules[] = 'RewriteRule ^ - [E=W3TC_QUERY_STRING:%1%3]';
@@ -587,7 +613,10 @@ private function rules_core_generate_apache( $config ) {
 
 				$query_rules = apply_filters(
 					'w3tc_pagecache_rules_apache_accept_qs_rules',
-					$query_rules, $query );
+					$query_rules,
+					$query
+				);
+
 				$rules .= '    ' . implode( "\n    ", $query_rules ) . "\n";
 			}
 
@@ -595,177 +624,170 @@ private function rules_core_generate_apache( $config ) {
 			$rules .= "    RewriteRule ^ - [E=W3TC_QUERY_STRING]\n";
 		}
 
-		/**
-		 * Check for mobile redirect
-		 */
+		// Check for mobile redirect.
 		if ( $config->get_boolean( 'mobile.enabled' ) ) {
 			$mobile_groups = $config->get_array( 'mobile.rgroups' );
 
 			foreach ( $mobile_groups as $mobile_group => $mobile_config ) {
-				$mobile_enabled = ( isset( $mobile_config['enabled'] ) ? (boolean) $mobile_config['enabled'] : false );
-				$mobile_agents = ( isset( $mobile_config['agents'] ) ? (array) $mobile_config['agents'] : '' );
+				$mobile_enabled  = ( isset( $mobile_config['enabled'] ) ? (bool) $mobile_config['enabled'] : false );
+				$mobile_agents   = ( isset( $mobile_config['agents'] ) ? (array) $mobile_config['agents'] : '' );
 				$mobile_redirect = ( isset( $mobile_config['redirect'] ) ? $mobile_config['redirect'] : '' );
 
 				if ( $mobile_enabled && count( $mobile_agents ) && $mobile_redirect ) {
-					$rules .= "    RewriteCond %{HTTP_USER_AGENT} (" . implode( '|', $mobile_agents ) . ") [NC]\n";
-					$rules .= "    RewriteRule .* " . $mobile_redirect . " [R,L]\n";
+					$rules .= '    RewriteCond %{HTTP_USER_AGENT} (' . implode( '|', $mobile_agents ) . ") [NC]\n";
+					$rules .= '    RewriteRule .* ' . $mobile_redirect . " [R,L]\n";
 				}
 			}
 		}
 
-		/**
-		 * Check for referrer redirect
-		 */
+		// Check for referrer redirect.
 		if ( $config->get_boolean( 'referrer.enabled' ) ) {
 			$referrer_groups = $config->get_array( 'referrer.rgroups' );
 
 			foreach ( $referrer_groups as $referrer_group => $referrer_config ) {
-				$referrer_enabled = ( isset( $referrer_config['enabled'] ) ? (boolean) $referrer_config['enabled'] : false );
+				$referrer_enabled   = ( isset( $referrer_config['enabled'] ) ? (bool) $referrer_config['enabled'] : false );
 				$referrer_referrers = ( isset( $referrer_config['referrers'] ) ? (array) $referrer_config['referrers'] : '' );
-				$referrer_redirect = ( isset( $referrer_config['redirect'] ) ? $referrer_config['redirect'] : '' );
+				$referrer_redirect  = ( isset( $referrer_config['redirect'] ) ? $referrer_config['redirect'] : '' );
 
 				if ( $referrer_enabled && count( $referrer_referrers ) && $referrer_redirect ) {
-					$rules .= "    RewriteCond %{HTTP_COOKIE} w3tc_referrer=.*(" . implode( '|', $referrer_referrers ) . ") [NC]\n";
-					$rules .= "    RewriteRule .* " . $referrer_redirect . " [R,L]\n";
+					$rules .= '    RewriteCond %{HTTP_COOKIE} w3tc_referrer=.*(' . implode( '|', $referrer_referrers ) . ") [NC]\n";
+					$rules .= '    RewriteRule .* ' . $referrer_redirect . " [R,L]\n";
 				}
 			}
 		}
 
-		/**
-		 * Set mobile groups
-		 */
+		// Set mobile groups.
 		if ( $config->get_boolean( 'mobile.enabled' ) ) {
 			$mobile_groups = array_reverse( $config->get_array( 'mobile.rgroups' ) );
 
 			foreach ( $mobile_groups as $mobile_group => $mobile_config ) {
-				$mobile_enabled = ( isset( $mobile_config['enabled'] ) ? (boolean) $mobile_config['enabled'] : false );
-				$mobile_agents = ( isset( $mobile_config['agents'] ) ? (array) $mobile_config['agents'] : '' );
+				$mobile_enabled  = ( isset( $mobile_config['enabled'] ) ? (bool) $mobile_config['enabled'] : false );
+				$mobile_agents   = ( isset( $mobile_config['agents'] ) ? (array) $mobile_config['agents'] : '' );
 				$mobile_redirect = ( isset( $mobile_config['redirect'] ) ? $mobile_config['redirect'] : '' );
 
-				if ( $mobile_enabled && count( $mobile_agents ) && !$mobile_redirect ) {
-					$rules .= "    RewriteCond %{HTTP_USER_AGENT} (" . implode( '|', $mobile_agents ) . ") [NC]\n";
-					$rules .= "    RewriteRule .* - [E=W3TC_UA:_" . $mobile_group . "]\n";
+				if ( $mobile_enabled && count( $mobile_agents ) && ! $mobile_redirect ) {
+					$rules      .= '    RewriteCond %{HTTP_USER_AGENT} (' . implode( '|', $mobile_agents ) . ") [NC]\n";
+					$rules      .= '    RewriteRule .* - [E=W3TC_UA:_' . $mobile_group . "]\n";
 					$env_W3TC_UA = '%{ENV:W3TC_UA}';
 				}
 			}
 		}
 
-		/**
-		 * Set referrer groups
-		 */
+		// Set referrer groups.
 		if ( $config->get_boolean( 'referrer.enabled' ) ) {
 			$referrer_groups = array_reverse( $config->get_array( 'referrer.rgroups' ) );
 
 			foreach ( $referrer_groups as $referrer_group => $referrer_config ) {
-				$referrer_enabled = ( isset( $referrer_config['enabled'] ) ? (boolean) $referrer_config['enabled'] : false );
+				$referrer_enabled   = ( isset( $referrer_config['enabled'] ) ? (bool) $referrer_config['enabled'] : false );
 				$referrer_referrers = ( isset( $referrer_config['referrers'] ) ? (array) $referrer_config['referrers'] : '' );
-				$referrer_redirect = ( isset( $referrer_config['redirect'] ) ? $referrer_config['redirect'] : '' );
+				$referrer_redirect  = ( isset( $referrer_config['redirect'] ) ? $referrer_config['redirect'] : '' );
 
-				if ( $referrer_enabled && count( $referrer_referrers ) && !$referrer_redirect ) {
-					$rules .= "    RewriteCond %{HTTP_COOKIE} w3tc_referrer=.*(" . implode( '|', $referrer_referrers ) . ") [NC]\n";
-					$rules .= "    RewriteRule .* - [E=W3TC_REF:_" . $referrer_group . "]\n";
+				if ( $referrer_enabled && count( $referrer_referrers ) && ! $referrer_redirect ) {
+					$rules       .= '    RewriteCond %{HTTP_COOKIE} w3tc_referrer=.*(' . implode( '|', $referrer_referrers ) . ") [NC]\n";
+					$rules       .= '    RewriteRule .* - [E=W3TC_REF:_' . $referrer_group . "]\n";
 					$env_W3TC_REF = '%{ENV:W3TC_REF}';
 				}
 			}
 		}
 
-		/**
-		 * Set cookie group
-		 */
+		// Set cookie group.
 		if ( $config->get_boolean( 'pgcache.cookiegroups.enabled' ) ) {
 			$cookie_groups = $config->get_array( 'pgcache.cookiegroups.groups' );
 
 			foreach ( $cookie_groups as $group_name => $g ) {
 				if ( isset( $g['enabled'] ) && $g['enabled'] ) {
 					$cookies = array();
-					foreach ($g['cookies'] as $cookie ) {
+					foreach ( $g['cookies'] as $cookie ) {
 						$cookie = trim( $cookie );
-						if ( !empty( $cookie ) ) {
+						if ( ! empty( $cookie ) ) {
 							$cookie = str_replace( '+', ' ', $cookie );
 							$cookie = Util_Environment::preg_quote( $cookie );
-							if ( strpos( $cookie, '=') === false )
+							if ( strpos( $cookie, '=' ) === false ) {
 								$cookie .= '=.*';
+							}
 							$cookies[] = $cookie;
 						}
 					}
 
 					if ( count( $cookies ) > 0 ) {
-						$cookies_regexp = '^(.*;\s*)?(' . implode( '|', $cookies ) . ')(\s*;.*)?$';
-						$rules .= "    RewriteCond %{HTTP_COOKIE} $cookies_regexp [NC]\n";
-						$rules .= "    RewriteRule .* - [E=W3TC_COOKIE:_" . $group_name . "]\n";
+						$cookies_regexp  = '^(.*;\s*)?(' . implode( '|', $cookies ) . ')(\s*;.*)?$';
+						$rules          .= "    RewriteCond %{HTTP_COOKIE} $cookies_regexp [NC]\n";
+						$rules          .= '    RewriteRule .* - [E=W3TC_COOKIE:_' . $group_name . "]\n";
 						$env_W3TC_COOKIE = '%{ENV:W3TC_COOKIE}';
 					}
 				}
 			}
 		}
 
-		/**
-		 * Set HTTPS
-		 */
+		// Set HTTPS.
 		if ( $config->get_boolean( 'pgcache.cache.ssl' ) ) {
-			$rules .= "    RewriteCond %{HTTPS} =on\n";
-			$rules .= "    RewriteRule .* - [E=W3TC_SSL:_ssl]\n";
-			$rules .= "    RewriteCond %{SERVER_PORT} =443\n";
-			$rules .= "    RewriteRule .* - [E=W3TC_SSL:_ssl]\n";
-			$rules .= "    RewriteCond %{HTTP:X-Forwarded-Proto} =https [NC]\n";
-			$rules .= "    RewriteRule .* - [E=W3TC_SSL:_ssl]\n";
+			$rules       .= "    RewriteCond %{HTTPS} =on\n";
+			$rules       .= "    RewriteRule .* - [E=W3TC_SSL:_ssl]\n";
+			$rules       .= "    RewriteCond %{SERVER_PORT} =443\n";
+			$rules       .= "    RewriteRule .* - [E=W3TC_SSL:_ssl]\n";
+			$rules       .= "    RewriteCond %{HTTP:X-Forwarded-Proto} =https [NC]\n";
+			$rules       .= "    RewriteRule .* - [E=W3TC_SSL:_ssl]\n";
 			$env_W3TC_SSL = '%{ENV:W3TC_SSL}';
 		}
 
 		$cache_path = str_replace( Util_Environment::document_root(), '', $cache_dir );
 
-		/**
-		 * Set Accept-Encoding gzip
-		 */
+		// Set Accept-Encoding gzip.
 		if ( $config->get_boolean( 'browsercache.enabled' ) && $config->get_boolean( 'browsercache.html.compression' ) ) {
-			$rules .= "    RewriteCond %{HTTP:Accept-Encoding} gzip\n";
-			$rules .= "    RewriteRule .* - [E=W3TC_ENC:_gzip]\n";
+			$rules       .= "    RewriteCond %{HTTP:Accept-Encoding} gzip\n";
+			$rules       .= "    RewriteRule .* - [E=W3TC_ENC:_gzip]\n";
 			$env_W3TC_ENC = '%{ENV:W3TC_ENC}';
 		}
 
-		/**
-		 * Set Accept-Encoding brotli
-		 */
+		// Set Accept-Encoding brotli.
 		if ( $config->get_boolean( 'browsercache.enabled' ) && $config->get_boolean( 'browsercache.html.brotli' ) ) {
-			$rules .= "    RewriteCond %{HTTP:Accept-Encoding} br\n";
-			$rules .= "    RewriteRule .* - [E=W3TC_ENC:_br]\n";
+			$rules       .= "    RewriteCond %{HTTP:Accept-Encoding} br\n";
+			$rules       .= "    RewriteRule .* - [E=W3TC_ENC:_br]\n";
 			$env_W3TC_ENC = '%{ENV:W3TC_ENC}';
 		}
 
-		$rules .= "    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]\n";
-		$rules .= "    RewriteRule .* - [E=W3TC_PREVIEW:_preview]\n";
+		$rules           .= "    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]\n";
+		$rules           .= "    RewriteRule .* - [E=W3TC_PREVIEW:_preview]\n";
 		$env_W3TC_PREVIEW = '%{ENV:W3TC_PREVIEW}';
 
-		$rules .= "    RewriteCond %{REQUEST_URI} \\/$\n";
-		$rules .= "    RewriteRule .* - [E=W3TC_SLASH:_slash]\n";
+		$rules         .= "    RewriteCond %{REQUEST_URI} \\/$\n";
+		$rules         .= "    RewriteRule .* - [E=W3TC_SLASH:_slash]\n";
 		$env_W3TC_SLASH = '%{ENV:W3TC_SLASH}';
 
 		$use_cache_rules = '';
-		/**
-		 * Don't accept POSTs
-		 */
+
+		// Don't accept POSTs.
 		$use_cache_rules .= "    RewriteCond %{REQUEST_METHOD} !=POST\n";
 
-		/**
-		 * Query string should be empty
-		 */
+		// Query string should be empty.
 		$use_cache_rules .= empty( $w3tc_query_strings ) ?
 			"    RewriteCond %{QUERY_STRING} =\"\"\n" :
 			"    RewriteCond %{ENV:W3TC_QUERY_STRING} =\"\"\n";
 
-		/**
-		 * Check for rejected cookies
-		 */
-		$use_cache_rules .= "    RewriteCond %{HTTP_COOKIE} !(" . implode( '|',
-			array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ) ) . ") [NC]\n";
+		// Check for rejected cookies.
+		$use_cache_rules .= '    RewriteCond %{HTTP_COOKIE} !(' . implode(
+			'|',
+			array_map(
+				array(
+					'\W3TC\Util_Environment',
+					'preg_quote',
+				),
+				$reject_cookies
+			)
+		) . ") [NC]\n";
 
-		/**
-		 * Check for rejected user agents
-		 */
+		// Check for rejected user agents.
 		if ( count( $reject_user_agents ) ) {
-			$use_cache_rules .= "    RewriteCond %{HTTP_USER_AGENT} !(" .
-				implode( '|',
-				array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_user_agents ) ) . ") [NC]\n";
+			$use_cache_rules .= '    RewriteCond %{HTTP_USER_AGENT} !(' . implode(
+				'|',
+				array_map(
+					array(
+						'\W3TC\Util_Environment',
+						'preg_quote',
+					),
+					$reject_user_agents
+				)
+			) . ") [NC]\n";
 		}
 
 		$use_cache_rules = apply_filters(
@@ -773,23 +795,20 @@ private function rules_core_generate_apache( $config ) {
 			$use_cache_rules
 		);
 
-		/**
-		 * Make final rewrites for specific files
-		 */
-		$uri_prefix =  $cache_path . '/%{HTTP_HOST}/%{REQUEST_URI}/' .
-			'_index' . $env_W3TC_SLASH . $env_W3TC_UA . $env_W3TC_REF . $env_W3TC_COOKIE .
-			$env_W3TC_SSL . $env_W3TC_PREVIEW;
-		$uri_prefix = apply_filters( 'w3tc_pagecache_rules_apache_uri_prefix',
-			$uri_prefix );
+		// Make final rewrites for specific files.
+		$uri_prefix = $cache_path . '/%{HTTP_HOST}/%{REQUEST_URI}/_index' . $env_W3TC_SLASH .
+			$env_W3TC_UA . $env_W3TC_REF . $env_W3TC_COOKIE . $env_W3TC_SSL . $env_W3TC_PREVIEW;
+		$uri_prefix = apply_filters( 'w3tc_pagecache_rules_apache_uri_prefix', $uri_prefix );
 
-		$switch = " -" . ( $config->get_boolean( 'pgcache.file.nfs' ) ? 'F' : 'f' );
+		$switch = ' -' . ( $config->get_boolean( 'pgcache.file.nfs' ) ? 'F' : 'f' );
 
 		$document_root = Util_Rule::apache_docroot_variable();
 
-		// write rule to rewrite to .html/.xml file
+		// write rule to rewrite to .html/.xml file.
 		$exts = array( '.html' );
-		if ($config->get_boolean('pgcache.cache.nginx_handle_xml'))
+		if ( $config->get_boolean( 'pgcache.cache.nginx_handle_xml' ) ) {
 			$exts[] = '.xml';
+		}
 
 		/**
 		 * Filter: Allow adding additional rules at the end of the PGCACHE_CORE block, before the last rule.
@@ -815,10 +834,9 @@ private function rules_core_generate_apache( $config ) {
 		foreach ( $exts as $ext ) {
 			$rules .= $use_cache_rules;
 
-			$rules .= "    RewriteCond \"" . $document_root . $uri_prefix . $ext .
-				$env_W3TC_ENC . "\"" . $switch . "\n";
-			$rules .= "    RewriteRule .* \"" . $uri_prefix . $ext .
-				$env_W3TC_ENC . "\" [L]\n";
+			$rules .= '    RewriteCond "' . $document_root . $uri_prefix . $ext . $env_W3TC_ENC .
+				'"' . $switch . "\n";
+			$rules .= '    RewriteRule .* "' . $uri_prefix . $ext . $env_W3TC_ENC . "\" [L]\n";
 		}
 
 		$rules .= "</IfModule>\n";
@@ -829,39 +847,37 @@ private function rules_core_generate_apache( $config ) {
 	}
 
 	/**
-	 * Generates rules for WP dir
+	 * Generates NGINX configuration rules for page cache.
+	 *
+	 * @param \W3TC\Config $config Configuration object containing various settings for the cache.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string NGINX rules for page cache.
 	 */
 	private function rules_core_generate_nginx( $config ) {
 		$is_network = Util_Environment::is_wpmu();
 
-		$cache_dir = Util_Environment::normalize_path( W3TC_CACHE_PAGE_ENHANCED_DIR );
+		$cache_dir           = Util_Environment::normalize_path( W3TC_CACHE_PAGE_ENHANCED_DIR );
 		$permalink_structure = get_option( 'permalink_structure' );
-		$pgcache_engine = $config->get_string( 'pgcache.engine' );
+		$pgcache_engine      = $config->get_string( 'pgcache.engine' );
 
-		/**
-		 * Auto reject cookies
-		 */
+		// Auto reject cookies.
 		$reject_cookies = array(
 			'comment_author',
-			'wp-postpass'
+			'wp-postpass',
 		);
 
-		if ( $pgcache_engine == 'file_generic' ) {
+		if ( 'file_generic' === $pgcache_engine ) {
 			$reject_cookies[] = 'w3tc_logged_out';
 		}
 
-		/**
-		 * Reject cache for logged in users
-		 * OR
-		 * Reject cache for roles if any
-		 */
+		// Reject cache for logged in users OR Reject cache for roles if any.
 		if ( $config->get_boolean( 'pgcache.reject.logged' ) ) {
-			$reject_cookies = array_merge( $reject_cookies, array(
-					'wordpress_logged_in'
-				) );
+			$reject_cookies = array_merge(
+				$reject_cookies,
+				array(
+					'wordpress_logged_in',
+				)
+			);
 		} elseif ( $config->get_boolean( 'pgcache.reject.logged_roles' ) ) {
 			$new_cookies = array();
 			foreach ( $config->get_array( 'pgcache.reject.roles' ) as $role ) {
@@ -870,49 +886,43 @@ private function rules_core_generate_nginx( $config ) {
 			$reject_cookies = array_merge( $reject_cookies, $new_cookies );
 		}
 
-		/**
-		 * Custom config
-		 */
-		$reject_cookies = array_merge( $reject_cookies,
-			$config->get_array( 'pgcache.reject.cookie' ) );
+		// Custom config.
+		$reject_cookies = array_merge( $reject_cookies, $config->get_array( 'pgcache.reject.cookie' ) );
 		Util_Rule::array_trim( $reject_cookies );
 
 		$reject_user_agents = $config->get_array( 'pgcache.reject.ua' );
 		if ( $config->get_boolean( 'pgcache.compatibility' ) ) {
-			$reject_user_agents = array_merge( array( W3TC_POWERED_BY ),
-				$reject_user_agents );
+			$reject_user_agents = array_merge( array( W3TC_POWERED_BY ), $reject_user_agents );
 		}
+
 		Util_Rule::array_trim( $reject_user_agents );
 
-		/**
-		 * Generate rules
-		 */
-		$env_w3tc_ua = '';
-		$env_w3tc_ref = '';
+		// Generate rules.
+		$env_w3tc_ua     = '';
+		$env_w3tc_ref    = '';
 		$env_w3tc_cookie = '';
-		$env_w3tc_ssl = '';
-		$env_w3tc_ext = '';
-		$env_w3tc_enc = '';
+		$env_w3tc_ssl    = '';
+		$env_w3tc_ext    = '';
+		$env_w3tc_enc    = '';
 		$env_request_uri = '$request_uri';
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_PGCACHE_CORE . "\n";
 		if ( $config->get_boolean( 'pgcache.debug' ) ) {
 			$rules .= "rewrite ^(.*\\/)?w3tc_rewrite_test([0-9]+)/?$ $1?w3tc_rewrite_test=1 last;\n";
 		}
 
-		/**
-		 * Set accept query strings
-		 */
+		// Set accept query strings.
 		$w3tc_query_strings = apply_filters(
 			'w3tc_pagecache_rules_nginx_accept_qs',
-			$config->get_array( 'pgcache.accept.qs' ) );
+			$config->get_array( 'pgcache.accept.qs' )
+		);
 
 		Util_Rule::array_trim( $w3tc_query_strings );
 
-		if ( !empty( $w3tc_query_strings ) ) {
-		   $w3tc_query_strings = str_replace( ' ', '+', $w3tc_query_strings );
-		   $w3tc_query_strings = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $w3tc_query_strings );
+		if ( ! empty( $w3tc_query_strings ) ) {
+			$w3tc_query_strings = str_replace( ' ', '+', $w3tc_query_strings );
+			$w3tc_query_strings = array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $w3tc_query_strings );
 
 			$rules .= "set \$w3tc_query_string \$query_string;\n";
 
@@ -930,7 +940,10 @@ private function rules_core_generate_nginx( $config ) {
 
 				$query_rules = apply_filters(
 					'w3tc_pagecache_rules_nginx_accept_qs_rules',
-					$query_rules, $query );
+					$query_rules,
+					$query
+				);
+
 				$rules .= implode( "\n", $query_rules ) . "\n";
 			}
 
@@ -942,71 +955,55 @@ private function rules_core_generate_nginx( $config ) {
 			$rules .= "if (\$w3tc_request_uri ~* \"^([^?]+)\?\") {\n";
 			$rules .= "    set \$w3tc_request_uri \$1;\n";
 			$rules .= "}\n";
+
 			$env_request_uri = '$w3tc_request_uri';
 		}
 
-		/**
-		 * Check for mobile redirect
-		 */
+		// Check for mobile redirect.
 		if ( $config->get_boolean( 'mobile.enabled' ) ) {
 			$mobile_groups = $config->get_array( 'mobile.rgroups' );
 
 			foreach ( $mobile_groups as $mobile_group => $mobile_config ) {
-				$mobile_enabled = ( isset( $mobile_config['enabled'] ) ?
-					(boolean) $mobile_config['enabled'] : false );
-				$mobile_agents = ( isset( $mobile_config['agents'] ) ?
-					(array) $mobile_config['agents'] : '' );
-				$mobile_redirect = ( isset( $mobile_config['redirect'] ) ?
-					$mobile_config['redirect'] : '' );
+				$mobile_enabled  = ( isset( $mobile_config['enabled'] ) ? (bool) $mobile_config['enabled'] : false );
+				$mobile_agents   = ( isset( $mobile_config['agents'] ) ? (array) $mobile_config['agents'] : '' );
+				$mobile_redirect = ( isset( $mobile_config['redirect'] ) ? $mobile_config['redirect'] : '' );
 
 				if ( $mobile_enabled && count( $mobile_agents ) && $mobile_redirect ) {
-					$rules .= "if (\$http_user_agent ~* \"(" . implode( '|',
-						$mobile_agents ) . ")\") {\n";
-					$rules .= "    rewrite .* " . $mobile_redirect . " last;\n";
+					$rules .= 'if ($http_user_agent ~* "(' . implode( '|', $mobile_agents ) . ")\") {\n";
+					$rules .= '    rewrite .* ' . $mobile_redirect . " last;\n";
 					$rules .= "}\n";
 				}
 			}
 		}
 
-		/**
-		 * Check for referrer redirect
-		 */
+		// Check for referrer redirect.
 		if ( $config->get_boolean( 'referrer.enabled' ) ) {
 			$referrer_groups = $config->get_array( 'referrer.rgroups' );
 
 			foreach ( $referrer_groups as $referrer_group => $referrer_config ) {
-				$referrer_enabled = ( isset( $referrer_config['enabled'] ) ?
-					(boolean) $referrer_config['enabled'] : false );
-				$referrer_referrers = ( isset( $referrer_config['referrers'] ) ?
-					(array) $referrer_config['referrers'] : '' );
-				$referrer_redirect = ( isset( $referrer_config['redirect'] ) ?
-					$referrer_config['redirect'] : '' );
+				$referrer_enabled   = ( isset( $referrer_config['enabled'] ) ? (bool) $referrer_config['enabled'] : false );
+				$referrer_referrers = ( isset( $referrer_config['referrers'] ) ? (array) $referrer_config['referrers'] : '' );
+				$referrer_redirect  = ( isset( $referrer_config['redirect'] ) ? $referrer_config['redirect'] : '' );
 
 				if ( $referrer_enabled && count( $referrer_referrers ) &&
 					$referrer_redirect ) {
-					$rules .= "if (\$http_cookie ~* \"w3tc_referrer=.*(" .
-						implode( '|', $referrer_referrers ) . ")\") {\n";
-					$rules .= "    rewrite .* " . $referrer_redirect . " last;\n";
+					$rules .= 'if ($http_cookie ~* "w3tc_referrer=.*(' . implode( '|', $referrer_referrers ) . ")\") {\n";
+					$rules .= '    rewrite .* ' . $referrer_redirect . " last;\n";
 					$rules .= "}\n";
 				}
 			}
 		}
 
-		/**
-		 * Don't accept POSTs
-		 */
+		// Don't accept POSTs.
 		$rules .= "set \$w3tc_rewrite 1;\n";
 		$rules .= "if (\$request_method = POST) {\n";
 		$rules .= "    set \$w3tc_rewrite 0;\n";
 		$rules .= "}\n";
 
-		/**
-		 * Query string should be empty
-		 */
-		$querystring_variable = ( empty( $w3tc_query_strings ) ?
-			'$query_string' : '$w3tc_query_string' );
+		// Query string should be empty.
+		$querystring_variable = ( empty( $w3tc_query_strings ) ? '$query_string' : '$w3tc_query_string' );
 
-		$rules .= "if (" . $querystring_variable . " != \"\") {\n";
+		$rules .= 'if (' . $querystring_variable . " != \"\") {\n";
 		$rules .= "    set \$w3tc_rewrite 0;\n";
 		$rules .= "}\n";
 
@@ -1014,113 +1011,112 @@ private function rules_core_generate_nginx( $config ) {
 		$rules .= "if ($env_request_uri ~ \\/$) {\n";
 		$rules .= "    set \$w3tc_slash _slash;\n";
 		$rules .= "}\n";
-		$env_w3tc_slash = "\$w3tc_slash";
 
-		/**
-		 * Check for rejected cookies
-		 */
-		$rules .= "if (\$http_cookie ~* \"(" . implode( '|',
-			array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_cookies ) ) . ")\") {\n";
+		$env_w3tc_slash = '$w3tc_slash';
+
+		// Check for rejected cookies.
+		$rules .= 'if ($http_cookie ~* "(' . implode(
+			'|',
+			array_map(
+				array(
+					'\W3TC\Util_Environment',
+					'preg_quote',
+				),
+				$reject_cookies
+			)
+		) . ")\") {\n";
 		$rules .= "    set \$w3tc_rewrite 0;\n";
 		$rules .= "}\n";
 
-		/**
-		 * Check for rejected user agents
-		 */
+		// Check for rejected user agents.
 		if ( count( $reject_user_agents ) ) {
-			$rules .= "if (\$http_user_agent ~* \"(" . implode( '|',
-				array_map( array( '\W3TC\Util_Environment', 'preg_quote' ), $reject_user_agents ) ) . ")\") {\n";
+			$rules .= 'if ($http_user_agent ~* "(' . implode(
+				'|',
+				array_map(
+					array(
+						'\W3TC\Util_Environment',
+						'preg_quote',
+					),
+					$reject_user_agents
+				)
+			) . ")\") {\n";
 			$rules .= "    set \$w3tc_rewrite 0;\n";
 			$rules .= "}\n";
 		}
 
-		/**
-		 * Check mobile groups
-		 */
+		// Check mobile groups.
 		if ( $config->get_boolean( 'mobile.enabled' ) ) {
 			$mobile_groups = array_reverse( $config->get_array( 'mobile.rgroups' ) );
-			$set_ua_var = true;
+			$set_ua_var    = true;
 
 			foreach ( $mobile_groups as $mobile_group => $mobile_config ) {
-				$mobile_enabled = ( isset( $mobile_config['enabled'] ) ?
-					(boolean) $mobile_config['enabled'] : false );
-				$mobile_agents = ( isset( $mobile_config['agents'] ) ?
-					(array) $mobile_config['agents'] : '' );
-				$mobile_redirect = ( isset( $mobile_config['redirect'] ) ?
-					$mobile_config['redirect'] : '' );
-
-				if ( $mobile_enabled && count( $mobile_agents ) &&
-					!$mobile_redirect ) {
+				$mobile_enabled  = ( isset( $mobile_config['enabled'] ) ? (bool) $mobile_config['enabled'] : false );
+				$mobile_agents   = ( isset( $mobile_config['agents'] ) ? (array) $mobile_config['agents'] : '' );
+				$mobile_redirect = ( isset( $mobile_config['redirect'] ) ? $mobile_config['redirect'] : '' );
+
+				if ( $mobile_enabled && count( $mobile_agents ) && ! $mobile_redirect ) {
 					if ( $set_ua_var ) {
-						$rules .= "set \$w3tc_ua \"\";\n";
+						$rules     .= "set \$w3tc_ua \"\";\n";
 						$set_ua_var = false;
 					}
-					$rules .= "if (\$http_user_agent ~* \"(" .
-						implode( '|', $mobile_agents ) . ")\") {\n";
-					$rules .= "    set \$w3tc_ua _" . $mobile_group . ";\n";
+					$rules .= 'if ($http_user_agent ~* "(' . implode( '|', $mobile_agents ) . ")\") {\n";
+					$rules .= '    set $w3tc_ua _' . $mobile_group . ";\n";
 					$rules .= "}\n";
 
-					$env_w3tc_ua = "\$w3tc_ua";
+					$env_w3tc_ua = '$w3tc_ua';
 				}
 			}
 		}
 
-		/**
-		 * Check for preview cookie
-		 */
+		// Check for preview cookie.
 		$rules .= "set \$w3tc_preview \"\";\n";
 		$rules .= "if (\$http_cookie ~* \"(w3tc_preview)\") {\n";
 		$rules .= "    set \$w3tc_preview _preview;\n";
 		$rules .= "}\n";
-		$env_w3tc_preview = "\$w3tc_preview";
 
-		/**
-		 * Check referrer groups
-		 */
+		$env_w3tc_preview = '$w3tc_preview';
+
+		// Check referrer groups.
 		if ( $config->get_boolean( 'referrer.enabled' ) ) {
 			$referrer_groups = array_reverse( $config->get_array( 'referrer.rgroups' ) );
-			$set_ref_var = true;
+			$set_ref_var     = true;
 			foreach ( $referrer_groups as $referrer_group => $referrer_config ) {
-				$referrer_enabled = ( isset( $referrer_config['enabled'] ) ?
-					(boolean) $referrer_config['enabled'] : false );
-				$referrer_referrers = ( isset( $referrer_config['referrers'] ) ?
-					(array) $referrer_config['referrers'] : '' );
-				$referrer_redirect = ( isset( $referrer_config['redirect'] ) ?
-					$referrer_config['redirect'] : '' );
+				$referrer_enabled   = ( isset( $referrer_config['enabled'] ) ? (bool) $referrer_config['enabled'] : false );
+				$referrer_referrers = ( isset( $referrer_config['referrers'] ) ? (array) $referrer_config['referrers'] : '' );
+				$referrer_redirect  = ( isset( $referrer_config['redirect'] ) ? $referrer_config['redirect'] : '' );
 
-				if ( $referrer_enabled && count( $referrer_referrers ) &&
-					!$referrer_redirect ) {
+				if ( $referrer_enabled && count( $referrer_referrers ) && ! $referrer_redirect ) {
 					if ( $set_ref_var ) {
-						$rules .= "set \$w3tc_ref \"\";\n";
+						$rules      .= "set \$w3tc_ref \"\";\n";
 						$set_ref_var = false;
 					}
-					$rules .= "if (\$http_cookie ~* \"w3tc_referrer=.*(" .
-						implode( '|', $referrer_referrers ) . ")\") {\n";
-					$rules .= "    set \$w3tc_ref _" . $referrer_group . ";\n";
+
+					$rules .= 'if ($http_cookie ~* "w3tc_referrer=.*(' . implode( '|', $referrer_referrers ) . ")\") {\n";
+					$rules .= '    set $w3tc_ref _' . $referrer_group . ";\n";
 					$rules .= "}\n";
 
-					$env_w3tc_ref = "\$w3tc_ref";
+					$env_w3tc_ref = '$w3tc_ref';
 				}
 			}
 		}
 
-		/**
-		 * Set cookie group
-		 */
+		// Set cookie group.
 		if ( $config->get_boolean( 'pgcache.cookiegroups.enabled' ) ) {
-			$cookie_groups = $config->get_array( 'pgcache.cookiegroups.groups' );
+			$cookie_groups  = $config->get_array( 'pgcache.cookiegroups.groups' );
 			$set_cookie_var = true;
 
 			foreach ( $cookie_groups as $group_name => $g ) {
 				if ( isset( $g['enabled'] ) && $g['enabled'] ) {
 					$cookies = array();
-					foreach ($g['cookies'] as $cookie ) {
+					foreach ( $g['cookies'] as $cookie ) {
 						$cookie = trim( $cookie );
-						if ( !empty( $cookie ) ) {
+						if ( ! empty( $cookie ) ) {
 							$cookie = str_replace( '+', ' ', $cookie );
 							$cookie = Util_Environment::preg_quote( $cookie );
-							if ( strpos( $cookie, '=') === false )
+							if ( false === strpos( $cookie, '=' ) ) {
 								$cookie .= '=.*';
+							}
+
 							$cookies[] = $cookie;
 						}
 					}
@@ -1129,14 +1125,15 @@ private function rules_core_generate_nginx( $config ) {
 						$cookies_regexp = '"^(.*;)?(' . implode( '|', $cookies ) . ')(;.*)?$"';
 
 						if ( $set_cookie_var ) {
-							$rules .= "set \$w3tc_cookie \"\";\n";
+							$rules         .= "set \$w3tc_cookie \"\";\n";
 							$set_cookie_var = false;
 						}
+
 						$rules .= "if (\$http_cookie ~* $cookies_regexp) {\n";
-						$rules .= "    set \$w3tc_cookie _" . $group_name . ";\n";
+						$rules .= '    set $w3tc_cookie _' . $group_name . ";\n";
 						$rules .= "}\n";
 
-						$env_w3tc_cookie = "\$w3tc_cookie";
+						$env_w3tc_cookie = '$w3tc_cookie';
 					}
 				}
 			}
@@ -1155,8 +1152,7 @@ private function rules_core_generate_nginx( $config ) {
 			$env_w3tc_ssl = '$w3tc_ssl';
 		}
 
-		if ( $config->get_boolean( 'browsercache.enabled' ) &&
-			$config->get_boolean( 'browsercache.html.compression' ) ) {
+		if ( $config->get_boolean( 'browsercache.enabled' ) && $config->get_boolean( 'browsercache.html.compression' ) ) {
 			$rules .= "set \$w3tc_enc \"\";\n";
 
 			$rules .= "if (\$http_accept_encoding ~ gzip) {\n";
@@ -1166,8 +1162,7 @@ private function rules_core_generate_nginx( $config ) {
 			$env_w3tc_enc = '$w3tc_enc';
 		}
 
-		if ( $config->get_boolean( 'browsercache.enabled' ) &&
-			$config->get_boolean( 'browsercache.html.brotli' ) ) {
+		if ( $config->get_boolean( 'browsercache.enabled' ) && $config->get_boolean( 'browsercache.html.brotli' ) ) {
 			$rules .= "set \$w3tc_enc \"\";\n";
 
 			$rules .= "if (\$http_accept_encoding ~ br) {\n";
@@ -1177,8 +1172,7 @@ private function rules_core_generate_nginx( $config ) {
 			$env_w3tc_enc = '$w3tc_enc';
 		}
 
-		$key_postfix = $env_w3tc_slash . $env_w3tc_ua . $env_w3tc_ref . $env_w3tc_cookie .
-			$env_w3tc_ssl . $env_w3tc_preview;
+		$key_postfix = $env_w3tc_slash . $env_w3tc_ua . $env_w3tc_ref . $env_w3tc_cookie . $env_w3tc_ssl . $env_w3tc_preview;
 
 		/**
 		 * Filter: Allow modifying the key_postfix string used in the PGCACHE_CORE block.
@@ -1189,12 +1183,22 @@ private function rules_core_generate_nginx( $config ) {
 		 */
 		$key_postfix = \apply_filters( 'w3tc_pgcache_postfix_nginx', $key_postfix );
 
-		if ( $pgcache_engine == 'file_generic' ) {
-			$rules .= $this->for_file_generic( $config, $cache_dir,
-				$env_request_uri, $key_postfix, $env_w3tc_enc );
-		} elseif ( $pgcache_engine == 'nginx_memcached' ) {
-			$rules .= $this->for_nginx_memcached( $config, $cache_dir,
-				$env_request_uri, $key_postfix, $env_w3tc_enc );
+		if ( 'file_generic' === $pgcache_engine ) {
+			$rules .= $this->for_file_generic(
+				$config,
+				$cache_dir,
+				$env_request_uri,
+				$key_postfix,
+				$env_w3tc_enc
+			);
+		} elseif ( 'nginx_memcached' === $pgcache_engine ) {
+			$rules .= $this->for_nginx_memcached(
+				$config,
+				$cache_dir,
+				$env_request_uri,
+				$key_postfix,
+				$env_w3tc_enc
+			);
 		}
 
 		$rules .= W3TC_MARKER_END_PGCACHE_CORE . "\n";
@@ -1202,36 +1206,39 @@ private function rules_core_generate_nginx( $config ) {
 		return $rules;
 	}
 
-
-
-	private function for_file_generic( $config, $cache_dir, $env_request_uri,
-			$key_postfix, $env_w3tc_enc ) {
+	/**
+	 * Generates the cache rules for file-based generic cache handling.
+	 *
+	 * @param object $config          The configuration object containing settings for cache handling.
+	 * @param string $cache_dir       The directory where cache files are stored.
+	 * @param string $env_request_uri The request URI for the environment.
+	 * @param string $key_postfix     The key postfix to be used in cache keys.
+	 * @param string $env_w3tc_enc    The encoded string to append to cache file names.
+	 *
+	 * @return string The generated cache rules for nginx.
+	 */
+	private function for_file_generic( $config, $cache_dir, $env_request_uri, $key_postfix, $env_w3tc_enc ) {
 		$rules = '';
 
-		$cache_path = str_replace( Util_Environment::document_root(), '',
-			$cache_dir );
+		$cache_path = str_replace( Util_Environment::document_root(), '', $cache_dir );
 		$uri_prefix = "$cache_path/\$http_host/$env_request_uri/_index$key_postfix";
-		$uri_prefix = apply_filters( 'w3tc_pagecache_rules_nginx_uri_prefix',
-			$uri_prefix );
+		$uri_prefix = apply_filters( 'w3tc_pagecache_rules_nginx_uri_prefix', $uri_prefix );
 
-		if ( !$config->get_boolean( 'pgcache.cache.nginx_handle_xml' ) ) {
+		if ( ! $config->get_boolean( 'pgcache.cache.nginx_handle_xml' ) ) {
 			$env_w3tc_ext = '.html';
 
-			$rules .= 'if (!-f "$document_root' . $uri_prefix . '.html' .
-				$env_w3tc_enc . '") {' . "\n";
+			$rules .= 'if (!-f "$document_root' . $uri_prefix . '.html' . $env_w3tc_enc . '") {' . "\n";
 			$rules .= '  set $w3tc_rewrite 0;' . "\n";
 			$rules .= "}\n";
 		} else {
 			$env_w3tc_ext = '$w3tc_ext';
 
 			$rules .= 'set $w3tc_ext "";' . "\n";
-			$rules .= 'if (-f "$document_root' . $uri_prefix . '.html' .
-				$env_w3tc_enc . '") {' . "\n";
-			$rules .= '    set $w3tc_ext .html;' . "\n";
+			$rules .= 'if (-f "$document_root' . $uri_prefix . '.html' . $env_w3tc_enc . '") {' . "\n";
+			$rules .= '  set $w3tc_ext .html;' . "\n";
 			$rules .= "}\n";
 
-			$rules .= 'if (-f "$document_root' . $uri_prefix . '.xml' .
-				$env_w3tc_enc . '") {' . "\n";
+			$rules .= 'if (-f "$document_root' . $uri_prefix . '.xml' . $env_w3tc_enc . '") {' . "\n";
 			$rules .= '    set $w3tc_ext .xml;' . "\n";
 			$rules .= "}\n";
 
@@ -1241,38 +1248,42 @@ private function for_file_generic( $config, $cache_dir, $env_request_uri,
 		}
 
 		$rules .= 'if ($w3tc_rewrite = 1) {' . "\n";
-		$rules .= '    rewrite .* "' . $uri_prefix . $env_w3tc_ext . $env_w3tc_enc .
-			'" last;' . "\n";
+		$rules .= '    rewrite .* "' . $uri_prefix . $env_w3tc_ext . $env_w3tc_enc . '" last;' . "\n";
 		$rules .= "}\n";
 
 		return $rules;
 	}
 
-
-
-	private function for_nginx_memcached( $config, $cache_dir, $env_request_uri,
-			$key_postfix, $env_w3tc_enc ) {
-		$rules =  "set \$request_uri_noslash $env_request_uri;\n";
+	/**
+	 * Generates the cache rules for nginx with memcached support.
+	 *
+	 * @param object $config          The configuration object containing settings for cache handling.
+	 * @param string $cache_dir       The directory where cache files are stored.
+	 * @param string $env_request_uri The request URI for the environment.
+	 * @param string $key_postfix     The key postfix to be used in cache keys.
+	 * @param string $env_w3tc_enc    The encoded string to append to cache file names.
+	 *
+	 * @return string The generated cache rules for nginx with memcached support.
+	 */
+	private function for_nginx_memcached( $config, $cache_dir, $env_request_uri, $key_postfix, $env_w3tc_enc ) {
+		$rules  = "set \$request_uri_noslash $env_request_uri;\n";
 		$rules .= "if ($env_request_uri ~ \"(.*?)(/+)$\") {\n";
 		$rules .= '    set $request_uri_noslash $1;' . "\n";
 		$rules .= "}\n";
 
-		$cache_path = str_replace( Util_Environment::document_root(), '',
-			$cache_dir );
+		$cache_path = str_replace( Util_Environment::document_root(), '', $cache_dir );
 
 		$rules .= 'location ~ ".*(?<!php)$" {' . "\n";
-		$rules .= '  set $memcached_key "$http_host$request_uri_noslash/' .
-			$key_postfix . $env_w3tc_enc . '";' . "\n";
+		$rules .= '  set $memcached_key "$http_host$request_uri_noslash/' . $key_postfix . $env_w3tc_enc . '";' . "\n";
 
-		if ( $config->get_boolean( 'browsercache.enabled' ) &&
-			$config->get_boolean( 'browsercache.html.compression' ) ) {
+		if ( $config->get_boolean( 'browsercache.enabled' ) && $config->get_boolean( 'browsercache.html.compression' ) ) {
 			$rules .= '  memcached_gzip_flag 65536;' . "\n";
-		   }
+		}
 
 		$rules .= '  default_type text/html;' . "\n";
 
 		$memcached_servers = $config->get_array( 'pgcache.memcached.servers' );
-		$memcached_pass = !empty( $memcached_servers ) ? array_values( $memcached_servers )[0] : 'localhost:11211';
+		$memcached_pass    = ! empty( $memcached_servers ) ? array_values( $memcached_servers )[0] : 'localhost:11211';
 
 		$rules .= '  if ($w3tc_rewrite = 1) {' . "\n";
 		$rules .= '    memcached_pass ' . $memcached_pass . ';' . "\n";
@@ -1287,98 +1298,99 @@ private function for_nginx_memcached( $config, $cache_dir, $env_request_uri,
 		return $rules;
 	}
 
-
-
-	/*
-	 * cache rules
-	 */
-
 	/**
-	 * Writes directives to file cache .htaccess
-	 * Throws exception on error
+	 * Adds cache rules to a given set of existing rules.
+	 *
+	 * @param object $config The configuration object containing settings for cache handling.
+	 * @param array  $exs    The existing set of rules to which new cache rules will be added.
 	 *
-	 * @param Config  $config
-	 * @param Util_Environment_Exceptions $exs
+	 * @return void
 	 */
 	private function rules_cache_add( $config, $exs ) {
-		Util_Rule::add_rules( $exs,
+		Util_Rule::add_rules(
+			$exs,
 			Util_Rule::get_pgcache_rules_cache_path(),
 			$this->rules_cache_generate( $config ),
 			W3TC_MARKER_BEGIN_PGCACHE_CACHE,
 			W3TC_MARKER_END_PGCACHE_CACHE,
 			array(
 				W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE => 0,
-				W3TC_MARKER_BEGIN_MINIFY_CORE => 0,
-				W3TC_MARKER_BEGIN_PGCACHE_CORE => 0,
-				W3TC_MARKER_BEGIN_WORDPRESS => 0,
-				W3TC_MARKER_END_MINIFY_CACHE => strlen( W3TC_MARKER_END_MINIFY_CACHE ) + 1
+				W3TC_MARKER_BEGIN_MINIFY_CORE        => 0,
+				W3TC_MARKER_BEGIN_PGCACHE_CORE       => 0,
+				W3TC_MARKER_BEGIN_WORDPRESS          => 0,
+				W3TC_MARKER_END_MINIFY_CACHE         => strlen( W3TC_MARKER_END_MINIFY_CACHE ) + 1,
 			)
 		);
 	}
 
 	/**
-	 * Removes Page Cache cache directives
+	 * Removes cache rules from a given set of existing rules.
+	 *
+	 * @param array $exs The existing set of rules from which cache rules will be removed.
 	 *
-	 * @param Util_Environment_Exceptions $exs
-	 * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
+	 * @return void
 	 */
 	private function rules_cache_remove( $exs ) {
-		// apache's cache files are not used when core rules disabled
-		if ( !Util_Environment::is_nginx() )
+		// apache's cache files are not used when core rules disabled.
+		if ( ! Util_Environment::is_nginx() ) {
 			return;
+		}
 
-		Util_Rule::remove_rules( $exs,
+		Util_Rule::remove_rules(
+			$exs,
 			Util_Rule::get_pgcache_rules_cache_path(),
 			W3TC_MARKER_BEGIN_PGCACHE_CACHE,
-			W3TC_MARKER_END_PGCACHE_CACHE );
+			W3TC_MARKER_END_PGCACHE_CACHE
+		);
 	}
 
 	/**
-	 * Generates directives for file cache dir
+	 * Generates cache rules based on the environment (Apache or Nginx).
+	 *
+	 * @param object $config The configuration object containing settings for cache handling.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string The generated cache rules based on the server environment.
 	 */
 	public function rules_cache_generate( $config ) {
 		switch ( true ) {
-		case Util_Environment::is_apache():
-		case Util_Environment::is_litespeed():
-			return $this->rules_cache_generate_apache( $config );
+			case Util_Environment::is_apache():
+			case Util_Environment::is_litespeed():
+				return $this->rules_cache_generate_apache( $config );
 
-		case Util_Environment::is_nginx():
-			return $this->rules_cache_generate_nginx( $config );
+			case Util_Environment::is_nginx():
+				return $this->rules_cache_generate_nginx( $config );
 		}
 
 		return '';
 	}
 
-
 	/**
-	 * Generates directives for file cache dir
+	 * Generates cache rules for Apache-based environments.
+	 *
+	 * @param object $config The configuration object containing settings for cache handling.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string The generated cache rules for Apache-based environments.
 	 */
 	private function rules_cache_generate_apache( $config ) {
-		$charset = get_option( 'blog_charset' );
+		$charset      = get_option( 'blog_charset' );
 		$pingback_url = get_bloginfo( 'pingback_url' );
 
-		$browsercache = $config->get_boolean( 'browsercache.enabled' );
-		$brotli = ( $browsercache && $config->get_boolean( 'browsercache.html.brotli' ) );
-		$compression = ( $browsercache && $config->get_boolean( 'browsercache.html.compression' ) );
-		$expires = ( $browsercache && $config->get_boolean( 'browsercache.html.expires' ) );
-		$lifetime = ( $browsercache ? $config->get_integer( 'browsercache.html.lifetime' ) : 0 );
+		$browsercache  = $config->get_boolean( 'browsercache.enabled' );
+		$brotli        = ( $browsercache && $config->get_boolean( 'browsercache.html.brotli' ) );
+		$compression   = ( $browsercache && $config->get_boolean( 'browsercache.html.compression' ) );
+		$expires       = ( $browsercache && $config->get_boolean( 'browsercache.html.expires' ) );
+		$lifetime      = ( $browsercache ? $config->get_integer( 'browsercache.html.lifetime' ) : 0 );
 		$cache_control = ( $browsercache && $config->get_boolean( 'browsercache.html.cache.control' ) );
-		$etag = ( $browsercache && $config->get_integer( 'browsercache.html.etag' ) );
-		$w3tc = ( $browsercache && $config->get_integer( 'browsercache.html.w3tc' ) );
+		$etag          = ( $browsercache && $config->get_integer( 'browsercache.html.etag' ) );
+		$w3tc          = ( $browsercache && $config->get_integer( 'browsercache.html.w3tc' ) );
 		$compatibility = $config->get_boolean( 'pgcache.compatibility' );
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_PGCACHE_CACHE . "\n";
 		if ( $compatibility ) {
 			$rules .= "Options -MultiViews\n";
 
-			// allow to read files by apache if they are blocked at some level above
+			// allow to read files by apache if they are blocked at some level above.
 			$rules .= "<Files ~ \"\.(html|html_gzip|html_br|xml|xml_gzip|xml_br)$\">\n";
 
 			if ( version_compare( Util_Environment::get_server_version(), '2.4', '>=' ) ) {
@@ -1390,16 +1402,17 @@ private function rules_cache_generate_apache( $config ) {
 
 			$rules .= "</Files>\n";
 
-			if ( !$etag ) {
+			if ( ! $etag ) {
 				$rules .= "FileETag None\n";
 			}
 		}
+
 		if ( $config->get_boolean( 'pgcache.file.nfs' ) ) {
 			$rules .= "EnableSendfile Off \n";
 		}
 
-		if ( !$config->get_boolean( 'pgcache.remove_charset' ) ) {
-			$rules .= "AddDefaultCharset " . ( $charset ? $charset : 'utf-8' ) . "\n";
+		if ( ! $config->get_boolean( 'pgcache.remove_charset' ) ) {
+			$rules .= 'AddDefaultCharset ' . ( $charset ? $charset : 'utf-8' ) . "\n";
 		}
 
 		if ( $etag ) {
@@ -1435,19 +1448,18 @@ private function rules_cache_generate_apache( $config ) {
 		if ( $expires ) {
 			$rules .= "<IfModule mod_expires.c>\n";
 			$rules .= "    ExpiresActive On\n";
-			$rules .= "    ExpiresByType text/html M" . $lifetime . "\n";
+			$rules .= '    ExpiresByType text/html M' . $lifetime . "\n";
 			$rules .= "</IfModule>\n";
 		}
 
 		$header_rules = '';
 
 		if ( $compatibility ) {
-			$header_rules .= "    Header set X-Pingback \"" . $pingback_url . "\"\n";
+			$header_rules .= '    Header set X-Pingback "' . $pingback_url . "\"\n";
 		}
 
 		if ( $w3tc ) {
-			$header_rules .= "    Header set X-Powered-By \"" .
-				Util_Environment::w3tc_header() . "\"\n";
+			$header_rules .= '    Header set X-Powered-By "' . Util_Environment::w3tc_header() . "\"\n";
 		}
 
 		if ( $expires ) {
@@ -1456,7 +1468,7 @@ private function rules_cache_generate_apache( $config ) {
 
 		$set_last_modified = $config->get_boolean( 'browsercache.html.last_modified' );
 
-		if ( !$set_last_modified && $config->get_boolean( 'browsercache.enabled' ) ) {
+		if ( ! $set_last_modified && $config->get_boolean( 'browsercache.enabled' ) ) {
 			$header_rules .= "    Header unset Last-Modified\n";
 		}
 
@@ -1464,50 +1476,50 @@ private function rules_cache_generate_apache( $config ) {
 			$cache_policy = $config->get_string( 'browsercache.html.cache.policy' );
 
 			switch ( $cache_policy ) {
-			case 'cache':
-				$header_rules .= "    Header set Pragma \"public\"\n";
-				$header_rules .= "    Header set Cache-Control \"public\"\n";
-				break;
-
-			case 'cache_public_maxage':
-				$header_rules .= "    Header set Pragma \"public\"\n";
-
-				if ( $expires ) {
-					$header_rules .= "    Header append Cache-Control \"public\"\n";
-				} else {
-					$header_rules .= "    Header set Cache-Control \"max-age=" . $lifetime . ", public\"\n";
-				}
-				break;
+				case 'cache':
+					$header_rules .= "    Header set Pragma \"public\"\n";
+					$header_rules .= "    Header set Cache-Control \"public\"\n";
+					break;
+
+				case 'cache_public_maxage':
+					$header_rules .= "    Header set Pragma \"public\"\n";
+
+					if ( $expires ) {
+						$header_rules .= "    Header append Cache-Control \"public\"\n";
+					} else {
+						$header_rules .= '    Header set Cache-Control "max-age=' . $lifetime . ", public\"\n";
+					}
+					break;
 
-			case 'cache_validation':
-				$header_rules .= "    Header set Pragma \"public\"\n";
-				$header_rules .= "    Header set Cache-Control \"public, must-revalidate, proxy-revalidate\"\n";
-				break;
+				case 'cache_validation':
+					$header_rules .= "    Header set Pragma \"public\"\n";
+					$header_rules .= "    Header set Cache-Control \"public, must-revalidate, proxy-revalidate\"\n";
+					break;
 
-			case 'cache_noproxy':
-				$header_rules .= "    Header set Pragma \"public\"\n";
-				$header_rules .= "    Header set Cache-Control \"private, must-revalidate\"\n";
-				break;
+				case 'cache_noproxy':
+					$header_rules .= "    Header set Pragma \"public\"\n";
+					$header_rules .= "    Header set Cache-Control \"private, must-revalidate\"\n";
+					break;
 
-			case 'cache_maxage':
-				$header_rules .= "    Header set Pragma \"public\"\n";
+				case 'cache_maxage':
+					$header_rules .= "    Header set Pragma \"public\"\n";
 
-				if ( $expires ) {
-					$header_rules .= "    Header append Cache-Control \"public, must-revalidate, proxy-revalidate\"\n";
-				} else {
-					$header_rules .= "    Header set Cache-Control \"max-age=" . $lifetime . ", public, must-revalidate, proxy-revalidate\"\n";
-				}
-				break;
+					if ( $expires ) {
+						$header_rules .= "    Header append Cache-Control \"public, must-revalidate, proxy-revalidate\"\n";
+					} else {
+						$header_rules .= '    Header set Cache-Control "max-age=' . $lifetime . ", public, must-revalidate, proxy-revalidate\"\n";
+					}
+					break;
 
-			case 'no_cache':
-				$header_rules .= "    Header set Pragma \"no-cache\"\n";
-				$header_rules .= "    Header set Cache-Control \"private, no-cache\"\n";
-				break;
+				case 'no_cache':
+					$header_rules .= "    Header set Pragma \"no-cache\"\n";
+					$header_rules .= "    Header set Cache-Control \"private, no-cache\"\n";
+					break;
 
-			case 'no_store':
-				$header_rules .= "    Header set Pragma \"no-store\"\n";
-				$header_rules .= "    Header set Cache-Control \"no-store\"\n";
-				break;
+				case 'no_store':
+					$header_rules .= "    Header set Pragma \"no-store\"\n";
+					$header_rules .= "    Header set Cache-Control \"no-store\"\n";
+					break;
 			}
 		}
 
@@ -1523,48 +1535,46 @@ private function rules_cache_generate_apache( $config ) {
 	}
 
 	/**
-	 * Generates directives for file cache dir
+	 * Generates cache rules for Nginx-based environments.
+	 *
+	 * @param object $config The configuration object containing settings for cache handling.
 	 *
-	 * @param Config  $config
-	 * @return string
+	 * @return string The generated cache rules for Nginx-based environments.
 	 */
 	private function rules_cache_generate_nginx( $config ) {
-		if ( $config->get_string( 'pgcache.engine') != 'file_generic' ) {
+		if ( 'file_generic' !== $config->get_string( 'pgcache.engine' ) ) {
 			return '';
 		}
 
 		$cache_root = Util_Environment::normalize_path( W3TC_CACHE_PAGE_ENHANCED_DIR );
-		$cache_dir = rtrim( str_replace( Util_Environment::document_root(), '', $cache_root ), '/' );
+		$cache_dir  = rtrim( str_replace( Util_Environment::document_root(), '', $cache_root ), '/' );
 
 		if ( Util_Environment::is_wpmu() ) {
 			$cache_dir = preg_replace( '~/w3tc.*?/~', '/w3tc.*?/', $cache_dir, 1 );
 		}
 
 		$browsercache = $config->get_boolean( 'browsercache.enabled' );
-		$brotli = ( $browsercache && $config->get_boolean( 'browsercache.html.brotli' ) );
-		$compression = ( $browsercache && $config->get_boolean( 'browsercache.html.compression' ) );
+		$brotli       = ( $browsercache && $config->get_boolean( 'browsercache.html.brotli' ) );
+		$compression  = ( $browsercache && $config->get_boolean( 'browsercache.html.compression' ) );
 
-		$common_rules_a = Dispatcher::nginx_rules_for_browsercache_section(
-			$config, 'html', true );
-		$common_rules = '';
-		if ( !empty( $common_rules_a ) ) {
+		$common_rules_a = Dispatcher::nginx_rules_for_browsercache_section( $config, 'html', true );
+		$common_rules   = '';
+		if ( ! empty( $common_rules_a ) ) {
 			$common_rules = '    ' . implode( "\n    ", $common_rules_a ) . "\n";
 		}
 
-		$rules = '';
+		$rules  = '';
 		$rules .= W3TC_MARKER_BEGIN_PGCACHE_CACHE . "\n";
 
 		if ( $brotli ) {
 			$maybe_xml = '';
-			if ($config->get_boolean('pgcache.cache.nginx_handle_xml')) {
-				$maybe_xml = "\n" .
-					"        text/xml xml_br;\n" .
-					"    ";
+			if ( $config->get_boolean( 'pgcache.cache.nginx_handle_xml' ) ) {
+				$maybe_xml = "\n        text/xml xml_br;\n    ";
 			}
 
-			$rules .= "location ~ " . $cache_dir . ".*br$ {\n";
+			$rules .= 'location ~ ' . $cache_dir . ".*br$ {\n";
 			$rules .= "    brotli off;\n";
-			$rules .= "    types {" . $maybe_xml . "}\n";
+			$rules .= '    types {' . $maybe_xml . "}\n";
 			$rules .= "    default_type text/html;\n";
 			$rules .= "    add_header Content-Encoding br;\n";
 			$rules .= $common_rules;
@@ -1573,15 +1583,13 @@ private function rules_cache_generate_nginx( $config ) {
 
 		if ( $compression ) {
 			$maybe_xml = '';
-			if ($config->get_boolean('pgcache.cache.nginx_handle_xml')) {
-				$maybe_xml = "\n" .
-					"        text/xml xml_gzip;\n" .
-					"    ";
+			if ( $config->get_boolean( 'pgcache.cache.nginx_handle_xml' ) ) {
+				$maybe_xml = "\n        text/xml xml_gzip;\n    ";
 			}
 
-			$rules .= "location ~ " . $cache_dir . ".*gzip$ {\n";
+			$rules .= 'location ~ ' . $cache_dir . ".*gzip$ {\n";
 			$rules .= "    gzip off;\n";
-			$rules .= "    types {" . $maybe_xml . "}\n";
+			$rules .= '    types {' . $maybe_xml . "}\n";
 			$rules .= "    default_type text/html;\n";
 			$rules .= "    add_header Content-Encoding gzip;\n";
 			$rules .= $common_rules;
diff --git a/PgCache_Flush.php b/PgCache_Flush.php
index 9849811ad..e8b2617ea 100644
--- a/PgCache_Flush.php
+++ b/PgCache_Flush.php
@@ -1,26 +1,71 @@
 <?php
+/**
+ * File: PgCache_Flush.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * W3 PgCache flushing
+ * Class PgCache_Flush
+ *
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
  */
 class PgCache_Flush extends PgCache_ContentGrabber {
 	/**
-	 * Array of urls to flush
+	 * Queued URLs
+	 *
+	 * @var array
 	 */
 	private $queued_urls = array();
+
+	/**
+	 * Queued groups
+	 *
+	 * @var array
+	 */
 	private $queued_groups = array();
+
+	/**
+	 * Queued post IDs
+	 *
+	 * @var array
+	 */
 	private $queued_post_ids = array();
+
+	/**
+	 * Flush all operation requested flag
+	 *
+	 * @var bool
+	 */
 	private $flush_all_operation_requested = false;
+
+	/**
+	 * Debug purge flag
+	 *
+	 * @var bool
+	 */
 	private $debug_purge = false;
 
+	/**
+	 * Constructor for PgCache_Flush class.
+	 *
+	 * Initializes necessary configuration options and sets up the debug mode for purging.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 		parent::__construct();
 		$this->debug_purge = $this->_config->get_boolean( 'pgcache.debug_purge' );
 	}
 
 	/**
-	 * Flushes all caches
+	 * Flushes all cached pages.
+	 *
+	 * Initiates the flushing of all cached pages and logs the purge if debug mode is enabled.
+	 *
+	 * @return bool Returns true if the flush operation is initiated successfully.
 	 */
 	public function flush() {
 		if ( $this->debug_purge ) {
@@ -28,221 +73,285 @@ public function flush() {
 		}
 
 		$this->flush_all_operation_requested = true;
+
 		return true;
 	}
 
+	/**
+	 * Flushes a specific group of cached pages.
+	 *
+	 * Logs the purge operation for a given group if debug mode is enabled.
+	 *
+	 * @param string $group The cache group to flush.
+	 *
+	 * @return void
+	 */
 	public function flush_group( $group ) {
 		if ( $this->debug_purge ) {
 			Util_Debug::log_purge( 'pagecache', 'flush_group', $group );
 		}
 
-		$this->queued_groups[$group] = '*';
+		$this->queued_groups[ $group ] = '*';
 	}
 
 	/**
-	 * Flushes post cache
+	 * Flushes cache for a specific post.
+	 *
+	 * Identifies post URLs and associated resources to be purged and queues them for flushing. Logs purge details if debug mode is enabled.
+	 *
+	 * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log
 	 *
-	 * @param integer $post_id Post ID.
-	 * @param boolean $force   Force flag (optional).
+	 * @param int|null $post_id Post ID to flush. If null, the post ID is detected automatically.
+	 * @param bool     $force  Optional flag to forcefully flush the post cache even if it is not configured for purging.
+	 *
+	 * @return bool Returns true if the flushing is successfully queued, false if not.
 	 */
 	public function flush_post( $post_id = null, $force = false ) {
-		if ( !$post_id ) {
+		if ( ! $post_id ) {
 			$post_id = Util_Environment::detect_post_id();
 		}
 
-		if ( !$post_id ) {
+		if ( ! $post_id ) {
 			return false;
 		}
 
-		global $wp_rewrite;   // required by many Util_PageUrls methods
+		global $wp_rewrite; // required by many Util_PageUrls methods.
 		if ( empty( $wp_rewrite ) ) {
 			if ( $this->debug_purge ) {
-				Util_Debug::log_purge( 'pagecache', 'flush_post', array(
-					'post_id' => $post_id,
-					'error' => 'Post flush attempt before wp_rewrite initialization. Cant flush cache.'
-				) );
+				Util_Debug::log_purge(
+					'pagecache',
+					'flush_post',
+					array(
+						'post_id' => $post_id,
+						'error'   => 'Post flush attempt before wp_rewrite initialization. Cant flush cache.',
+					)
+				);
 			}
 
-			error_log('Post flush attempt before wp_rewrite initialization. Cant flush cache.');
+			error_log( 'Post flush attempt before wp_rewrite initialization. Cant flush cache.' );
+
 			return false;
 		}
 
-		// prevent multiple calculation of post urls
+		// prevent multiple calculation of post urls.
 		$queued_post_id_key = Util_Environment::blog_id() . '.' . $post_id;
-		if ( isset( $this->queued_post_ids[$queued_post_id_key] ) ) {
+		if ( isset( $this->queued_post_ids[ $queued_post_id_key ] ) ) {
 			return true;
 		}
-		$this->queued_post_ids[$queued_post_id_key] = '*';
 
-		// calculate urls to purge
+		$this->queued_post_ids[ $queued_post_id_key ] = '*';
+
+		// calculate urls to purge.
 		$full_urls = array();
-		$post = get_post( $post_id );
+		$post      = get_post( $post_id );
 		if ( empty( $post ) ) {
 			return true;
 		}
+
 		$is_cpt = Util_Environment::is_custom_post_type( $post );
-		$terms = array();
+		$terms  = array();
 
-		$feeds = $this->_config->get_array( 'pgcache.purge.feed.types' );
+		$feeds            = $this->_config->get_array( 'pgcache.purge.feed.types' );
 		$limit_post_pages = $this->_config->get_integer( 'pgcache.purge.postpages_limit' );
 
-		if ( $this->_config->get_string( 'pgcache.rest' ) == 'cache' ) {
+		if ( 'cache' === $this->_config->get_string( 'pgcache.rest' ) ) {
 			$this->flush_group( 'rest' );
 		}
 
-		if ( $this->_config->get_boolean( 'pgcache.purge.terms' ) ||
-			$this->_config->get_boolean( 'pgcache.purge.feed.terms' ) ) {
+		if (
+			$this->_config->get_boolean( 'pgcache.purge.terms' ) ||
+			$this->_config->get_boolean( 'pgcache.purge.feed.terms' )
+		) {
 			$taxonomies = get_post_taxonomies( $post_id );
-			$terms = wp_get_post_terms( $post_id, $taxonomies );
-			$terms = $this->_append_parent_terms( $terms, $terms );
+			$terms      = wp_get_post_terms( $post_id, $taxonomies );
+			$terms      = $this->_append_parent_terms( $terms, $terms );
 		}
 
 		$front_page = get_option( 'show_on_front' );
 
-		// Home (Frontpage) URL
-		if ( ( $this->_config->get_boolean( 'pgcache.purge.home' ) &&
-				$front_page == 'posts' ) ||
-			$this->_config->get_boolean( 'pgcache.purge.front_page' ) ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_frontpage_urls( $limit_post_pages ) );
+		// Home (Frontpage) URL.
+		if (
+			(
+				$this->_config->get_boolean( 'pgcache.purge.home' ) &&
+				'posts' === $front_page
+			) ||
+			$this->_config->get_boolean( 'pgcache.purge.front_page' )
+		) {
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_frontpage_urls( $limit_post_pages )
+			);
 		}
 
 		// pgcache.purge.home becomes "Posts page" option in settings if home page and blog are set to page(s)
-		// Home (Post page) URL
-		if ( $this->_config->get_boolean( 'pgcache.purge.home' ) &&
-			$front_page != 'posts' &&
-			!$is_cpt ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_postpage_urls( $limit_post_pages ) );
+		// Home (Post page) URL.
+		if (
+			$this->_config->get_boolean( 'pgcache.purge.home' ) &&
+			'posts' !== $front_page &&
+			! $is_cpt
+		) {
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_postpage_urls( $limit_post_pages )
+			);
 		}
 
 		// pgcache.purge.home becomes "Posts page" option in settings if home page and blog are set to page(s)
-		// Custom Post Type Archive URL
-		if ( $this->_config->get_boolean( 'pgcache.purge.home' ) &&
-			$is_cpt ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_cpt_archive_urls( $post_id, $limit_post_pages ) );
+		// Custom Post Type Archive URL.
+		if ( $this->_config->get_boolean( 'pgcache.purge.home' ) && $is_cpt ) {
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_cpt_archive_urls( $post_id, $limit_post_pages )
+			);
 		}
 
-		// Post URL
+		// Post URL.
 		if ( $this->_config->get_boolean( 'pgcache.purge.post' ) || $force ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_post_urls( $post_id ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_post_urls( $post_id )
+			);
 		}
 
-		// Post comments URLs
-		if ( $this->_config->get_boolean( 'pgcache.purge.comments' ) &&
-			function_exists( 'get_comments_pagenum_link' ) ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_post_comments_urls( $post_id ) );
+		// Post comments URLs.
+		if (
+			$this->_config->get_boolean( 'pgcache.purge.comments' ) &&
+			function_exists( 'get_comments_pagenum_link' )
+		) {
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_post_comments_urls( $post_id )
+			);
 		}
 
-		// Post author URLs
+		// Post author URLs.
 		if ( $this->_config->get_boolean( 'pgcache.purge.author' ) && $post ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_post_author_urls( $post->post_author,
-					$limit_post_pages ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_post_author_urls( $post->post_author, $limit_post_pages )
+			);
 		}
 
-		// Post terms URLs
+		// Post terms URLs.
 		if ( $this->_config->get_boolean( 'pgcache.purge.terms' ) ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_post_terms_urls( $terms, $limit_post_pages ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_post_terms_urls( $terms, $limit_post_pages )
+			);
 		}
 
-		// Daily archive URLs
+		// Daily archive URLs.
 		if ( $this->_config->get_boolean( 'pgcache.purge.archive.daily' ) && $post ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_daily_archive_urls( $post, $limit_post_pages ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_daily_archive_urls( $post, $limit_post_pages )
+			);
 		}
 
-		// Monthly archive URLs
+		// Monthly archive URLs.
 		if ( $this->_config->get_boolean( 'pgcache.purge.archive.monthly' ) && $post ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_monthly_archive_urls( $post, $limit_post_pages ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_monthly_archive_urls( $post, $limit_post_pages )
+			);
 		}
 
-		// Yearly archive URLs
+		// Yearly archive URLs.
 		if ( $this->_config->get_boolean( 'pgcache.purge.archive.yearly' ) && $post ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_yearly_archive_urls( $post, $limit_post_pages ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_yearly_archive_urls( $post, $limit_post_pages )
+			);
 		}
 
-		// Feed URLs for posts
-		if ( $this->_config->get_boolean( 'pgcache.purge.feed.blog' ) &&
-		!$is_cpt ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_feed_urls( $feeds, null ) );
+		// Feed URLs for posts.
+		if ( $this->_config->get_boolean( 'pgcache.purge.feed.blog' ) && ! $is_cpt ) {
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_feed_urls( $feeds, null )
+			);
 		}
 
-		// Feed URLs for posts
-		if ( $this->_config->get_boolean( 'pgcache.purge.feed.blog' ) &&
-		$is_cpt ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_feed_urls( $feeds, $post->post_type ) );
+		// Feed URLs for posts.
+		if ( $this->_config->get_boolean( 'pgcache.purge.feed.blog' ) && $is_cpt ) {
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_feed_urls( $feeds, $post->post_type )
+			);
 		}
 
 		if ( $this->_config->get_boolean( 'pgcache.purge.feed.comments' ) ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_feed_comments_urls( $post_id, $feeds ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_feed_comments_urls( $post_id, $feeds )
+			);
 		}
 
 		if ( $this->_config->get_boolean( 'pgcache.purge.feed.author' ) ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_feed_author_urls( $post->post_author, $feeds ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_feed_author_urls( $post->post_author, $feeds )
+			);
 		}
 
 		if ( $this->_config->get_boolean( 'pgcache.purge.feed.terms' ) ) {
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_feed_terms_urls( $terms, $feeds ) );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_feed_terms_urls( $terms, $feeds )
+			);
 		}
 
-		// Purge selected pages
+		// Purge selected pages.
 		if ( $this->_config->get_array( 'pgcache.purge.pages' ) ) {
-			$pages = $this->_config->get_array( 'pgcache.purge.pages' );
-			$full_urls = array_merge( $full_urls,
-				Util_PageUrls::get_pages_urls( $pages ) );
+			$pages     = $this->_config->get_array( 'pgcache.purge.pages' );
+			$full_urls = array_merge(
+				$full_urls,
+				Util_PageUrls::get_pages_urls( $pages )
+			);
 		}
 
-		// add mirror urls
+		// add mirror urls.
 		$full_urls = Util_PageUrls::complement_with_mirror_urls( $full_urls );
-		$full_urls = apply_filters( 'pgcache_flush_post_queued_urls',
-			$full_urls );
+		$full_urls = apply_filters( 'pgcache_flush_post_queued_urls', $full_urls );
 
 		if ( $this->debug_purge ) {
-			Util_Debug::log_purge( 'pagecache', 'flush_post', $post_id,
-				$full_urls );
+			Util_Debug::log_purge( 'pagecache', 'flush_post', $post_id, $full_urls );
 		}
 
-		// Queue flush
+		// Queue flush.
 		if ( count( $full_urls ) ) {
-			foreach ( $full_urls as $url )
-				$this->queued_urls[$url] = '*';
+			foreach ( $full_urls as $url ) {
+				$this->queued_urls[ $url ] = '*';
+			}
 		}
 
 		return true;
 	}
 
 	/**
-	 * Flush a single url
+	 * Flushes the cache for a specific URL.
+	 *
+	 * @param string $url URL of the page to flush.
+	 *
+	 * @return void
 	 */
 	public function flush_url( $url ) {
-		$parts = parse_url( $url );
-		$uri = ( isset( $parts['path'] ) ? $parts['path'] : '' ) .
+		$parts = wp_parse_url( $url );
+		$uri   = ( isset( $parts['path'] ) ? $parts['path'] : '' ) .
 			( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
 		$group = $this->get_cache_group_by_uri( $uri );
 
 		if ( $this->debug_purge ) {
-			Util_Debug::log_purge( 'pagecache', 'flush_url', array(
-				$url, $group ) );
+			Util_Debug::log_purge( 'pagecache', 'flush_url', array( $url, $group ) );
 		}
 
-		$this->queued_urls[$url] = ( empty( $group ) ? '*' : $group );
+		$this->queued_urls[ $url ] = ( empty( $group ) ? '*' : $group );
 	}
 
 	/**
-	 * Performs the actual flush at the end of request processing.
-	 * Duplicate flushes avoided that way.
+	 * Cleans up after a flush operation for posts.
+	 *
+	 * @return int Number of items flushed.
 	 */
 	public function flush_post_cleanup() {
 		if ( $this->flush_all_operation_requested ) {
@@ -251,21 +360,20 @@ public function flush_post_cleanup() {
 			}
 
 			$groups_to_flush = array( '' );
-			if ( $this->_config->get_string( 'pgcache.rest' ) == 'cache' ) {
+			if ( 'cache' === $this->_config->get_string( 'pgcache.rest' ) ) {
 				$groups_to_flush[] = 'rest';
 			}
 
-			$groups_to_flush = apply_filters(
-				'w3tc_pagecache_flush_all_groups', $groups_to_flush );
+			$groups_to_flush = apply_filters( 'w3tc_pagecache_flush_all_groups', $groups_to_flush );
 
 			foreach ( $groups_to_flush as $group ) {
 				$cache = $this->_get_cache( $group );
 				$cache->flush( $group );
 			}
 
-			$count = 999;
+			$count                               = 999;
 			$this->flush_all_operation_requested = false;
-			$this->queued_urls = array();
+			$this->queued_urls                   = array();
 		} else {
 			$count = 0;
 			if ( count( $this->queued_groups ) > 0 ) {
@@ -285,20 +393,21 @@ public function flush_post_cleanup() {
 					self::log( 'pgcache flush ' . $count . ' urls' );
 				}
 
-				$mobile_groups = $this->_get_mobile_groups();
+				$mobile_groups   = $this->_get_mobile_groups();
 				$referrer_groups = $this->_get_referrer_groups();
-				$cookies = $this->_get_cookies();
-				$encryptions = $this->_get_encryptions();
-				$compressions = $this->_get_compressions();
+				$cookies         = $this->_get_cookies();
+				$encryptions     = $this->_get_encryptions();
+				$compressions    = $this->_get_compressions();
 
 				$caches = array(
-					'*' => $this->_get_cache()
+					'*' => $this->_get_cache(),
 				);
 
 				foreach ( $this->queued_urls as $url => $group ) {
-					if ( !isset( $caches[$group] ) ) {
-						$caches[$group] = $this->_get_cache( $group );
+					if ( ! isset( $caches[ $group ] ) ) {
+						$caches[ $group ] = $this->_get_cache( $group );
 					}
+
 					$this->_flush_url(
 						array(
 							'url'             => $url,
@@ -330,9 +439,9 @@ public function flush_post_cleanup() {
 	}
 
 	/**
-	 * Does the actual job - flushing of a single url cache entries
+	 * Flushed a specific URL by generating cache keys for different conditions.
 	 *
-	 * @param array $data Data.
+	 * @param array $data Data required to flush the URL.
 	 *
 	 * @return void
 	 */
@@ -374,12 +483,11 @@ private function _flush_url( $data ) { // phpcs:ignore PSR2.Methods.MethodDeclar
 	}
 
 	/**
-	 * Gets a key extension for "ahead generation" mode.
-	 * Used by AlwaysCached functionality to regenerate content
+	 * Retrieves the ahead generation extension for a specific cache group.
 	 *
-	 * @param string $group Used to differentiate between groups of cache values.
+	 * @param string $group Cache group identifier.
 	 *
-	 * @return array
+	 * @return mixed The ahead generation extension for the group.
 	 */
 	public function get_ahead_generation_extension( $group ) {
 		$cache = $this->_get_cache( $group );
@@ -387,10 +495,10 @@ public function get_ahead_generation_extension( $group ) {
 	}
 
 	/**
-	 * Flushes group with before condition
+	 * Flushes the cache group after ahead generation.
 	 *
-	 * @param string $group Used to differentiate between groups of cache values.
-	 * @param array  $extension Used to set a condition what version to flush.
+	 * @param string $group     Cache group identifier.
+	 * @param mixed  $extension Extension used for the ahead generation.
 	 *
 	 * @return void
 	 */
@@ -400,66 +508,82 @@ public function flush_group_after_ahead_generation( $group, $extension ) {
 	}
 
 	/**
-	 * Returns array of mobile groups
+	 * Retrieves the mobile groups for cache flushing.
+	 *
+	 * @return array List of mobile groups.
 	 */
 	private function _get_mobile_groups() {
 		$mobile_groups = array( '' );
 
 		if ( $this->_mobile ) {
-			$mobile_groups = array_merge( $mobile_groups, array_keys(
-					$this->_mobile->get_groups() ) );
+			$mobile_groups = array_merge( $mobile_groups, array_keys( $this->_mobile->get_groups() ) );
 		}
 
 		return $mobile_groups;
 	}
 
 	/**
-	 * Returns array of referrer groups
+	 * Retrieves the referrer groups for cache flushing.
+	 *
+	 * @return array List of referrer groups.
 	 */
 	private function _get_referrer_groups() {
 		$referrer_groups = array( '' );
 
 		if ( $this->_referrer ) {
-			$referrer_groups = array_merge( $referrer_groups, array_keys(
-					$this->_referrer->get_groups() ) );
+			$referrer_groups = array_merge( $referrer_groups, array_keys( $this->_referrer->get_groups() ) );
 		}
 
 		return $referrer_groups;
 	}
 
 	/**
-	 * Returns array of cookies
+	 * Retrieves the cookies for cache flushing.
+	 *
+	 * @return array List of cookies.
 	 */
 	private function _get_cookies() {
 		$cookies = array( '' );
 
 		if ( $this->_config->get_boolean( 'pgcache.cookiegroups.enabled' ) ) {
-			$cookies = array_merge( $cookies,
-				array_keys( $this->_config->get_array( 'pgcache.cookiegroups.groups' ) ) );
+			$cookies = array_merge( $cookies, array_keys( $this->_config->get_array( 'pgcache.cookiegroups.groups' ) ) );
 		}
 
 		return $cookies;
 	}
 
 	/**
-	 * Returns array of encryptions
+	 * Retrieves the encryption types for cache flushing.
+	 *
+	 * @return array List of encryption types.
 	 */
 	private function _get_encryptions() {
-		$is_https = ( substr( get_home_url(), 0, 5 ) == 'https' );
+		$is_https = ( 'https' === substr( get_home_url(), 0, 5 ) );
 
 		$encryptions = array();
 
-		if ( ! $is_https || $this->_config->get_boolean( 'pgcache.cache.ssl' ) )
+		if ( ! $is_https || $this->_config->get_boolean( 'pgcache.cache.ssl' ) ) {
 			$encryptions[] = '';
-		if ( $is_https || $this->_config->get_boolean( 'pgcache.cache.ssl' ) )
+		}
+
+		if ( $is_https || $this->_config->get_boolean( 'pgcache.cache.ssl' ) ) {
 			$encryptions[] = 'ssl';
+		}
 
 		return $encryptions;
 	}
 
+	/**
+	 * Appends parent terms to the given terms for taxonomy purposes.
+	 *
+	 * @param array $terms                   Initial set of terms.
+	 * @param array $terms_to_check_parents Terms to check for parent relationships.
+	 *
+	 * @return array Modified list of terms with parent terms included.
+	 */
 	private function _append_parent_terms( $terms, $terms_to_check_parents ) {
 		$terms_to_check_parents = $terms;
-		$ids = null;
+		$ids                    = null;
 
 		for ( ;; ) {
 			$parent_ids = array();
@@ -467,40 +591,44 @@ private function _append_parent_terms( $terms, $terms_to_check_parents ) {
 
 			foreach ( $terms_to_check_parents as $term ) {
 				if ( $term->parent ) {
-					$parent_ids[$term->parent] = '*';
-					$taxonomies[$term->taxonomy] = '*';
+					$parent_ids[ $term->parent ]   = '*';
+					$taxonomies[ $term->taxonomy ] = '*';
 				}
 			}
 
-			if ( empty( $parent_ids ) )
+			if ( empty( $parent_ids ) ) {
 				return $terms;
+			}
 
 			if ( is_null( $ids ) ) {
-				// build a map of ids for faster check
+				// build a map of ids for faster check.
 				$ids = array();
-				foreach ( $terms as $term )
-					$ids[$term->term_id] = '*';
+				foreach ( $terms as $term ) {
+					$ids[ $term->term_id ] = '*';
+				}
 			} else {
-				// append last new items to ids map
-				foreach ( $terms_to_check_parents as $term )
-					$ids[$term->term_id] = '*';
+				// append last new items to ids map.
+				foreach ( $terms_to_check_parents as $term ) {
+					$ids[ $term->term_id ] = '*';
+				}
 			}
 
-			// build list to extract
+			// build list to extract.
 			$include_ids = array();
 
 			foreach ( $parent_ids as $id => $v ) {
-				if ( !isset( $ids[$id] ) )
+				if ( ! isset( $ids[ $id ] ) ) {
 					$include_ids[] = $id;
+				}
 			}
 
-			if ( empty( $include_ids ) )
+			if ( empty( $include_ids ) ) {
 				return $terms;
+			}
 
-			$new_terms = get_terms( array_keys( $taxonomies ),
-				array( 'include' => $include_ids ) );
+			$new_terms = get_terms( array_keys( $taxonomies ), array( 'include' => $include_ids ) );
 
-			$terms = array_merge( $terms, $new_terms );
+			$terms                  = array_merge( $terms, $new_terms );
 			$terms_to_check_parents = $new_terms;
 		}
 	}
diff --git a/PgCache_Page.php b/PgCache_Page.php
index f96568440..5454b2a01 100644
--- a/PgCache_Page.php
+++ b/PgCache_Page.php
@@ -1,11 +1,32 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: PgCache_Flush.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class PgCache_Page
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ */
 class PgCache_Page extends Base_Page_Settings {
-	static public function admin_print_scripts_w3tc_pgcache() {
-		wp_enqueue_script( 'w3tc-options-validator', plugins_url( 'pub/js/options-validator.js', W3TC_FILE ), array(), W3TC_VERSION );
+	/**
+	 * Current page
+	 *
+	 * @var string
+	 */
+	protected $_page = 'w3tc_pgcache';
+
+	/**
+	 * Enqueues and registers scripts related to the W3 Total Cache PgCache settings page.
+	 *
+	 * @return void
+	 */
+	public static function admin_print_scripts_w3tc_pgcache() {
+		wp_enqueue_script( 'w3tc-options-validator', plugins_url( 'pub/js/options-validator.js', W3TC_FILE ), array(), W3TC_VERSION, false );
 
 		wp_register_script( 'w3tc-pgcache-qsexempts', plugins_url( 'PgCache_Page_View.js', W3TC_FILE ), array(), W3TC_VERSION, true );
 
@@ -20,38 +41,29 @@ static public function admin_print_scripts_w3tc_pgcache() {
 		wp_enqueue_script( 'w3tc-pgcache-qsexempts' );
 	}
 
-
-
-	/**
-	 * Current page
-	 *
-	 * @var string
-	 */
-	protected $_page = 'w3tc_pgcache';
-
-
 	/**
-	 * Page cache tab
+	 * Displays the view for the PgCache settings page.
 	 *
 	 * @return void
 	 */
-	function view() {
+	public function view() {
 		global $wp_rewrite;
 
 		$feeds = $wp_rewrite->feeds;
 
-		$feed_key = array_search( 'feed', $feeds );
+		$feed_key = array_search( 'feed', $feeds, true );
 
-		if ( $feed_key !== false ) {
-			unset( $feeds[$feed_key] );
+		if ( false !== $feed_key ) {
+			unset( $feeds[ $feed_key ] );
 		}
 
-		$default_feed = get_default_feed();
-		$pgcache_enabled = $this->_config->get_boolean( 'pgcache.enabled' );
+		$default_feed        = get_default_feed();
+		$pgcache_enabled     = $this->_config->get_boolean( 'pgcache.enabled' );
 		$permalink_structure = get_option( 'permalink_structure' );
 
 		$varnish_enabled = $this->_config->get_boolean( 'varnish.enabled' );
-		$cdnfsd_enabled = $this->_config->get_boolean( 'cdnfsd.enabled' );
+		$cdnfsd_enabled  = $this->_config->get_boolean( 'cdnfsd.enabled' );
+
 		include W3TC_INC_DIR . '/options/pgcache.php';
 	}
 }
diff --git a/PgCache_Plugin.php b/PgCache_Plugin.php
index 8813153b0..01c1c21a1 100644
--- a/PgCache_Plugin.php
+++ b/PgCache_Plugin.php
@@ -3,14 +3,16 @@
  * File: PgCache_Plugin.php
  *
  * @package W3TC
- *
- * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
  */
 
 namespace W3TC;
 
 /**
+ * Class PgCache_Plugin
+ *
  * W3 PgCache plugin
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
  */
 class PgCache_Plugin {
 	/**
@@ -21,14 +23,18 @@ class PgCache_Plugin {
 	private $_config = null;
 
 	/**
-	 * Constructor.
+	 * Initializes the PgCache Plugin.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs plugin
+	 * Registers actions, filters, and other operations for the PgCache plugin.
+	 *
+	 * @return void
 	 */
 	public function run() {
 		add_action( 'w3tc_flush_all', array( $this, 'w3tc_flush_posts' ), 1100, 1 );
@@ -73,15 +79,19 @@ public function run() {
 
 		if ( ( $this->_config->get_boolean( 'pgcache.late_init' ) ||
 			$this->_config->get_boolean( 'pgcache.late_caching' ) ) &&
-			! is_admin() ) {
+			! is_admin()
+		) {
 			$o = Dispatcher::component( 'PgCache_ContentGrabber' );
 			add_action( 'init', array( $o, 'delayed_cache_print' ), 99999 );
 		}
 
-		if ( ! $this->_config->get_boolean( 'pgcache.mirrors.enabled' ) &&
-			! Util_Environment::is_wpmu_subdomain() ) {
+		if (
+			! $this->_config->get_boolean( 'pgcache.mirrors.enabled' ) &&
+			! Util_Environment::is_wpmu_subdomain()
+		) {
 			add_action( 'init', array( $this, 'redirect_on_foreign_domain' ) );
 		}
+
 		if ( 'disable' === $this->_config->get_string( 'pgcache.rest' ) ) {
 			// remove XMLRPC edit link.
 			remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
@@ -95,11 +105,11 @@ public function run() {
 	}
 
 	/**
-	 * Get authentication WP Error.
+	 * Handles REST API authentication errors.
 	 *
-	 * @param mixed $result Result.
+	 * @param mixed $result The result of the authentication attempt.
 	 *
-	 * @return WP_Error
+	 * @return \WP_Error Authentication error message.
 	 */
 	public function rest_authentication_errors( $result ) {
 		$error_message = __( 'REST API disabled.', 'w3-total-cache' );
@@ -108,7 +118,7 @@ public function rest_authentication_errors( $result ) {
 	}
 
 	/**
-	 * Does disk cache cleanup
+	 * Performs cache cleanup.
 	 *
 	 * @return void
 	 */
@@ -117,7 +127,7 @@ public function cleanup() {
 	}
 
 	/**
-	 * Prime cache
+	 * Priming process for the page cache.
 	 *
 	 * @return void
 	 */
@@ -126,18 +136,20 @@ public function prime() {
 	}
 
 	/**
-	 * Instantiates worker on demand
+	 * Returns an instance of the PgCache Plugin Admin component.
+	 *
+	 * @return \PgCache_Plugin_Admin The PgCache Plugin Admin instance.
 	 */
 	private function get_admin() {
 		return Dispatcher::component( 'PgCache_Plugin_Admin' );
 	}
 
 	/**
-	 * Cron schedules filter
+	 * Modifies the available cron schedules.
 	 *
-	 * @param array $schedules Schedules.
+	 * @param array $schedules Existing cron schedules.
 	 *
-	 * @return array
+	 * @return array Modified cron schedules.
 	 */
 	public function cron_schedules( $schedules ) {
 		$c               = $this->_config;
@@ -172,11 +184,13 @@ public function cron_schedules( $schedules ) {
 	}
 
 	/**
-	 * Cron job for processing purging page cache.
+	 * Purges the page cache via WP Cron.
 	 *
 	 * @since 2.8.0
 	 *
 	 * @return void
+	 *
+	 * @throws \Exception If there is an error while purging the cache.
 	 */
 	public function w3tc_pgcache_purge_wpcron() {
 		$flusher = Dispatcher::component( 'CacheFlush' );
@@ -184,7 +198,9 @@ public function w3tc_pgcache_purge_wpcron() {
 	}
 
 	/**
-	 * Redirect if foreign domain or WP_CLI.
+	 * Redirects to the correct domain if on a foreign domain.
+	 *
+	 * @return void
 	 */
 	public function redirect_on_foreign_domain() {
 		$request_host = Util_Environment::host();
@@ -225,9 +241,11 @@ public function redirect_on_foreign_domain() {
 	}
 
 	/**
-	 * Get comment cookie lifetime
+	 * Modifies the comment cookie lifetime.
+	 *
+	 * @param int $lifetime The current cookie lifetime.
 	 *
-	 * @param integer $lifetime Comment cookie lifetime.
+	 * @return int The modified cookie lifetime.
 	 */
 	public function comment_cookie_lifetime( $lifetime ) {
 		$l = $this->_config->get_integer( 'pgcache.comment_cookie_ttl' );
@@ -239,14 +257,18 @@ public function comment_cookie_lifetime( $lifetime ) {
 	}
 
 	/**
-	 * Add cookie on logout to circumvent pagecache due to browser cache resulting in 304s
+	 * Handles actions upon user logout.
+	 *
+	 * @return void
 	 */
 	public function on_logout() {
 		setcookie( 'w3tc_logged_out' );
 	}
 
 	/**
-	 * Remove logout cookie on logins
+	 * Handles actions upon user login.
+	 *
+	 * @return void
 	 */
 	public function on_login() {
 		if ( isset( $_COOKIE['w3tc_logged_out'] ) ) {
@@ -255,11 +277,11 @@ public function on_login() {
 	}
 
 	/**
-	 * Primes post.
+	 * Priming the post cache upon post publish or update.
 	 *
-	 * @param integer $post_id Post ID.
-	 * @param object  $post    Post object.
-	 * @param boolean $update  Update flag.
+	 * @param int      $post_id The post ID.
+	 * @param \WP_Post $post    The post object.
+	 * @param bool     $update  Whether the post is being updated.
 	 *
 	 * @return void
 	 */
@@ -289,9 +311,11 @@ function () use ( $post, $update ) {
 	}
 
 	/**
-	 * Retrive usage statistics metrics
+	 * Merges additional page cache metrics into the provided array.
+	 *
+	 * @param array $metrics Array of existing metrics.
 	 *
-	 * @param array $metrics Metrics.
+	 * @return array Merged array of metrics.
 	 */
 	public function w3tc_usage_statistics_metrics( $metrics ) {
 		return array_merge(
@@ -314,11 +338,11 @@ public function w3tc_usage_statistics_metrics( $metrics ) {
 	}
 
 	/**
-	 * Usage Statisitcs sources filter.
+	 * Adds page cache engine information to the statistics sources array based on the configuration.
 	 *
-	 * @param array $sources Sources.
+	 * @param array $sources Existing sources array.
 	 *
-	 * @return array
+	 * @return array Modified sources array with added page cache engine information.
 	 */
 	public function w3tc_usage_statistics_sources( $sources ) {
 		$c = Dispatcher::config();
@@ -348,9 +372,11 @@ public function w3tc_usage_statistics_sources( $sources ) {
 	}
 
 	/**
-	 * Setup admin menu elements
+	 * Adds page cache-related items to the admin bar menu.
+	 *
+	 * @param array $menu_items Existing admin menu items.
 	 *
-	 * @param array $menu_items Menu items.
+	 * @return array Modified admin menu items with page cache options.
 	 */
 	public function w3tc_admin_bar_menu( $menu_items ) {
 		$menu_items['20110.pagecache'] = array(
@@ -379,10 +405,12 @@ public function w3tc_admin_bar_menu( $menu_items ) {
 	}
 
 	/**
-	 * Flush cache group.
+	 * Flushes the specified page cache group.
 	 *
-	 * @param string $group Group name.
-	 * @param array  $extras Additionals to flush.
+	 * @param string $group  The group to flush.
+	 * @param array  $extras Optional extra parameters.
+	 *
+	 * @return mixed Result of the flush operation.
 	 */
 	public function w3tc_flush_group( $group, $extras = array() ) {
 		if ( isset( $extras['only'] ) && 'pagecache' !== (string) $extras['only'] ) {
@@ -396,11 +424,11 @@ public function w3tc_flush_group( $group, $extras = array() ) {
 	}
 
 	/**
-	 * Flushes all caches
+	 * Flushes the entire page cache for posts.
 	 *
-	 * @param array $extras Additionals to flush.
+	 * @param array $extras Optional extra parameters.
 	 *
-	 * @return boolean
+	 * @return mixed Result of the flush operation.
 	 */
 	public function w3tc_flush_posts( $extras = array() ) {
 		if ( isset( $extras['only'] ) && 'pagecache' !== (string) $extras['only'] ) {
@@ -414,12 +442,12 @@ public function w3tc_flush_posts( $extras = array() ) {
 	}
 
 	/**
-	 * Flushes post cache
+	 * Flushes the page cache for a specific post.
 	 *
-	 * @param integer $post_id Post ID.
-	 * @param boolean $force   Force flag (optional).
+	 * @param int  $post_id Post ID to flush.
+	 * @param bool $force   Whether to force the flush.
 	 *
-	 * @return boolean
+	 * @return mixed Result of the flush operation.
 	 */
 	public function w3tc_flush_post( $post_id, $force = false ) {
 		$pgcacheflush = Dispatcher::component( 'PgCache_Flush' );
@@ -429,11 +457,11 @@ public function w3tc_flush_post( $post_id, $force = false ) {
 	}
 
 	/**
-	 * Flushes post cache
+	 * Flushes the page cache for a specific URL.
 	 *
-	 * @param string $url URL.
+	 * @param string $url URL to flush.
 	 *
-	 * @return boolean
+	 * @return mixed Result of the flush operation.
 	 */
 	public function w3tc_flush_url( $url ) {
 		$pgcacheflush = Dispatcher::component( 'PgCache_Flush' );
@@ -442,16 +470,14 @@ public function w3tc_flush_url( $url ) {
 		return $v;
 	}
 
-
-
 	/**
-	 * By default headers are not cached by file_generic
+	 * Sets the page cache header for file_generic engine.
 	 *
-	 * @param mixed  $header New header.
-	 * @param mixed  $header_original Original header.
-	 * @param string $pagecache_engine Engine name.
+	 * @param string $header            The current header.
+	 * @param string $header_original   The original header.
+	 * @param string $pagecache_engine  The page cache engine type.
 	 *
-	 * @return mixed|null
+	 * @return string|null The modified header or null if no change.
 	 */
 	public function w3tc_pagecache_set_header( $header, $header_original, $pagecache_engine ) {
 		if ( 'file_generic' === (string) $pagecache_engine ) {
diff --git a/PgCache_Plugin_Admin.php b/PgCache_Plugin_Admin.php
index a3f988c21..c18b2811f 100644
--- a/PgCache_Plugin_Admin.php
+++ b/PgCache_Plugin_Admin.php
@@ -1,30 +1,42 @@
 <?php
-namespace W3TC;
-
 /**
- * W3 PgCache plugin - administrative interface
+ * File: PgCache_Flush.php
+ *
+ * @package W3TC
  */
 
-
-
+namespace W3TC;
 
 /**
- * class PgCache_Plugin_Admin
+ * Class PgCache_Plugin_Admin
+ *
+ * W3 PgCache plugin - administrative interface
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
  */
 class PgCache_Plugin_Admin {
 	/**
 	 * Config
+	 *
+	 * @var Config
 	 */
 	private $_config = null;
 
-	function __construct() {
+	/**
+	 * Initializes the plugin configuration.
+	 *
+	 * @return void
+	 */
+	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Runs plugin
+	 * Runs the plugin by registering various filters and actions.
+	 *
+	 * @return void
 	 */
-	function run() {
+	public function run() {
 		add_filter( 'w3tc_save_options', array( $this, 'w3tc_save_options' ) );
 
 		$config_labels = new PgCache_ConfigLabels();
@@ -32,8 +44,7 @@ function run() {
 
 		if ( $this->_config->get_boolean( 'pgcache.enabled' ) ) {
 			add_filter( 'w3tc_errors', array( $this, 'w3tc_errors' ) );
-			add_filter( 'w3tc_usage_statistics_summary_from_history', array(
-					$this, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
+			add_filter( 'w3tc_usage_statistics_summary_from_history', array( $this, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
 		}
 
 		// Cache groups.
@@ -48,12 +59,17 @@ function run() {
 		);
 	}
 
-	function cleanup() {
-		// We check to see if we're dealing with a cluster
-		$config = Dispatcher::config();
+	/**
+	 * Cleans up the cache either locally or in a cluster.
+	 *
+	 * @return void
+	 */
+	public function cleanup() {
+		// We check to see if we're dealing with a cluster.
+		$config     = Dispatcher::config();
 		$is_cluster = $config->get_boolean( 'cluster.messagebus.enabled' );
 
-		// If we are, we notify the subscribers. If not, we just cleanup in here
+		// If we are, we notify the subscribers. If not, we just cleanup in here.
 		if ( $is_cluster ) {
 			$this->cleanup_cluster();
 		} else {
@@ -63,56 +79,72 @@ function cleanup() {
 	}
 
 	/**
-	 * Will trigger notifications to be sent to the cluster to 'order' them to clean their page cache.
+	 * Cleans up the cache in a cluster environment.
+	 *
+	 * @return void
 	 */
-	function cleanup_cluster() {
+	public function cleanup_cluster() {
 		$sns_client = Dispatcher::component( 'Enterprise_CacheFlush_MakeSnsEvent' );
 		$sns_client->pgcache_cleanup();
 	}
 
-	function cleanup_local() {
+	/**
+	 * Cleans up the cache in a local environment.
+	 *
+	 * @return void
+	 */
+	public function cleanup_local() {
 		$engine = $this->_config->get_string( 'pgcache.engine' );
 
 		switch ( $engine ) {
-		case 'file':
-			$w3_cache_file_cleaner = new Cache_File_Cleaner( array(
-					'cache_dir' => Util_Environment::cache_blog_dir( 'page' ),
-					'clean_timelimit' => $this->_config->get_integer( 'timelimit.cache_gc' )
-				) );
-
-			$w3_cache_file_cleaner->clean();
-			break;
-
-		case 'file_generic':
-			if ( Util_Environment::blog_id() == 0 )
-				$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
-			else
-				$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . Util_Environment::host();
-
-			$w3_cache_file_cleaner_generic = new Cache_File_Cleaner_Generic( array(
-					'exclude' => array(
-						'.htaccess'
-					),
-					'cache_dir' => $flush_dir,
-					'expire' => $this->_config->get_integer( 'pgcache.lifetime' ),
-					'clean_timelimit' => $this->_config->get_integer( 'timelimit.cache_gc' )
-				) );
+			case 'file':
+				$w3_cache_file_cleaner = new Cache_File_Cleaner(
+					array(
+						'cache_dir'       => Util_Environment::cache_blog_dir( 'page' ),
+						'clean_timelimit' => $this->_config->get_integer( 'timelimit.cache_gc' ),
+					)
+				);
+
+				$w3_cache_file_cleaner->clean();
+				break;
+
+			case 'file_generic':
+				if ( 0 === Util_Environment::blog_id() ) {
+					$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
+				} else {
+					$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . Util_Environment::host();
+				}
 
-			$w3_cache_file_cleaner_generic->clean();
-			break;
+				$w3_cache_file_cleaner_generic = new Cache_File_Cleaner_Generic(
+					array(
+						'exclude'         => array(
+							'.htaccess',
+						),
+						'cache_dir'       => $flush_dir,
+						'expire'          => $this->_config->get_integer( 'pgcache.lifetime' ),
+						'clean_timelimit' => $this->_config->get_integer( 'timelimit.cache_gc' ),
+					)
+				);
+
+				$w3_cache_file_cleaner_generic->clean();
+				break;
 		}
 	}
 
 	/**
-	 * Prime cache
+	 * Primes the cache based on a sitemap or other criteria.
+	 *
+	 * @param int|null      $start        The starting point for priming, or null to use the default.
+	 * @param int|null      $limit        The limit for how many pages to prime, or null for the default limit.
+	 * @param callable|null $log_callback A callback function for logging progress, or null to disable logging.
 	 *
-	 * @param integer $start
 	 * @return void
 	 */
-	function prime( $start = null, $limit = null, $log_callback = null ) {
+	public function prime( $start = null, $limit = null, $log_callback = null ) {
 		if ( is_null( $start ) ) {
 			$start = get_option( 'w3tc_pgcache_prime_offset' );
 		}
+
 		if ( $start < 0 ) {
 			$start = 0;
 		}
@@ -121,25 +153,23 @@ function prime( $start = null, $limit = null, $log_callback = null ) {
 		if ( is_null( $limit ) ) {
 			$limit = $this->_config->get_integer( 'pgcache.prime.limit' );
 		}
+
 		if ( $limit < 1 ) {
 			$limit = 1;
 		}
 
 		$sitemap = $this->_config->get_string( 'pgcache.prime.sitemap' );
 
-		if ( !is_null( $log_callback ) ) {
-			$log_callback( 'Priming from sitemap ' . $sitemap .
-				' entries ' . ( $start + 1 ) . '..' . ( $start + $limit ) );
+		if ( ! is_null( $log_callback ) ) {
+			$log_callback(
+				'Priming from sitemap ' . $sitemap . ' entries ' . ( $start + 1 ) . '..' . ( $start + $limit )
+			);
 		}
 
-		/**
-		 * Parse XML sitemap
-		 */
+		// Parse XML sitemap.
 		$urls = $this->parse_sitemap( $sitemap );
 
-		/**
-		 * Queue URLs
-		 */
+		// Queue URLs.
 		$queue = array_slice( $urls, $start, $limit );
 
 		if ( count( $urls ) > ( $start + $limit ) ) {
@@ -150,36 +180,34 @@ function prime( $start = null, $limit = null, $log_callback = null ) {
 
 		update_option( 'w3tc_pgcache_prime_offset', $next_offset, false );
 
-		/**
-		 * Make HTTP requests and prime cache
-		 */
-
-		// use 'WordPress' since by default we use W3TC-powered by
-		// which blocks caching
+		// Make HTTP requests and prime cache.
+		// Use 'WordPress' since by default we use W3TC-powered by which blocks caching.
 		foreach ( $queue as $url ) {
 			Util_Http::get( $url, array( 'user-agent' => 'WordPress' ) );
 
-			if ( !is_null( $log_callback ) ) {
+			if ( ! is_null( $log_callback ) ) {
 				$log_callback( 'Priming ' . $url );
 			}
 		}
 	}
 
 	/**
-	 * Parses sitemap
+	 * Parses a sitemap URL and returns the list of URLs contained in it.
+	 *
+	 * @param string $url The URL of the sitemap to parse.
 	 *
-	 * @param string  $url
-	 * @return array
+	 * @return array The list of URLs parsed from the sitemap.
 	 */
-	function parse_sitemap( $url ) {
-		if ( !Util_Environment::is_url( $url ) )
+	public function parse_sitemap( $url ) {
+		if ( ! Util_Environment::is_url( $url ) ) {
 			$url = home_url( $url );
+		}
 
-		$urls = array( $url );
+		$urls     = array( $url );
 		$response = Util_Http::get( $url );
 
-		if ( !is_wp_error( $response ) && $response['response']['code'] == 200 ) {
-			$url_matches = null;
+		if ( ! is_wp_error( $response ) && 200 === $response['response']['code'] ) {
+			$url_matches     = null;
 			$sitemap_matches = null;
 
 			if ( preg_match_all( '~<!--.*?-->(*SKIP)(*FAIL)|<sitemap>(.*?)</sitemap>~is', $response['body'], $sitemap_matches ) ) {
@@ -195,12 +223,12 @@ function parse_sitemap( $url ) {
 					}
 				}
 			} elseif ( preg_match_all( '~<!--.*?-->(*SKIP)(*FAIL)|<url>(.*?)</url>~is', $response['body'], $url_matches ) ) {
-				$locs = array();
-				$loc_matches = null;
+				$locs             = array();
+				$loc_matches      = null;
 				$priority_matches = null;
 
 				foreach ( $url_matches[1] as $url_match ) {
-					$loc = '';
+					$loc      = '';
 					$priority = 0.5;
 
 					if ( preg_match( '~<loc>(.*?)</loc>~is', $url_match, $loc_matches ) ) {
@@ -208,11 +236,11 @@ function parse_sitemap( $url ) {
 					}
 
 					if ( preg_match( '~<priority>(.*?)</priority>~is', $url_match, $priority_matches ) ) {
-						$priority = (double) trim( $priority_matches[1] );
+						$priority = (float) trim( $priority_matches[1] );
 					}
 
 					if ( $loc && $priority ) {
-						$locs[$loc] = $priority;
+						$locs[ $loc ] = $priority;
 					}
 				}
 
@@ -220,11 +248,10 @@ function parse_sitemap( $url ) {
 
 				$urls = array_merge( $urls, array_keys( $locs ) );
 			} elseif ( preg_match_all( '~<!--.*?-->(*SKIP)(*FAIL)|<rss[^>]*>(.*?)</rss>~is', $response['body'], $sitemap_matches ) ) {
-
-				// rss feed format
+				// rss feed format.
 				if ( preg_match_all( '~<link[^>]*>(.*?)</link>~is', $response['body'], $url_matches ) ) {
 					foreach ( $url_matches[1] as $url_match ) {
-						$url = trim( $url_match );
+						$url           = trim( $url_match );
 						$cdata_matches = null;
 						if ( preg_match( '~<!\[CDATA\[(.*)\]\]>~is', $url, $cdata_matches ) ) {
 							$url = $cdata_matches[1];
@@ -240,25 +267,33 @@ function parse_sitemap( $url ) {
 	}
 
 	/**
-	 * Makes get requests to url specific to a post, its permalink
+	 * Primes the cache for a given post ID by making HTTP requests for each associated URL.
+	 *
+	 * @param int $post_id The post ID for which to prime the cache.
 	 *
-	 * @param unknown $post_id
-	 * @return boolean returns true on success
+	 * @return bool True on success, false on failure.
 	 */
 	public function prime_post( $post_id ) {
 		$post_urls = Util_PageUrls::get_post_urls( $post_id );
 
-		// Make HTTP requests and prime cache
+		// Make HTTP requests and prime cache.
 		foreach ( $post_urls as $url ) {
 			$result = Util_Http::get( $url, array( 'user-agent' => 'WordPress' ) );
-			if ( is_wp_error( $result ) )
+			if ( is_wp_error( $result ) ) {
 				return false;
+			}
 		}
+
 		return true;
 	}
 
-
-
+	/**
+	 * Saves configuration options and triggers actions based on changes.
+	 *
+	 * @param array $data The configuration data containing both new and old configurations.
+	 *
+	 * @return array The updated configuration data.
+	 */
 	public function w3tc_save_options( $data ) {
 		$new_config = $data['new_config'];
 		$old_config = $data['old_config'];
@@ -267,11 +302,28 @@ public function w3tc_save_options( $data ) {
 			$new_config->set( 'pgcache.cache.nginx_handle_xml', true );
 		}
 
-		if ( ( !$new_config->get_boolean( 'pgcache.cache.home' ) && $old_config->get_boolean( 'pgcache.cache.home' ) ) ||
-			$new_config->get_boolean( 'pgcache.reject.front_page' ) && !$old_config->get_boolean( 'pgcache.reject.front_page' ) ||
-			!$new_config->get_boolean( 'pgcache.cache.feed' ) && $old_config->get_boolean( 'pgcache.cache.feed' ) ||
-			!$new_config->get_boolean( 'pgcache.cache.query' ) && $old_config->get_boolean( 'pgcache.cache.query' ) ||
-			!$new_config->get_boolean( 'pgcache.cache.ssl' ) && $old_config->get_boolean( 'pgcache.cache.ssl' ) ) {
+		if (
+			(
+				! $new_config->get_boolean( 'pgcache.cache.home' ) &&
+				$old_config->get_boolean( 'pgcache.cache.home' )
+			) ||
+			(
+				$new_config->get_boolean( 'pgcache.reject.front_page' ) &&
+				! $old_config->get_boolean( 'pgcache.reject.front_page' )
+			) ||
+			(
+				! $new_config->get_boolean( 'pgcache.cache.feed' ) &&
+				$old_config->get_boolean( 'pgcache.cache.feed' )
+			) ||
+			(
+				! $new_config->get_boolean( 'pgcache.cache.query' ) &&
+				$old_config->get_boolean( 'pgcache.cache.query' )
+			) ||
+			(
+				! $new_config->get_boolean( 'pgcache.cache.ssl' ) &&
+				$old_config->get_boolean( 'pgcache.cache.ssl' )
+			)
+		) {
 			$state = Dispatcher::config_state();
 			$state->set( 'common.show_note.flush_posts_needed', true );
 			$state->save();
@@ -302,70 +354,96 @@ public function w3tc_save_options( $data ) {
 		return $data;
 	}
 
+	/**
+	 * Checks and reports any errors related to the page cache engine (e.g., Memcached).
+	 *
+	 * @param array $errors The array of errors to append to.
+	 *
+	 * @return array The updated array of errors.
+	 */
 	public function w3tc_errors( $errors ) {
 		$c = Dispatcher::config();
 
-		if ( $c->get_string( 'pgcache.engine' ) == 'memcached' ) {
-			$memcached_servers = $c->get_array( 'pgcache.memcached.servers' );
+		if ( 'memcached' === $c->get_string( 'pgcache.engine' ) ) {
+			$memcached_servers         = $c->get_array( 'pgcache.memcached.servers' );
 			$memcached_binary_protocol = $c->get_boolean( 'pgcache.memcached.binary_protocol' );
-			$memcached_username = $c->get_string( 'pgcache.memcached.username' );
-			$memcached_password = $c->get_string( 'pgcache.memcached.password' );
-
-			if ( !Util_Installed::is_memcache_available( $memcached_servers, $memcached_binary_protocol, $memcached_username, $memcached_password ) ) {
-				if ( !isset( $errors['memcache_not_responding.details'] ) )
+			$memcached_username        = $c->get_string( 'pgcache.memcached.username' );
+			$memcached_password        = $c->get_string( 'pgcache.memcached.password' );
+
+			if (
+				! Util_Installed::is_memcache_available(
+					$memcached_servers,
+					$memcached_binary_protocol,
+					$memcached_username,
+					$memcached_password
+				)
+			) {
+				if ( ! isset( $errors['memcache_not_responding.details'] ) ) {
 					$errors['memcache_not_responding.details'] = array();
+				}
 
 				$errors['memcache_not_responding.details'][] = sprintf(
-					__( 'Page Cache: %s.', 'w3-total-cache' ),
-					implode( ', ', $memcached_servers ) );
+					// Translators: 1 memcached servers.
+					__(
+						'Page Cache: %1$s.',
+						'w3-total-cache'
+					),
+					implode( ', ', $memcached_servers )
+				);
 			}
 		}
 
 		return $errors;
 	}
 
+	/**
+	 * Summarizes usage statistics from historical data, including cache size and request hits.
+	 *
+	 * @param array $summary The summary data to update.
+	 * @param array $history The historical usage data to process.
+	 *
+	 * @return array The updated summary with additional page cache statistics.
+	 */
 	public function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
-		// total size
-		$g = Dispatcher::component( 'PgCache_ContentGrabber' );
+		// total size.
+		$g         = Dispatcher::component( 'PgCache_ContentGrabber' );
 		$pagecache = array();
 
-		$e = $this->_config->get_string( 'pgcache.engine' );
+		$e                        = $this->_config->get_string( 'pgcache.engine' );
 		$pagecache['engine_name'] = Cache::engine_name( $e );
-		$file_generic = ( $e == 'file_generic' );
-
+		$file_generic             = ( 'file_generic' === $e );
 
-		// build metrics in php block
-		if ( !isset( $summary['php'] ) ) {
+		// build metrics in php block.
+		if ( ! isset( $summary['php'] ) ) {
 			$summary['php'] = array();
 		}
 
-		Util_UsageStatistics::sum_by_prefix_positive( $summary['php'],
-			$history, 'php_requests_pagecache' );
+		Util_UsageStatistics::sum_by_prefix_positive( $summary['php'], $history, 'php_requests_pagecache' );
 
-		// need to return cache size
+		// need to return cache size.
 		if ( $file_generic ) {
-			list( $v, $should_count ) =
-				Util_UsageStatistics::get_or_init_size_transient(
-				'w3tc_ustats_pagecache_size', $summary );
+			list( $v, $should_count ) = Util_UsageStatistics::get_or_init_size_transient(
+				'w3tc_ustats_pagecache_size',
+				$summary
+			);
+
 			if ( $should_count ) {
-				$size = $g->get_cache_stats_size( $summary['timeout_time'] );
-				$v['size_used'] = Util_UsageStatistics::bytes_to_size2(
-					$size, 'bytes' );
-				$v['items'] = Util_UsageStatistics::integer2(
-					$size, 'items' );
+				$size           = $g->get_cache_stats_size( $summary['timeout_time'] );
+				$v['size_used'] = Util_UsageStatistics::bytes_to_size2( $size, 'bytes' );
+				$v['items']     = Util_UsageStatistics::integer2( $size, 'items' );
 
 				set_transient( 'w3tc_ustats_pagecache_size', $v, 55 );
 			}
 
 			if ( isset( $v['size_used'] ) ) {
 				$pagecache['size_used'] = $v['size_used'];
-				$pagecache['items'] = $v['items'];
+				$pagecache['items']     = $v['items'];
 			}
 
 			if ( isset( $summary['access_log'] ) ) {
-				$pagecache['requests'] = $summary['access_log']['dynamic_requests_total_v'];
+				$pagecache['requests']     = $summary['access_log']['dynamic_requests_total_v'];
 				$pagecache['requests_hit'] = $pagecache['requests'] - $summary['php']['php_requests_v'];
-				if ($pagecache['requests_hit'] < 0) {
+				if ( $pagecache['requests_hit'] < 0 ) {
 					$pagecache['requests_hit'] = 0;
 				}
 			}
@@ -374,32 +452,31 @@ public function w3tc_usage_statistics_summary_from_history( $summary, $history )
 			$pagecache['requests']     = isset( $summary['php']['php_requests_v'] ) ? $summary['php']['php_requests_v'] : 0;
 			$pagecache['requests_hit'] = isset( $summary['php']['php_requests_pagecache_hit'] ) ? $summary['php']['php_requests_pagecache_hit'] : 0;
 
-			$requests_time_ms = Util_UsageStatistics::sum( $history,
-				'pagecache_requests_time_10ms' ) * 10;
-			$php_requests = Util_UsageStatistics::sum( $history,
-				'php_requests' );
+			$requests_time_ms = Util_UsageStatistics::sum( $history, 'pagecache_requests_time_10ms' ) * 10;
+			$php_requests     = Util_UsageStatistics::sum( $history, 'php_requests' );
 
 			if ( $php_requests > 0 ) {
-				$pagecache['request_time_ms'] = Util_UsageStatistics::integer(
-					$requests_time_ms / $php_requests );
+				$pagecache['request_time_ms'] = Util_UsageStatistics::integer( $requests_time_ms / $php_requests );
 			}
 		}
 
-		if ( $e == 'memcached' ) {
+		if ( 'memcached' === $e ) {
 			$pagecache['size_percent'] = $summary['memcached']['size_percent'];
 		}
-		if ( isset($pagecache['requests_hit'] ) ) {
+
+		if ( isset( $pagecache['requests_hit'] ) ) {
 			$pagecache['requests_hit_rate'] = Util_UsageStatistics::percent(
-				$pagecache['requests_hit'], $pagecache['requests'] );
+				$pagecache['requests_hit'],
+				$pagecache['requests']
+			);
 		}
 
-		if ( !isset( $summary['php']['php_requests_pagecache_hit'] ) ) {
+		if ( ! isset( $summary['php']['php_requests_pagecache_hit'] ) ) {
 			$summary['php']['php_requests_pagecache_hit'] = 0;
 		}
 
 		if ( isset( $summary['php']['php_requests_v'] ) ) {
-			$v = $summary['php']['php_requests_v'] -
-				$summary['php']['php_requests_pagecache_hit'];
+			$v = $summary['php']['php_requests_v'] - $summary['php']['php_requests_pagecache_hit'];
 			if ( $v < 0 ) {
 				$v = 0;
 			}
@@ -408,11 +485,12 @@ public function w3tc_usage_statistics_summary_from_history( $summary, $history )
 		}
 
 		if ( isset( $pagecache['requests'] ) ) {
-			$pagecache['requests_per_second'] =
-				Util_UsageStatistics::value_per_period_seconds( $pagecache['requests'], $summary );
+			$pagecache['requests_per_second'] = Util_UsageStatistics::value_per_period_seconds(
+				$pagecache['requests'],
+				$summary
+			);
 		}
 
-
 		$summary['pagecache'] = $pagecache;
 
 		return $summary;
diff --git a/PgCache_QsExempts.php b/PgCache_QsExempts.php
index 2a42e5f4b..c795d5eb4 100644
--- a/PgCache_QsExempts.php
+++ b/PgCache_QsExempts.php
@@ -12,7 +12,9 @@
  */
 class PgCache_QsExempts {
 	/**
-	 * Returns list of default accepted QS key/values to be ignored when generating the Page Cache.
+	 * Retrieves an array of query string parameters that are exempt from processing.
+	 *
+	 * @return array List of query string parameter names that are exempt.
 	 */
 	public static function get_qs_exempts() {
 		return array(
diff --git a/Root_AdminActions.php b/Root_AdminActions.php
index 82f2e17d2..feeb66b94 100644
--- a/Root_AdminActions.php
+++ b/Root_AdminActions.php
@@ -1,73 +1,124 @@
 <?php
+/**
+ * File: Root_AdminActions.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Root_AdminActions
+ *
+ * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
+ */
 class Root_AdminActions {
+	/**
+	 * Constructor for Root_AdminActions class.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 	}
 
+	/**
+	 * Executes an action based on the given action string.
+	 *
+	 * @param string $action The action to execute.
+	 *
+	 * @return void
+	 *
+	 * @throws \Exception If the action does not exist.
+	 */
 	public function execute( $action ) {
-		$handler_class = $this->_get_handler( $action );
+		$handler_class          = $this->_get_handler( $action );
 		$handler_class_fullname = '\\W3TC\\' . $handler_class;
-		$handler_object = new $handler_class_fullname;
+		$handler_object         = new $handler_class_fullname();
 
 		$action_details = explode( '~', $action );
 
 		if ( count( $action_details ) > 1 ) {
-			// action is in form "action~parameter"
+			// action is in form "action~parameter".
 			$method = $action_details[0];
 			if ( method_exists( $handler_object, $method ) ) {
 				$handler_object->$method( $action_details[1] );
 				return;
 			}
 		} else {
-			// regular action
+			// regular action.
 			if ( method_exists( $handler_object, $action ) ) {
 				$handler_object->$action();
 				return;
 			}
 		}
 
-		throw new \Exception( sprintf( __( 'action %s does not exist' ), $action ) );
+		throw new \Exception(
+			sprintf(
+				// Translators: 1 action name.
+				__(
+					'action %1$s does not exist',
+					'w3-total-cache'
+				),
+				$action
+			)
+		);
 	}
 
+	/**
+	 * Checks if an action exists.
+	 *
+	 * @param string $action The action to check.
+	 *
+	 * @return bool True if the action exists, false otherwise.
+	 */
 	public function exists( $action ) {
-		$handler =  $this->_get_handler( $action );
-		return $handler != '';
+		$handler = $this->_get_handler( $action );
+		return '' !== $handler;
 	}
 
+	/**
+	 * Retrieves the handler class for the given action.
+	 *
+	 * @param string $action The action to retrieve the handler for.
+	 *
+	 * @return string|null The handler class name or null if no handler exists.
+	 */
 	private function _get_handler( $action ) {
 		static $handlers = null;
 		if ( is_null( $handlers ) ) {
 			$handlers = array(
-				'boldgrid' => 'Generic_WidgetBoldGrid_AdminActions',
+				'boldgrid'         => 'Generic_WidgetBoldGrid_AdminActions',
 				'cdn_google_drive' => 'Cdn_GoogleDrive_AdminActions',
-				'cdn' => 'Cdn_AdminActions',
-				'config' => 'Generic_AdminActions_Config',
-				'default' => 'Generic_AdminActions_Default',
-				'extensions' => 'Extensions_AdminActions',
-				'flush' => 'Generic_AdminActions_Flush',
-				'licensing' => 'Licensing_AdminActions',
-				'support' => 'Support_AdminActions',
-				'test' => 'Generic_AdminActions_Test',
-				'ustats' => 'UsageStatistics_AdminActions'
+				'cdn'              => 'Cdn_AdminActions',
+				'config'           => 'Generic_AdminActions_Config',
+				'default'          => 'Generic_AdminActions_Default',
+				'extensions'       => 'Extensions_AdminActions',
+				'flush'            => 'Generic_AdminActions_Flush',
+				'licensing'        => 'Licensing_AdminActions',
+				'support'          => 'Support_AdminActions',
+				'test'             => 'Generic_AdminActions_Test',
+				'ustats'           => 'UsageStatistics_AdminActions',
 			);
 			$handlers = apply_filters( 'w3tc_admin_actions', $handlers );
 		}
 
-		if ( $action == 'w3tc_save_options' )
+		if ( 'w3tc_save_options' === $action ) {
 			return $handlers['default'];
+		}
 
 		$candidate_prefix = '';
-		$candidate_class = '';
+		$candidate_class  = '';
 
 		foreach ( $handlers as $prefix => $class ) {
 			$v1 = "w3tc_$prefix";
 			$v2 = "w3tc_save_$prefix";
 
-			if ( substr( $action, 0, strlen( $v1 ) ) == $v1 ||
-				substr( $action, 0, strlen( $v2 ) ) == $v2 ) {
+			if (
+				substr( $action, 0, strlen( $v1 ) ) === $v1 ||
+				substr( $action, 0, strlen( $v2 ) ) === $v2
+			) {
 				if ( strlen( $candidate_prefix ) < strlen( $prefix ) ) {
-					$candidate_class = $class;
+					$candidate_class  = $class;
 					$candidate_prefix = $prefix;
 				}
 			}
diff --git a/Root_AdminActivation.php b/Root_AdminActivation.php
index 94c2dd7de..805a57e75 100644
--- a/Root_AdminActivation.php
+++ b/Root_AdminActivation.php
@@ -1,27 +1,43 @@
 <?php
-namespace W3TC;
-
 /**
- * W3 Total Cache plugin
+ * File: Root_AdminActions.php
+ *
+ * @package W3TC
  */
 
+namespace W3TC;
+
 /**
  * Class Root_AdminActivation
+ *
+ * W3 Total Cache plugin
+ *
+ * phpcs:disable Generic.CodeAnalysis.EmptyStatement
  */
 class Root_AdminActivation {
 	/**
-	 * Activate plugin action
+	 * Activates the plugin and performs necessary configuration tasks.
+	 *
+	 * @param bool $network_wide Whether the plugin is being activated network-wide in a multisite environment.
 	 *
-	 * @param bool $network_wide
 	 * @return void
+	 *
+	 * @throws \Exception If an error occurs during activation.
 	 */
 	public static function activate( $network_wide ) {
 		// Decline non-network activation at WPMU.
 		if ( Util_Environment::is_wpmu() ) {
 			if ( $network_wide ) {
 				// We are in network activation.
-			} else if ( Util_Request::get_string( 'action' ) == 'error_scrape' &&
-					strpos( isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '', '/network/' ) !== false ) {
+			} elseif (
+				'error_scrape' === Util_Request::get_string( 'action' ) &&
+				false !== strpos(
+					isset( $_SERVER['REQUEST_URI'] ) ?
+						sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) :
+						'',
+					'/network/'
+				)
+			) {
 				// Workaround for error_scrape page called after error really we are in network activation and going to throw some error.
 			} else {
 				echo wp_kses(
@@ -78,9 +94,11 @@ public static function activate( $network_wide ) {
 	}
 
 	/**
-	 * Deactivate plugin action
+	 * Deactivates the plugin and cleans up necessary tasks.
 	 *
 	 * @return void
+	 *
+	 * @throws \Exception If an error occurs during deactivation.
 	 */
 	public static function deactivate() {
 		try {
@@ -139,6 +157,7 @@ public static function deactivate() {
 
 		// Delete cron events.
 		require_once __DIR__ . '/Extension_ImageService_Cron.php';
+
 		Extension_ImageService_Cron::delete_cron();
 
 		// Check if data cleanup is required.
diff --git a/Root_AdminMenu.php b/Root_AdminMenu.php
index 02d19d860..70c49efeb 100644
--- a/Root_AdminMenu.php
+++ b/Root_AdminMenu.php
@@ -26,16 +26,18 @@ class Root_AdminMenu {
 	private $_config; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
 
 	/**
-	 * Constructor.
+	 * Constructor to initialize the Root_AdminMenu class and configuration.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
 	/**
-	 * Generate menu array.
+	 * Generates an array of menu items for the admin menu.
 	 *
-	 * @return array
+	 * @return array Associative array of menu items with details.
 	 */
 	public function generate_menu_array() {
 		$pages = array(
@@ -115,7 +117,7 @@ public function generate_menu_array() {
 				'visible_always' => true,
 				'order'          => 1200,
 			),
-			'w3tc_pagespeed'          => array(
+			'w3tc_pagespeed'        => array(
 				'page_title'     => __( 'Google PageSpeed', 'w3-total-cache' ),
 				'menu_text'      => __( 'Google PageSpeed', 'w3-total-cache' ),
 				'visible_always' => true,
@@ -147,10 +149,11 @@ public function generate_menu_array() {
 	}
 
 	/**
-	 * Generate menu.
+	 * Generates the admin menu and submenu pages.
+	 *
+	 * @param string $base_capability Capability required to access the menu.
 	 *
-	 * @param  string $base_capability Base compatibility.
-	 * @return array
+	 * @return array List of submenu page hooks.
 	 */
 	public function generate( $base_capability ) {
 		$pages = $this->generate_menu_array();
@@ -203,7 +206,9 @@ function( $a, $b ) {
 	}
 
 	/**
-	 * Options page.
+	 * Handles the display of the options page.
+	 *
+	 * @return void
 	 */
 	public function options() {
 		$this->_page = Util_Request::get_string( 'page' );
@@ -212,18 +217,14 @@ public function options() {
 			$this->_page = 'w3tc_dashboard';
 		}
 
-		/*
-		 * Hidden pages.
-		 */
+		// Hidden pages.
 		if ( ! empty( Util_Request::get_string( 'w3tc_dbcluster_config' ) ) ) {
 			$options_dbcache = new DbCache_Page();
 			$options_dbcache->dbcluster_config();
 			return;
 		}
 
-		/**
-		 * Show tab.
-		 */
+		// Show tab.
 		switch ( $this->_page ) {
 			case 'w3tc_dashboard':
 				$options_dashboard = new Generic_Page_Dashboard();
diff --git a/Root_Environment.php b/Root_Environment.php
index aba13f4b4..533d5a3b5 100644
--- a/Root_Environment.php
+++ b/Root_Environment.php
@@ -1,28 +1,38 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: Root_Environment.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
- * class Root_Environment
+ * Class Root_Environment
  */
 class Root_Environment {
 	/**
-	 * Fixes environment
+	 * Fixes the environment configuration in the WordPress admin panel.
+	 *
+	 * @param object $config            Configuration object to be applied during the fix process.
+	 * @param bool   $force_all_checks  Whether to force all environment checks.
+	 *
+	 * @return void
 	 *
-	 * @param Config  $config
-	 * @throws Util_Environment_Exceptions
+	 * @throws Util_Environment_Exceptions If one or more handlers fail during the fix process.
 	 */
-	function fix_in_wpadmin( $config, $force_all_checks = false ) {
-		$exs = new Util_Environment_Exceptions();
+	public function fix_in_wpadmin( $config, $force_all_checks = false ) {
+		$exs          = new Util_Environment_Exceptions();
 		$fix_on_event = false;
-		if ( Util_Environment::is_wpmu() && Util_Environment::blog_id() != 0 ) {
-			if ( get_transient( 'w3tc_config_changes' ) != ( $md5_string = $config->get_md5() ) ) {
+		if ( Util_Environment::is_wpmu() && Util_Environment::blog_id() !== 0 ) {
+			$md5_string = $config->get_md5();
+			if ( get_transient( 'w3tc_config_changes' ) !== $md5_string ) {
 				$fix_on_event = true;
 				set_transient( 'w3tc_config_changes', $md5_string, 3600 );
 			}
 		}
-		// call plugin-related handlers
+
+		// call plugin-related handlers.
 		foreach ( $this->get_handlers() as $h ) {
 			try {
 				$h->fix_on_wpadmin_request( $config, $force_all_checks );
@@ -35,25 +45,31 @@ function fix_in_wpadmin( $config, $force_all_checks = false ) {
 		}
 
 		try {
-			do_action( 'w3tc_environment_fix_on_wpadmin_request',
-				$config, $force_all_checks );
+			do_action( 'w3tc_environment_fix_on_wpadmin_request', $config, $force_all_checks );
 		} catch ( Util_Environment_Exceptions $ex ) {
 			$exs->push( $ex );
 		}
 
-		if ( count( $exs->exceptions() ) > 0 )
+		if ( count( $exs->exceptions() ) > 0 ) {
 			throw $exs;
+		}
 	}
 
 	/**
-	 * Fixes environment once event occurs
+	 * Fixes the environment configuration based on specific events.
+	 *
+	 * @param object      $config     Configuration object to be applied during the fix process.
+	 * @param string      $event      Name of the triggering event.
+	 * @param object|null $old_config Optional old configuration object for comparison.
 	 *
-	 * @throws Util_Environment_Exceptions
+	 * @return void
+	 *
+	 * @throws Util_Environment_Exceptions If one or more handlers fail during the fix process.
 	 */
 	public function fix_on_event( $config, $event, $old_config = null ) {
 		$exs = new Util_Environment_Exceptions();
 
-		// call plugin-related handlers
+		// call plugin-related handlers.
 		foreach ( $this->get_handlers() as $h ) {
 			try {
 				$h->fix_on_event( $config, $event );
@@ -63,26 +79,27 @@ public function fix_on_event( $config, $event, $old_config = null ) {
 		}
 
 		try {
-			do_action( 'w3tc_environment_fix_on_event',
-				$config, $event );
+			do_action( 'w3tc_environment_fix_on_event', $config, $event );
 		} catch ( Util_Environment_Exceptions $ex ) {
 			$exs->push( $ex );
 		}
 
-		if ( count( $exs->exceptions() ) > 0 )
+		if ( count( $exs->exceptions() ) > 0 ) {
 			throw $exs;
+		}
 	}
 
 	/**
-	 * Fixes environment after plugin deactivation
+	 * Fixes the environment configuration after deactivation.
 	 *
-	 * @param Config  $config
-	 * @throws Util_Environment_Exceptions
+	 * @return void
+	 *
+	 * @throws Util_Environment_Exceptions If one or more handlers fail during the fix process.
 	 */
 	public function fix_after_deactivation() {
 		$exs = new Util_Environment_Exceptions();
 
-		// call plugin-related handlers
+		// call plugin-related handlers.
 		foreach ( $this->get_handlers() as $h ) {
 			try {
 				$h->fix_after_deactivation();
@@ -97,15 +114,17 @@ public function fix_after_deactivation() {
 			$exs->push( $ex );
 		}
 
-		if ( count( $exs->exceptions() ) > 0 )
+		if ( count( $exs->exceptions() ) > 0 ) {
 			throw $exs;
+		}
 	}
 
 	/**
-	 * Returns an array[filename]=rules of rules for .htaccess or nginx files
+	 * Retrieves the rules required for the environment configuration.
+	 *
+	 * @param object $config Configuration object used to determine required rules.
 	 *
-	 * @param Config  $config
-	 * @return array
+	 * @return array Array of descriptors for required rewrite rules.
 	 */
 	public function get_required_rules( $config ) {
 		$required_rules = array();
@@ -119,53 +138,54 @@ public function get_required_rules( $config ) {
 			}
 		}
 
-		$required_rules = apply_filters( 'w3tc_environment_get_required_rules',
-			$required_rules, $config );
-
+		$required_rules = apply_filters( 'w3tc_environment_get_required_rules', $required_rules, $config );
 
 		$rewrite_rules_descriptors = array();
 
 		foreach ( $required_rules as $descriptor ) {
 			$filename = $descriptor['filename'];
 
-			if ( isset( $rewrite_rules_descriptors[$filename] ) )
-				$content = $rewrite_rules_descriptors[$filename]['content'];
-			else
+			if ( isset( $rewrite_rules_descriptors[ $filename ] ) ) {
+				$content = $rewrite_rules_descriptors[ $filename ]['content'];
+			} else {
 				$content = array();
+			}
 
-			if ( !isset( $descriptor['position'] ) )
+			if ( ! isset( $descriptor['position'] ) ) {
 				$content[] = $descriptor['content'];
-			else {
+			} else {
 				$position = $descriptor['position'];
 
-				if ( isset( $content[$position] ) )
-					$content[$position] .= $descriptor['content'];
-				else
-					$content[$position] = $descriptor['content'];
+				if ( isset( $content[ $position ] ) ) {
+					$content[ $position ] .= $descriptor['content'];
+				} else {
+					$content[ $position ] = $descriptor['content'];
+				}
 			}
 
-			$rewrite_rules_descriptors[$filename] = array(
+			$rewrite_rules_descriptors[ $filename ] = array(
 				'filename' => $filename,
-				'content' => $content
+				'content'  => $content,
 			);
 		}
 
 		$rewrite_rules_descriptors_out = array();
 		foreach ( $rewrite_rules_descriptors as $filename => $descriptor ) {
-			$rewrite_rules_descriptors_out[$filename] = array(
+			$rewrite_rules_descriptors_out[ $filename ] = array(
 				'filename' => $filename,
-				'content' => implode( '', $descriptor['content'] )
+				'content'  => implode( '', $descriptor['content'] ),
 			);
 		}
+
 		ksort( $rewrite_rules_descriptors_out );
+
 		return $rewrite_rules_descriptors_out;
 	}
 
 	/**
-	 * Returns plugin-related environment handlers
+	 * Retrieves the list of environment handlers.
 	 *
-	 * @param Config  $config
-	 * @return array
+	 * @return array Array of handler objects for managing environment configurations.
 	 */
 	private function get_handlers() {
 		$a = array(
@@ -183,24 +203,31 @@ private function get_handlers() {
 		return $a;
 	}
 
+	/**
+	 * Retrieves additional instructions for the environment configuration.
+	 *
+	 * @param object $config Configuration object used to determine additional instructions.
+	 *
+	 * @return array Array of descriptors for additional instructions, grouped by area.
+	 */
 	public function get_other_instructions( $config ) {
 		$instructions_descriptors = array();
 
 		foreach ( $this->get_handlers() as $h ) {
 			if ( method_exists( $h, 'get_instructions' ) ) {
 				$instructions = $h->get_instructions( $config );
-				if ( !is_null( $instructions ) ) {
+				if ( ! is_null( $instructions ) ) {
 					foreach ( $instructions as $descriptor ) {
-						$area = $descriptor['area'];
-						$instructions_descriptors[$area][] = array(
-							'title' => $descriptor['title'],
-							'content' => $descriptor['content']
+						$area                                = $descriptor['area'];
+						$instructions_descriptors[ $area ][] = array(
+							'title'   => $descriptor['title'],
+							'content' => $descriptor['content'],
 						);
 					}
 				}
 			}
-
 		}
+
 		return $instructions_descriptors;
 	}
 
diff --git a/Root_Loader.php b/Root_Loader.php
index 914c7359d..28dc9d178 100644
--- a/Root_Loader.php
+++ b/Root_Loader.php
@@ -28,7 +28,11 @@ class Root_Loader {
 	private $_loaded_extensions = array();
 
 	/**
-	 * Constructor.
+	 * Constructor for the Root_Loader class.
+	 *
+	 * Initializes and loads the required plugins based on the current configuration.
+	 *
+	 * @return void
 	 */
 	public function __construct() {
 		$c = Dispatcher::config();
@@ -129,7 +133,11 @@ public function __construct() {
 	}
 
 	/**
-	 * Run plugins
+	 * Runs all loaded plugins and initializes extensions.
+	 *
+	 * Executes the `on_w3tc_plugins_loaded` method if it exists in `$GLOBALS['wpdb']`.
+	 *
+	 * @return void
 	 */
 	public function run() {
 		foreach ( $this->_loaded_plugins as $plugin ) {
@@ -145,23 +153,31 @@ public function run() {
 	}
 
 	/**
-	 * Activation action hook
+	 * Activates the plugin, performing necessary setup actions.
+	 *
+	 * @param bool $network_wide Whether the activation is for a network-wide installation.
 	 *
-	 * @param bool $network_wide Network wide flag.
+	 * @return void
 	 */
 	public function activate( $network_wide ) {
 		Root_AdminActivation::activate( $network_wide );
 	}
 
 	/**
-	 * Deactivation action hook
+	 * Deactivates the plugin, performing necessary cleanup actions.
+	 *
+	 * @return void
 	 */
 	public function deactivate() {
 		Root_AdminActivation::deactivate();
 	}
 
 	/**
-	 * Loads extensions stored in config
+	 * Loads and runs the active extensions for both frontend and admin environments.
+	 *
+	 * Includes extension files and triggers extension-related actions.
+	 *
+	 * @return void
 	 */
 	public function run_extensions() {
 		$c          = Dispatcher::config();
@@ -214,9 +230,9 @@ public function run_extensions() {
 	}
 
 	/**
-	 * Modify query object to hide Image Service converted images.
+	 * Modifies the main query to exclude Image Service converted images from the media library.
 	 *
-	 * @param object $query WP_Query object.
+	 * @param \WP_Query $query The main query object.
 	 *
 	 * @return void
 	 */
@@ -242,11 +258,11 @@ public function w3tc_modify_query_obj( $query ) {
 	}
 
 	/**
-	 * Filter AJAX query arguments for attachements to hide Image Service converted images.
+	 * Filters AJAX attachment query arguments to exclude Image Service converted images.
 	 *
-	 * @param string $args arguments.
+	 * @param array $args The query arguments for AJAX attachments.
 	 *
-	 * @return void
+	 * @return array Modified query arguments.
 	 */
 	public function w3tc_filter_ajax_args( $args ) {
 		if ( ! is_admin() ) {
diff --git a/Support_AdminActions.php b/Support_AdminActions.php
index 346188ad2..7fdca40c9 100644
--- a/Support_AdminActions.php
+++ b/Support_AdminActions.php
@@ -1,90 +1,91 @@
 <?php
+/**
+ * File: Support_AdminActions.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Support_AdminActions
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
+ * phpcs:disable WordPress.DB.DirectDatabaseQuery
+ */
 class Support_AdminActions {
 	/**
-	 * Send support request action
+	 * Sends support details to a remote server.
+	 *
+	 * phpcs:disable WordPress.CodeAnalysis.AssignmentInCondition
+	 * phpcs:disable Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
+	 * phpcs:disable WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_phpinfo
 	 *
 	 * @return void
 	 */
-	function w3tc_support_send_details() {
+	public function w3tc_support_send_details() {
 		$c = Dispatcher::config();
 
 		$post = array();
 
-		foreach ( $_GET as $p => $v )
-			$post[$p] = Util_Request::get( $p );
+		foreach ( $_GET as $p => $v ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+			$post[ $p ] = Util_Request::get( $p );
+		}
 
 		$post['user_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
-		$post['version'] = W3TC_VERSION;
+		$post['version']    = W3TC_VERSION;
 
 		$license_level = 'community';
-		if ( Util_Environment::is_w3tc_pro( $c ) )
+		if ( Util_Environment::is_w3tc_pro( $c ) ) {
 			$license_level = 'pro';
+		}
 
-		$post['license_level'] = $license_level . ' ' .
-			$c->get_string( 'plugin.license_key' );
-
+		$post['license_level'] = $license_level . ' ' . $c->get_string( 'plugin.license_key' );
 
-		/**
-		 * Add attachments
-		 */
+		// Add attachments.
 		$attachments = array();
 
 		$attach_files = array(
-			/**
-			 * Attach WP config file
-			 */
 			Util_Environment::wp_config_path(),
-
-			/**
-			 * Attach .htaccess files
-			 */
 			Util_Rule::get_pgcache_rules_core_path(),
 			Util_Rule::get_pgcache_rules_cache_path(),
 			Util_Rule::get_browsercache_rules_cache_path(),
 			Util_Rule::get_minify_rules_core_path(),
-			Util_Rule::get_minify_rules_cache_path()
+			Util_Rule::get_minify_rules_cache_path(),
 		);
 
-		/**
-		 * Attach config files
-		 */
+		// Attach config files.
 		if ( $handle = opendir( W3TC_CONFIG_DIR ) ) {
 			while ( ( $entry = @readdir( $handle ) ) !== false ) {
-				if ( $entry == '.' || $entry == '..' || $entry == 'index.html' )
+				if ( '.' === $entry || '..' === $entry || 'index.html' === $entry ) {
 					continue;
+				}
 
 				$attach_file[] = W3TC_CONFIG_DIR . '/' . $entry;
 			}
 			closedir( $handle );
 		}
 
-
 		foreach ( $attach_files as $attach_file ) {
-			if ( $attach_file && file_exists( $attach_file ) &&
-				!in_array( $attach_file, $attachments ) ) {
+			if ( $attach_file && file_exists( $attach_file ) && ! in_array( $attach_file, $attachments, true ) ) {
 				$attachments[] = array(
 					'filename' => basename( $attach_file ),
-					'content' => file_get_contents( $attach_file )
+					'content'  => file_get_contents( $attach_file ),
 				);
 			}
 		}
 
-		/**
-		 * Attach server info
-		 */
-		$server_info = print_r( $this->get_server_info(), true );
+		// Attach server info.
+		$server_info = print_r( $this->get_server_info(), true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
 		$server_info = str_replace( "\n", "\r\n", $server_info );
 
 		$attachments[] = array(
 			'filename' => 'server_info.txt',
-			'content' => $server_info
+			'content'  => $server_info,
 		);
 
-		/**
-		 * Attach phpinfo
-		 */
+		// Attach phpinfo.
 		ob_start();
 		phpinfo();
 		$php_info = ob_get_contents();
@@ -92,12 +93,10 @@ function w3tc_support_send_details() {
 
 		$attachments[] = array(
 			'filename' => 'php_info.html',
-			'content' => $php_info
+			'content'  => $php_info,
 		);
 
-		/**
-		 * Attach self-test
-		 */
+		// Attach self-test.
 		ob_start();
 		$this->self_test();
 		$self_test = ob_get_contents();
@@ -105,19 +104,22 @@ function w3tc_support_send_details() {
 
 		$attachments[] = array(
 			'filename' => 'self_test.html',
-			'content' => $self_test
+			'content'  => $self_test,
 		);
 
 		$post['attachments'] = $attachments;
 
-		$response = wp_remote_post( W3TC_SUPPORT_REQUEST_URL, array(
-				'body' => $post,
-				'timeout' => $c->get_integer( 'timelimit.email_send' )
-			) );
+		$response = wp_remote_post(
+			W3TC_SUPPORT_REQUEST_URL,
+			array(
+				'body'    => $post,
+				'timeout' => $c->get_integer( 'timelimit.email_send' ),
+			)
+		);
 
-		if ( !is_wp_error( $response ) )
-			$result = $response['response']['code'] == 200 && $response['body'] == 'ok';
-		else {
+		if ( ! is_wp_error( $response ) ) {
+			$result = 200 === $response['response']['code'] && 'ok' === $response['body'];
+		} else {
 			$result = false;
 		}
 
@@ -125,73 +127,75 @@ function w3tc_support_send_details() {
 	}
 
 	/**
-	 * Self test action
+	 * Performs a self-test to validate the current environment.
+	 *
+	 * @return void
 	 */
 	private function self_test() {
 		include W3TC_INC_DIR . '/lightbox/self_test.php';
 	}
 
 	/**
-	 * Returns server info
+	 * Retrieves detailed information about the server environment.
 	 *
-	 * @return array
+	 * @return array An array containing server, WordPress, and MySQL environment details.
 	 */
 	private function get_server_info() {
 		global $wp_version, $wp_db_version, $wpdb;
 
-		$wordpress_plugins = get_plugins();
+		$wordpress_plugins        = get_plugins();
 		$wordpress_plugins_active = array();
 
 		foreach ( $wordpress_plugins as $wordpress_plugin_file => $wordpress_plugin ) {
 			if ( is_plugin_active( $wordpress_plugin_file ) ) {
-				$wordpress_plugins_active[$wordpress_plugin_file] = $wordpress_plugin;
+				$wordpress_plugins_active[ $wordpress_plugin_file ] = $wordpress_plugin;
 			}
 		}
 
-		$mysql_version = $wpdb->get_var( 'SELECT VERSION()' );
+		$mysql_version          = $wpdb->get_var( 'SELECT VERSION()' );
 		$mysql_variables_result = (array) $wpdb->get_results( 'SHOW VARIABLES', ARRAY_N );
-		$mysql_variables = array();
+		$mysql_variables        = array();
 
 		foreach ( $mysql_variables_result as $mysql_variables_row ) {
-			$mysql_variables[$mysql_variables_row[0]] = $mysql_variables_row[1];
+			$mysql_variables[ $mysql_variables_row[0] ] = $mysql_variables_row[1];
 		}
 
 		$server_info = array(
-			'w3tc' => array(
-				'version' => W3TC_VERSION,
-				'server' => ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : 'Unknown' ),
-				'dir' => W3TC_DIR,
-				'cache_dir' => W3TC_CACHE_DIR,
-				'blog_id' => Util_Environment::blog_id(),
+			'w3tc'  => array(
+				'version'              => W3TC_VERSION,
+				'server'               => ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : 'Unknown' ),
+				'dir'                  => W3TC_DIR,
+				'cache_dir'            => W3TC_CACHE_DIR,
+				'blog_id'              => Util_Environment::blog_id(),
 				'home_domain_root_url' => Util_Environment::home_domain_root_url(),
 				'home_url_maybe_https' => Util_Environment::home_url_maybe_https(),
-				'site_path' => Util_Environment::site_path(),
-				'document_root' => Util_Environment::document_root(),
-				'site_root' => Util_Environment::site_root(),
-				'site_url_uri' => Util_Environment::site_url_uri(),
-				'home_url_host' => Util_Environment::home_url_host(),
-				'home_url_uri' => Util_Environment::home_url_uri(),
+				'site_path'            => Util_Environment::site_path(),
+				'document_root'        => Util_Environment::document_root(),
+				'site_root'            => Util_Environment::site_root(),
+				'site_url_uri'         => Util_Environment::site_url_uri(),
+				'home_url_host'        => Util_Environment::home_url_host(),
+				'home_url_uri'         => Util_Environment::home_url_uri(),
 				'network_home_url_uri' => Util_Environment::network_home_url_uri(),
-				'host_port' => Util_Environment::host_port(),
-				'host' => Util_Environment::host(),
-				'wp_config_path' => Util_Environment::wp_config_path()
+				'host_port'            => Util_Environment::host_port(),
+				'host'                 => Util_Environment::host(),
+				'wp_config_path'       => Util_Environment::wp_config_path(),
 			),
-			'wp' => array(
-				'version' => $wp_version,
-				'db_version' => $wp_db_version,
-				'abspath' => ABSPATH,
-				'home' => get_option( 'home' ),
-				'siteurl' => get_option( 'siteurl' ),
-				'email' => get_option( 'admin_email' ),
+			'wp'    => array(
+				'version'     => $wp_version,
+				'db_version'  => $wp_db_version,
+				'abspath'     => ABSPATH,
+				'home'        => get_option( 'home' ),
+				'siteurl'     => get_option( 'siteurl' ),
+				'email'       => get_option( 'admin_email' ),
 				'upload_info' => (array) Util_Http::upload_info(),
-				'theme' => Util_Theme::get_current_theme(),
-				'wp_cache' => ( ( defined( 'WP_CACHE' ) && WP_CACHE ) ? 'true' : 'false' ),
-				'plugins' => $wordpress_plugins_active
+				'theme'       => Util_Theme::get_current_theme(),
+				'wp_cache'    => ( ( defined( 'WP_CACHE' ) && WP_CACHE ) ? 'true' : 'false' ),
+				'plugins'     => $wordpress_plugins_active,
 			),
 			'mysql' => array(
-				'version' => $mysql_version,
-				'variables' => $mysql_variables
-			)
+				'version'   => $mysql_version,
+				'variables' => $mysql_variables,
+			),
 		);
 
 		return $server_info;
diff --git a/Support_Page.php b/Support_Page.php
index 547f16f70..a14ec4bf9 100644
--- a/Support_Page.php
+++ b/Support_Page.php
@@ -1,20 +1,35 @@
 <?php
+/**
+ * File: Support_Page.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class Support_Page
+ */
 class Support_Page {
 	/**
-	 * called from Generic_Plugin_Admin on action
+	 * Prints the W3TC support scripts in the admin area.
+	 *
+	 * This method localizes and sets up the necessary variables to be used
+	 * by the W3TC support JavaScript in the admin area.
+	 *
+	 * @return void
 	 */
-	static public function admin_print_scripts_w3tc_support() {
+	public static function admin_print_scripts_w3tc_support() {
 		$url = get_home_url();
-		if ( substr( $url, 0, 7 ) == 'http://' )
+		if ( 'http://' === substr( $url, 0, 7 ) ) {
 			$url = substr( $url, 7 );
-		elseif ( substr( $url, 0, 8 ) == 'https://' )
+		} elseif ( 'https://' === substr( $url, 0, 8 ) ) {
 			$url = substr( $url, 8 );
+		}
 
-		// values from widget
-		$w3tc_support_form_hash = 'm5pom8z0qy59rm';
-		$w3tc_support_field_name = '';
+		// values from widget.
+		$w3tc_support_form_hash   = 'm5pom8z0qy59rm';
+		$w3tc_support_field_name  = '';
 		$w3tc_support_field_value = '';
 
 		$service_item_val = Util_Request::get_integer( 'service_item' );
@@ -24,58 +39,68 @@ static public function admin_print_scripts_w3tc_support() {
 			$v = get_site_option( 'w3tc_generic_widgetservices' );
 			try {
 				$v = json_decode( $v, true );
-				if ( isset( $v['items'] ) && isset( $v['items'][$pos] )) {
-					$i = $v['items'][$pos];
-					$w3tc_support_form_hash = $i['form_hash'];
-					$w3tc_support_field_name = $i['parameter_name'];
+				if ( isset( $v['items'] ) && isset( $v['items'][ $pos ] ) ) {
+					$i                        = $v['items'][ $pos ];
+					$w3tc_support_form_hash   = $i['form_hash'];
+					$w3tc_support_field_name  = $i['parameter_name'];
 					$w3tc_support_field_value = $i['parameter_value'];
 				}
-			} catch ( \Exception $e ) {
+			} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
 			}
 		}
 
 		$u = wp_get_current_user();
 
 		// w3tc-options script is already queued so attach to it
-		// just to make vars printed (while it's not related by semantics)
-		wp_localize_script( 'w3tc-options', 'w3tc_support_data',
+		// just to make vars printed (while it's not related by semantics).
+		wp_localize_script(
+			'w3tc-options',
+			'w3tc_support_data',
 			array(
-				'home_url' => $url,
-				'email' => get_bloginfo( 'admin_email' ),
-				'first_name' => $u->first_name,
-				'last_name' => $u->last_name,
-				'form_hash' => $w3tc_support_form_hash,
-				'field_name' => $w3tc_support_field_name,
+				'home_url'    => $url,
+				'email'       => get_bloginfo( 'admin_email' ),
+				'first_name'  => $u->first_name,
+				'last_name'   => $u->last_name,
+				'form_hash'   => $w3tc_support_form_hash,
+				'field_name'  => $w3tc_support_field_name,
 				'field_value' => $w3tc_support_field_value,
-				'postprocess' => urlencode( urlencode(
-					Util_Ui::admin_url(
-						wp_nonce_url( 'admin.php', 'w3tc' ) . '&page=w3tc_support&done=1'
-					) ) )
+				'postprocess' => rawurlencode(
+					rawurlencode(
+						Util_Ui::admin_url(
+							wp_nonce_url( 'admin.php', 'w3tc' ) . '&page=w3tc_support&done=1'
+						)
+					)
+				),
 			)
 		);
 	}
+
 	/**
-	 * Support tab
+	 * Displays the options page for W3TC support.
+	 *
+	 * This method renders the appropriate content based on the request parameters.
+	 * If a "done" parameter is detected, it processes the request and displays
+	 * the post-process content. Otherwise, it loads the main support page content.
 	 *
 	 * @return void
 	 */
-	function options() {
+	public function options() {
 		if ( ! empty( Util_Request::get_string( 'done' ) ) ) {
 			$postprocess_url =
 				'admin.php?page=w3tc_support&w3tc_support_send_details' .
 				'&_wpnonce=' . rawurlencode( Util_Request::get_string( '_wpnonce' ) );
-			foreach ( $_GET as $p => $v ) {
+			foreach ( $_GET as $p => $v ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 				if ( 'page' !== $p && '_wpnonce' !== $p && 'done' !== $p ) {
 					$postprocess_url .= '&' . rawurlencode( $p ) . '=' . rawurlencode( Util_Request::get_string( $p ) );
 				}
 			}
 
-			// terms accepted as a part of form
+			// terms accepted as a part of form.
 			Licensing_Core::terms_accept();
 
-			include  W3TC_DIR . '/Support_Page_View_DoneContent.php';
+			include W3TC_DIR . '/Support_Page_View_DoneContent.php';
 		} else {
-			include  W3TC_DIR . '/Support_Page_View_PageContent.php';
+			include W3TC_DIR . '/Support_Page_View_PageContent.php';
 		}
 	}
 }
diff --git a/Support_Page_View_DoneContent.php b/Support_Page_View_DoneContent.php
index 101f6e673..20c5530c2 100644
--- a/Support_Page_View_DoneContent.php
+++ b/Support_Page_View_DoneContent.php
@@ -1,5 +1,15 @@
-<?php include W3TC_INC_DIR . '/options/common/header.php'; ?>
+<?php
+/**
+ * File: Support_Page_View_DoneContent.php
+ *
+ * @package W3TC
+ */
+
+namespace W3TC;
+
+require W3TC_INC_DIR . '/options/common/header.php';
+?>
 <div style="text-align: center; font-weight: bold; margin-top: 50px">
 	Thank you for filling out the form
 </div>
-<iframe src="<?php echo esc_attr( $postprocess_url ) ?>" width="0" height="0"></iframe>
+<iframe src="<?php echo esc_attr( $postprocess_url ); ?>" width="0" height="0"></iframe>
diff --git a/Support_Page_View_PageContent.php b/Support_Page_View_PageContent.php
index dbdec2267..7354f2f6c 100644
--- a/Support_Page_View_PageContent.php
+++ b/Support_Page_View_PageContent.php
@@ -1,4 +1,13 @@
-<?php include W3TC_INC_DIR . '/options/common/header.php'; ?>
+<?php
+/**
+ * File: Support_Page_View_PageContent.php
+ *
+ * @package W3TC
+ */
+
+namespace W3TC;
+
+require W3TC_INC_DIR . '/options/common/header.php'; ?>
 
 <div id="wufoo-m5pom8z0qy59rm"></div>
 <form>
diff --git a/SystemOpCache_AdminActions.php b/SystemOpCache_AdminActions.php
index 46e8ef0c3..11f2653a8 100644
--- a/SystemOpCache_AdminActions.php
+++ b/SystemOpCache_AdminActions.php
@@ -1,21 +1,47 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: SystemOpCache_AdminActions.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class SystemOpCache_AdminActions
+ */
 class SystemOpCache_AdminActions {
-	function w3tc_opcache_flush() {
-		$core = Dispatcher::component( 'SystemOpCache_Core' );
+	/**
+	 * Flushes the OPCache and redirects with a success or error message.
+	 *
+	 * This method is designed to clear the PHP OPCache to ensure the latest
+	 * PHP code changes are loaded and executed. It interacts with the
+	 * `SystemOpCache_Core` component to perform the flush operation and
+	 * provides user feedback via admin redirect messages.
+	 *
+	 * @throws Exception If the `SystemOpCache_Core` component is unavailable
+	 *                   or the flush operation encounters an unexpected error.
+	 *
+	 * @return void This method performs a redirect and does not return a value.
+	 */
+	public function w3tc_opcache_flush() {
+		$core    = Dispatcher::component( 'SystemOpCache_Core' );
 		$success = $core->flush();
 
 		if ( $success ) {
-			Util_Admin::redirect_with_custom_messages2( array(
-					'notes' => array( 'OPCache was flushed successfully' )
-				), true );
+			Util_Admin::redirect_with_custom_messages2(
+				array(
+					'notes' => array( 'OPCache was flushed successfully' ),
+				),
+				true
+			);
 		} else {
-			Util_Admin::redirect_with_custom_messages2( array(
-					'errors' => array( 'Failed to flush OPCache' )
-				), true );
+			Util_Admin::redirect_with_custom_messages2(
+				array(
+					'errors' => array( 'Failed to flush OPCache' ),
+				),
+				true
+			);
 		}
 	}
 }
diff --git a/SystemOpCache_Core.php b/SystemOpCache_Core.php
index bf6f0b8e0..22a1ce178 100644
--- a/SystemOpCache_Core.php
+++ b/SystemOpCache_Core.php
@@ -1,45 +1,81 @@
 <?php
+/**
+ * File: SystemOpCache_Core.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class SystemOpCache_Core
+ */
 class SystemOpCache_Core {
+	/**
+	 * Checks if opcode caching is enabled.
+	 *
+	 * This method verifies if either Zend OPcache or APCu OPcache is enabled
+	 * on the server.
+	 *
+	 * @return bool True if opcode caching is enabled, false otherwise.
+	 */
 	public function is_enabled() {
 		return Util_Installed::opcache() || Util_Installed::apc_opcache();
 	}
 
-
-
+	/**
+	 * Flushes the opcode cache.
+	 *
+	 * Clears the opcode cache for the currently enabled caching mechanism
+	 * (either Zend OPcache or APCu OPcache). If no supported opcode caching
+	 * mechanism is found, it returns false.
+	 *
+	 * @return bool True if the cache was successfully cleared, false otherwise.
+	 */
 	public function flush() {
 		if ( Util_Installed::opcache() ) {
 			return opcache_reset();
-		} else if ( Util_Installed::apc_opcache() ) {
-				$result = apc_clear_cache();   // that doesnt clear user cache
-				$result |= apc_clear_cache( 'opcode' );   // extra
-				return $result;
-			}
+		} elseif ( Util_Installed::apc_opcache() ) {
+			$result  = apc_clear_cache(); // that doesnt clear user cache.
+			$result |= apc_clear_cache( 'opcode' ); // extra.
+			return $result;
+		}
+
 		return false;
 	}
 
-
-
-
+	/**
+	 * Flushes the opcode cache for a specific file.
+	 *
+	 * This method attempts to invalidate the opcode cache for a given file
+	 * by first resolving its path and then using the appropriate caching
+	 * function (e.g., `opcache_invalidate` or `apc_compile_file`). If the file
+	 * cannot be resolved or the cache cannot be invalidated, it returns false.
+	 *
+	 * @param string $filename The relative or absolute path to the file.
+	 *
+	 * @return bool True if the file cache was successfully invalidated, false otherwise.
+	 */
 	public function flush_file( $filename ) {
-		if ( file_exists( $filename ) ) {
-		} else if ( file_exists( ABSPATH . $filename ) )
-				$filename = ABSPATH . DIRECTORY_SEPARATOR . $filename;
-			elseif ( file_exists( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename ) )
-				$filename = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename;
-			elseif ( file_exists( WPINC . DIRECTORY_SEPARATOR . $filename ) )
-				$filename = WPINC . DIRECTORY_SEPARATOR . $filename;
-			elseif ( file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename ) )
-				$filename = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename;
-			else
-				return false;
+		if ( file_exists( $filename ) ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
+		} elseif ( file_exists( ABSPATH . $filename ) ) {
+			$filename = ABSPATH . DIRECTORY_SEPARATOR . $filename;
+		} elseif ( file_exists( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename ) ) {
+			$filename = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename;
+		} elseif ( file_exists( WPINC . DIRECTORY_SEPARATOR . $filename ) ) {
+			$filename = WPINC . DIRECTORY_SEPARATOR . $filename;
+		} elseif ( file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename ) ) {
+			$filename = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename;
+		} else {
+			return false;
+		}
 
-			if ( function_exists( 'opcache_invalidate' ) )
-				return opcache_invalidate( $filename, true );
-			else if ( function_exists( 'apc_compile_file' ) )
-					return apc_compile_file( $filename );
+		if ( function_exists( 'opcache_invalidate' ) ) {
+			return opcache_invalidate( $filename, true );
+		} elseif ( function_exists( 'apc_compile_file' ) ) {
+			return apc_compile_file( $filename );
+		}
 
-				return false;
+		return false;
 	}
 }
diff --git a/SystemOpCache_GeneralPage_View.php b/SystemOpCache_GeneralPage_View.php
index 9b0be0955..6e6501833 100644
--- a/SystemOpCache_GeneralPage_View.php
+++ b/SystemOpCache_GeneralPage_View.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: SystemOpCache_GeneralPage_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
@@ -53,7 +59,7 @@
 			'disabled'       => true,
 			'value'          => $validate_timestamps,
 			'checkbox_label' => esc_html__( 'Enable', 'w3-total-cache' ),
-			'description'    => esc_html__( 'Once enabled, each file request will update the cache with the latest version. When this setting is off, the Opcode Cache will not check, instead PHP must be restarted in order for setting changes to be reflected.', 'w3-total-cache' )
+			'description'    => esc_html__( 'Once enabled, each file request will update the cache with the latest version. When this setting is off, the Opcode Cache will not check, instead PHP must be restarted in order for setting changes to be reflected.', 'w3-total-cache' ),
 		)
 	);
 	?>
diff --git a/SystemOpCache_Plugin_Admin.php b/SystemOpCache_Plugin_Admin.php
index 41b319933..ffdc1ac78 100644
--- a/SystemOpCache_Plugin_Admin.php
+++ b/SystemOpCache_Plugin_Admin.php
@@ -1,59 +1,113 @@
 <?php
+/**
+ * File: SystemOpCache_Plugin_Admin.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class SystemOpCache_Plugin_Admin
+ */
 class SystemOpCache_Plugin_Admin {
-	function run() {
+	/**
+	 * Initializes the plugin by registering actions and filters with WordPress.
+	 *
+	 * Adds functionality for OPcache and APC OPcache support in the admin panel,
+	 * such as menu items, settings, and actions.
+	 *
+	 * @return void
+	 */
+	public function run() {
 		if ( Util_Installed::opcache() || Util_Installed::apc_opcache() ) {
-			add_filter( 'w3tc_admin_bar_menu',
-				array( $this, 'w3tc_admin_bar_menu' ) );
+			add_filter( 'w3tc_admin_bar_menu', array( $this, 'w3tc_admin_bar_menu' ) );
 		}
 
-		add_filter( 'w3tc_admin_actions',
-			array( $this, 'w3tc_admin_actions' ) );
-		add_action( 'w3tc_settings_general_boxarea_system_opcache',
-			array( $this, 'w3tc_settings_general_boxarea_system_opcache' ) );
+		add_filter( 'w3tc_admin_actions', array( $this, 'w3tc_admin_actions' ) );
+		add_action( 'w3tc_settings_general_boxarea_system_opcache', array( $this, 'w3tc_settings_general_boxarea_system_opcache' ) );
 	}
 
-
-
+	/**
+	 * Adds an entry for "System OPcache" to the W3 Total Cache settings anchors.
+	 *
+	 * This method appends the "System OPcache" anchor to the list of settings
+	 * anchors, enabling users to navigate to the relevant settings section.
+	 *
+	 * @param array $anchors Existing settings anchors.
+	 *
+	 * @return array Updated settings anchors including "System OPcache".
+	 */
 	public function w3tc_settings_general_anchors( $anchors ) {
-		$anchors[] = array( 'id' => 'system_opcache', 'text' => 'System OPcache' );
+		$anchors[] = array(
+			'id'   => 'system_opcache',
+			'text' => 'System OPcache',
+		);
+
 		return $anchors;
 	}
 
-
-
-	static public function w3tc_admin_actions( $handlers ) {
+	/**
+	 * Registers the "opcache" handler with W3 Total Cache admin actions.
+	 *
+	 * This static method maps the "opcache" identifier to the `SystemOpCache_AdminActions`
+	 * class, enabling the corresponding actions to be handled correctly.
+	 *
+	 * @param array $handlers Existing action handlers.
+	 *
+	 * @return array Updated action handlers including the "opcache" handler.
+	 */
+	public static function w3tc_admin_actions( $handlers ) {
 		$handlers['opcache'] = 'SystemOpCache_AdminActions';
 
 		return $handlers;
 	}
 
-
-
+	/**
+	 * Displays the settings box for OPcache in the general settings section.
+	 *
+	 * This method determines the availability of OPcache or APC OPcache and
+	 * their configurations, then includes the view file to render the settings.
+	 *
+	 * @return void
+	 */
 	public function w3tc_settings_general_boxarea_system_opcache() {
-		$opcode_engine = 'Not Available';
+		$opcode_engine       = 'Not Available';
 		$validate_timestamps = false;
 
 		if ( Util_Installed::opcache() ) {
-			$opcode_engine = 'OPcache';
+			$opcode_engine       = 'OPcache';
 			$validate_timestamps = Util_Installed::is_opcache_validate_timestamps();
-		} else if ( Util_Installed::apc_opcache() ) {
-				$opcode_engine = 'APC';
-				$engine_status = Util_Installed::is_apc_validate_timestamps();
-			}
+		} elseif ( Util_Installed::apc_opcache() ) {
+			$opcode_engine = 'APC';
+			$engine_status = Util_Installed::is_apc_validate_timestamps();
+		}
 
-		include  W3TC_DIR . '/SystemOpCache_GeneralPage_View.php';
+		include W3TC_DIR . '/SystemOpCache_GeneralPage_View.php';
 	}
 
 
-
+	/**
+	 * Adds an OPcache flush menu item to the WordPress admin bar.
+	 *
+	 * This method creates a menu item in the admin bar for flushing the
+	 * OPcache, providing a quick access point for this operation.
+	 *
+	 * @param array $menu_items Existing admin bar menu items.
+	 *
+	 * @return array Updated admin bar menu items including the OPcache flush menu item.
+	 */
 	public function w3tc_admin_bar_menu( $menu_items ) {
 		$menu_items['20910.system_opcache'] = array(
-			'id' => 'w3tc_flush_opcache',
+			'id'     => 'w3tc_flush_opcache',
 			'parent' => 'w3tc_flush',
-			'title' => __( 'Opcode Cache', 'w3-total-cache' ),
-			'href' => Util_Ui::url( array( 'page' => 'w3tc_dashboard', 'w3tc_opcache_flush' => '' ) ),
+			'title'  => __( 'Opcode Cache', 'w3-total-cache' ),
+			'href'   => Util_Ui::url(
+				array(
+					'page'               => 'w3tc_dashboard',
+					'w3tc_opcache_flush' => '',
+				)
+			),
 		);
 
 		return $menu_items;
diff --git a/UsageStatistics_AdminActions.php b/UsageStatistics_AdminActions.php
index ab4f9a462..0a4c72510 100644
--- a/UsageStatistics_AdminActions.php
+++ b/UsageStatistics_AdminActions.php
@@ -1,19 +1,47 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_AdminActions.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_AdminActions
+ *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ */
 class UsageStatistics_AdminActions {
+	/**
+	 * Config
+	 *
+	 * @var Config
+	 */
 	private $_config = null;
 
-
-
+	/**
+	 * Constructor for the UsageStatistics_AdminActions class.
+	 *
+	 * Initializes the configuration property by retrieving settings from the Dispatcher.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 		$this->_config = Dispatcher::config();
 	}
 
-
-
+	/**
+	 * Disables usage statistics tracking.
+	 *
+	 * This method updates the configuration to disable usage statistics tracking
+	 * by setting the 'stats.enabled' key to `false` and saving the configuration.
+	 * It then redirects the user back to the appropriate location using `Util_Admin::redirect`.
+	 *
+	 * @return void
+	 *
+	 * @throws Exception If there is an error saving the configuration or during the redirect process.
+	 */
 	public function w3tc_ustats_note_disable() {
 		$this->_config->set( 'stats.enabled', false );
 		$this->_config->save();
diff --git a/UsageStatistics_Core.php b/UsageStatistics_Core.php
index c5509fe4b..d6d04dfd1 100644
--- a/UsageStatistics_Core.php
+++ b/UsageStatistics_Core.php
@@ -1,80 +1,134 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Core.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_Core
+ */
 class UsageStatistics_Core {
+	/**
+	 * Shutdown handler added flag
+	 *
+	 * @var bool
+	 */
 	private $shutdown_handler_added = false;
-	private $storage;
-	private $hotspot_flushing_state_on_exit_attempt = null;
 
+	/**
+	 * Storage
+	 *
+	 * @var W3TC\UsageStatistics_StorageWriter
+	 */
+	private $storage;
 
+	/**
+	 * Hotspot flushing state on exit attempt
+	 *
+	 * @var string
+	 */
+	private $hotspot_flushing_state_on_exit_attempt = null;
 
+	/**
+	 * Constructor for the UsageStatistics_Core class.
+	 *
+	 * Initializes the storage mechanism for usage statistics.
+	 * This ensures that the class is ready to handle metrics and data operations.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 		$this->storage = new UsageStatistics_StorageWriter();
 	}
 
-
-
+	/**
+	 * Adds a shutdown handler for usage statistics.
+	 *
+	 * Registers the `shutdown` method to execute during the WordPress shutdown hook.
+	 * If exit-requested hotspot flushing is enabled, it also sets up an additional
+	 * initialization handler to ensure proper processing.
+	 *
+	 * @return void
+	 */
 	public function add_shutdown_handler() {
 		$this->shutdown_handler_added = true;
-		add_action( 'shutdown', array(
-				$this,
-				'shutdown'
-			), 100000, 0 );
-
-		if ( !is_null( $this->hotspot_flushing_state_on_exit_attempt ) )
-			add_action( 'init', array(
-					$this, 'init_when_exit_requested' ) );
-	}
-
+		add_action( 'shutdown', array( $this, 'shutdown' ), 100000, 0 );
 
+		if ( ! is_null( $this->hotspot_flushing_state_on_exit_attempt ) ) {
+			add_action( 'init', array( $this, 'init_when_exit_requested' ) );
+		}
+	}
 
+	/**
+	 * Checks if the shutdown handler has been added.
+	 *
+	 * @return bool True if the shutdown handler has been added, false otherwise.
+	 */
 	public function is_shutdown_handler_added() {
 		return $this->shutdown_handler_added;
 	}
 
-
-
+	/**
+	 * Initializes processing when an exit is requested.
+	 *
+	 * If called, it terminates the script execution immediately.
+	 * Typically used for critical flush processing.
+	 *
+	 * @return void
+	 */
 	public function init_when_exit_requested() {
 		exit();
 	}
 
-
-
+	/**
+	 * Executes the shutdown process for usage statistics.
+	 *
+	 * Handles the flushing of hotspot data based on the current state.
+	 * Also triggers an action hook for additional processing during the request shutdown.
+	 *
+	 * @return void
+	 */
 	public function shutdown() {
-		if ( !is_null( $this->hotspot_flushing_state_on_exit_attempt ) )
+		if ( ! is_null( $this->hotspot_flushing_state_on_exit_attempt ) ) {
 			$this->storage->finish_flush_hotspot_data();
-		else
+		} else {
 			$this->storage->maybe_flush_hotspot_data();
+		}
 
 		do_action( 'w3tc_usage_statistics_of_request', $this->storage );
 	}
 
-
-
 	/**
-	 * $metrics_function has to be added by add_action on plugin load
+	 * Applies metrics before WordPress initialization and exits if required.
+	 *
+	 * If the plugin is already loaded, it skips processing as metrics will be handled by the shutdown method.
+	 * Otherwise, it prepares for hotspot flushing and applies metrics via the provided function.
+	 * Exits the process if flushing is required immediately.
+	 *
+	 * @param callable $metrics_function A callback function to apply metrics using the storage instance.
+	 *
+	 * @return void
 	 */
 	public function apply_metrics_before_init_and_exit( $metrics_function ) {
-		// plugin already loaded, metrics will be added normal way
-		// by shutdown
+		// plugin already loaded, metrics will be added normal way by shutdown.
 
 		if ( $this->shutdown_handler_added ) {
 			return;
 		}
 
-		$this->hotspot_flushing_state_on_exit_attempt =
-			$this->storage->begin_flush_hotspot_data();
+		$this->hotspot_flushing_state_on_exit_attempt = $this->storage->begin_flush_hotspot_data();
 
 		// flush wants to happen in that process, need to pass through whole
-		// wp request processing further
-		if ( $this->hotspot_flushing_state_on_exit_attempt != 'not_needed' ) {
+		// wp request processing further.
+		if ( 'not_needed' !== $this->hotspot_flushing_state_on_exit_attempt ) {
 			return;
 		}
 
 		call_user_func( $metrics_function, $this->storage );
+
 		exit();
 	}
-
 }
diff --git a/UsageStatistics_GeneralPage.php b/UsageStatistics_GeneralPage.php
index dbc873ed7..c9aba3e2a 100644
--- a/UsageStatistics_GeneralPage.php
+++ b/UsageStatistics_GeneralPage.php
@@ -1,35 +1,58 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_GeneralPage.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_GeneralPage
+ */
 class UsageStatistics_GeneralPage {
 	/**
-	 * W3TC General settings page modifications
+	 * Initializes the general page settings for Usage Statistics in the W3 Total Cache plugin.
+	 *
+	 * This method sets up hooks to add custom sections and content to the General Settings page.
+	 *
+	 * @return void
 	 */
-	static public function admin_init_w3tc_general() {
+	public static function admin_init_w3tc_general() {
 		$o = new UsageStatistics_GeneralPage();
 
-		add_filter( 'w3tc_settings_general_anchors',
-			array( $o, 'w3tc_settings_general_anchors' ) );
-		add_action( 'w3tc_settings_general_boxarea_stats',
-			array( $o, 'w3tc_settings_general_boxarea_stats' ) );
+		add_filter( 'w3tc_settings_general_anchors', array( $o, 'w3tc_settings_general_anchors' ) );
+		add_action( 'w3tc_settings_general_boxarea_stats', array( $o, 'w3tc_settings_general_boxarea_stats' ) );
 	}
 
-
-
-
+	/**
+	 * Adds a "Statistics" anchor to the General Settings page navigation.
+	 *
+	 * This method modifies the array of navigation anchors for the General Settings page
+	 * by appending an entry for the "Statistics" section.
+	 *
+	 * @param array $anchors An array of existing anchors for the General Settings page.
+	 *
+	 * @return array The modified array of anchors with the "Statistics" anchor included.
+	 */
 	public function w3tc_settings_general_anchors( $anchors ) {
 		$anchors[] = array(
 			'id'   => 'stats',
 			'text' => __( 'Statistics', 'w3-total-cache' ),
 		);
+
 		return $anchors;
 	}
 
-
-
+	/**
+	 * Renders the Statistics box area on the General Settings page.
+	 *
+	 * This method includes a view file that outputs the content for the Statistics section
+	 * of the General Settings page.
+	 *
+	 * @return void
+	 */
 	public function w3tc_settings_general_boxarea_stats() {
-		include  W3TC_DIR . '/UsageStatistics_GeneralPage_View.php';
+		include W3TC_DIR . '/UsageStatistics_GeneralPage_View.php';
 	}
 }
diff --git a/UsageStatistics_GeneralPage_View.php b/UsageStatistics_GeneralPage_View.php
index eda760433..66d637375 100644
--- a/UsageStatistics_GeneralPage_View.php
+++ b/UsageStatistics_GeneralPage_View.php
@@ -11,7 +11,7 @@
 	die();
 }
 
-$c = Dispatcher::config();
+$c      = Dispatcher::config();
 $is_pro = Util_Environment::is_w3tc_pro( $c );
 
 Util_Ui::postbox_header_tabs(
@@ -101,15 +101,15 @@
 
 Util_Ui::config_item(
 	array(
-		'key'          => 'stats.access_log.webserver',
-		'label'        => __( 'Webserver:', 'w3-total-cache' ),
-		'control'      => 'selectbox',
+		'key'              => 'stats.access_log.webserver',
+		'label'            => __( 'Webserver:', 'w3-total-cache' ),
+		'control'          => 'selectbox',
 		'selectbox_values' => array(
 			'apache' => 'Apache',
 			'nginx'  => 'Nginx',
 		),
-		'description'  => __( 'Webserver type generating access logs.', 'w3-total-cache' ),
-		'show_in_free' => false,
+		'description'      => __( 'Webserver type generating access logs.', 'w3-total-cache' ),
+		'show_in_free'     => false,
 	)
 );
 
diff --git a/UsageStatistics_Page.php b/UsageStatistics_Page.php
index c7b662b81..b4a5a6d0c 100644
--- a/UsageStatistics_Page.php
+++ b/UsageStatistics_Page.php
@@ -1,27 +1,53 @@
 <?php
+/**
+ * File: UsageStatistics_Page.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UsageStatistics_Page
+ */
 class UsageStatistics_Page {
+	/**
+	 * Enqueues the necessary CSS and JavaScript for the usage statistics page.
+	 *
+	 * This method ensures that the required CSS and JS files for displaying usage statistics
+	 * are loaded. It checks if W3 Total Cache Pro is active and if statistics are enabled,
+	 * loading additional scripts if needed.
+	 *
+	 * @return void
+	 */
 	public static function admin_print_scripts_w3tc_stats() {
 		$config = Dispatcher::config();
 
 		wp_enqueue_style( 'w3tc-widget-usage-statistics', plugins_url( 'UsageStatistics_Page_View.css', W3TC_FILE ), array(), W3TC_VERSION );
-		wp_enqueue_script( 'w3tc-widget-usage-statistics', plugins_url( 'UsageStatistics_Page_View.js', W3TC_FILE ), array( 'w3tc-canvasjs' ), W3TC_VERSION );
+		wp_enqueue_script( 'w3tc-widget-usage-statistics', plugins_url( 'UsageStatistics_Page_View.js', W3TC_FILE ), array( 'w3tc-canvasjs' ), W3TC_VERSION, false );
 
 		if ( Util_Environment::is_w3tc_pro( $config ) && $config->get_boolean( 'stats.enabled' ) ) {
-			wp_enqueue_script( 'w3tc-canvasjs', plugins_url( 'pub/js/chartjs.min.js', W3TC_FILE ), array(), W3TC_VERSION );
+			wp_enqueue_script( 'w3tc-canvasjs', plugins_url( 'pub/js/chartjs.min.js', W3TC_FILE ), array(), W3TC_VERSION, false );
 		}
 	}
 
+	/**
+	 * Renders the usage statistics page.
+	 *
+	 * This method checks if W3 Total Cache Pro is active and if statistics are enabled. Based on
+	 * the request view (e.g., database requests, object cache requests, page cache requests), it
+	 * loads the relevant statistics view and data.
+	 *
+	 * @return void
+	 */
 	public function render() {
-		$c = Dispatcher::config();
-		$enabled = ( $c->get_boolean( 'stats.enabled' ) &&
-			Util_Environment::is_w3tc_pro( $c ) );
-		if ( !$enabled ) {
-			if ( !Util_Environment::is_w3tc_pro( $c ) ) {
-				include  W3TC_DIR . '/UsageStatistics_Page_View_Free.php';
+		$c       = Dispatcher::config();
+		$enabled = ( $c->get_boolean( 'stats.enabled' ) && Util_Environment::is_w3tc_pro( $c ) );
+		if ( ! $enabled ) {
+			if ( ! Util_Environment::is_w3tc_pro( $c ) ) {
+				include W3TC_DIR . '/UsageStatistics_Page_View_Free.php';
 			} else {
-				include  W3TC_DIR . '/UsageStatistics_Page_View_Disabled.php';
+				include W3TC_DIR . '/UsageStatistics_Page_View_Disabled.php';
 			}
 
 			return;
@@ -29,82 +55,112 @@ public function render() {
 
 		$view_val = Util_Request::get_string( 'view' );
 		if ( ! empty( $view_val ) && 'db_requests' === $view_val ) {
-			$storage = new UsageStatistics_StorageReader();
-			$summary = $storage->get_history_summary();
+			$storage         = new UsageStatistics_StorageReader();
+			$summary         = $storage->get_history_summary();
 			$timestamp_start = $summary['period']['timestamp_start'];
 
 			$sort_val    = Util_Request::get_string( 'sort' );
 			$sort_column = ! empty( $sort_val ) ? $sort_val : '';
-			if ( !in_array( $sort_column, array(
-					'query', 'count_total', 'count_hit', 'avg_size',
-					'avg_time_ms', 'sum_time_ms' ) ) ) {
+			if (
+				! in_array(
+					$sort_column,
+					array(
+						'query',
+						'count_total',
+						'count_hit',
+						'avg_size',
+						'avg_time_ms',
+						'sum_time_ms',
+					),
+					true
+				)
+			) {
 				$sort_column = 'sum_time_ms';
 			}
 
-			if ( !$c->get_boolean( 'dbcache.debug' ) ) {
-				include  W3TC_DIR . '/UsageStatistics_Page_View_NoDebugMode.php';
+			if ( ! $c->get_boolean( 'dbcache.debug' ) ) {
+				include W3TC_DIR . '/UsageStatistics_Page_View_NoDebugMode.php';
 				return;
 			}
 
-			$reader = new UsageStatistics_Source_DbQueriesLog( $timestamp_start,
-				$sort_column );
-			$items = $reader->list_entries();
+			$reader = new UsageStatistics_Source_DbQueriesLog( $timestamp_start, $sort_column );
+			$items  = $reader->list_entries();
 
 			$result = array(
-				'date_min' =>
-					Util_UsageStatistics::time_mins( $timestamp_start ),
-				'date_max' => Util_UsageStatistics::time_mins( time() ),
+				'date_min'    => Util_UsageStatistics::time_mins( $timestamp_start ),
+				'date_max'    => Util_UsageStatistics::time_mins( time() ),
 				'sort_column' => $sort_column,
-				'items' => $items
+				'items'       => $items,
 			);
 
-			include  W3TC_DIR . '/UsageStatistics_Page_DbRequests_View.php';
+			include W3TC_DIR . '/UsageStatistics_Page_DbRequests_View.php';
 		} elseif ( ! empty( $view_val ) && 'oc_requests' === $view_val ) {
-			$storage = new UsageStatistics_StorageReader();
-			$summary = $storage->get_history_summary();
+			$storage         = new UsageStatistics_StorageReader();
+			$summary         = $storage->get_history_summary();
 			$timestamp_start = $summary['period']['timestamp_start'];
 
 			$sort_val    = Util_Request::get_string( 'sort' );
 			$sort_column = ! empty( $sort_val ) ? $sort_val : '';
-			if ( !in_array( $sort_column, array(
-					'group', 'count_total', 'count_get_total', 'count_get_hit',
-					'count_set', 'avg_size', 'sum_size', 'sum_time_ms' ) ) ) {
+			if (
+				! in_array(
+					$sort_column,
+					array(
+						'group',
+						'count_total',
+						'count_get_total',
+						'count_get_hit',
+						'count_set',
+						'avg_size',
+						'sum_size',
+						'sum_time_ms',
+					),
+					true
+				)
+			) {
 				$sort_column = 'sum_time_ms';
 			}
 
-			if ( !$c->get_boolean( 'objectcache.debug' ) ) {
-				include  W3TC_DIR . '/UsageStatistics_Page_View_NoDebugMode.php';
+			if ( ! $c->get_boolean( 'objectcache.debug' ) ) {
+				include W3TC_DIR . '/UsageStatistics_Page_View_NoDebugMode.php';
 				return;
 			}
 
-			$reader = new UsageStatistics_Source_ObjectCacheLog( $timestamp_start,
-				$sort_column );
-			$items = $reader->list_entries();
+			$reader = new UsageStatistics_Source_ObjectCacheLog( $timestamp_start, $sort_column );
+			$items  = $reader->list_entries();
 
 			$result = array(
-				'date_min' =>
-					Util_UsageStatistics::time_mins( $timestamp_start ),
-				'date_max' => Util_UsageStatistics::time_mins( time() ),
+				'date_min'    => Util_UsageStatistics::time_mins( $timestamp_start ),
+				'date_max'    => Util_UsageStatistics::time_mins( time() ),
 				'sort_column' => $sort_column,
-				'items' => $items
+				'items'       => $items,
 			);
 
-			include  W3TC_DIR . '/UsageStatistics_Page_ObjectCacheLog_View.php';
+			include W3TC_DIR . '/UsageStatistics_Page_ObjectCacheLog_View.php';
 		} elseif ( ! empty( $view_val ) && 'pagecache_requests' === $view_val ) {
-			$storage = new UsageStatistics_StorageReader();
-			$summary = $storage->get_history_summary();
+			$storage         = new UsageStatistics_StorageReader();
+			$summary         = $storage->get_history_summary();
 			$timestamp_start = $summary['period']['timestamp_start'];
 
 			$sort_val    = Util_Request::get_string( 'sort' );
 			$sort_column = ! empty( $sort_val ) ? $sort_val : '';
-			if ( !in_array( $sort_column, array(
-					'uri', 'count', 'avg_size', 'avg_time_ms',
-					'sum_time_ms' ) ) ) {
+			if (
+				! in_array(
+					$sort_column,
+					array(
+						'uri',
+						'count',
+						'avg_size',
+						'avg_time_ms',
+						'sum_time_ms',
+					),
+					true
+				)
+			) {
 				$sort_column = 'sum_time_ms';
 			}
 
-			if ( !$c->get_boolean( 'pgcache.debug' ) ) {
-				include  W3TC_DIR . '/UsageStatistics_Page_View_NoDebugMode.php';
+			if ( ! $c->get_boolean( 'pgcache.debug' ) ) {
+				include W3TC_DIR . '/UsageStatistics_Page_View_NoDebugMode.php';
 				return;
 			}
 
@@ -113,46 +169,69 @@ public function render() {
 				Util_Request::get_string( 'status' ),
 				$sort_column
 			);
-			$items = $reader->list_entries();
+			$items  = $reader->list_entries();
 
 			$result = array(
-				'date_min' =>
-					Util_UsageStatistics::time_mins( $timestamp_start ),
-				'date_max' => Util_UsageStatistics::time_mins( time() ),
+				'date_min'    => Util_UsageStatistics::time_mins( $timestamp_start ),
+				'date_max'    => Util_UsageStatistics::time_mins( time() ),
 				'sort_column' => $sort_column,
-				'items' => $items
+				'items'       => $items,
 			);
 
-			include  W3TC_DIR . '/UsageStatistics_Page_PageCacheRequests_View.php';
+			include W3TC_DIR . '/UsageStatistics_Page_PageCacheRequests_View.php';
 		} else {
 			$c = Dispatcher::config();
 
 			$php_php_requests_pagecache_hit_name = 'Cache hit';
-			if ( $c->get_boolean( 'pgcache.enabled' ) &&
-				$c->get_string( 'pgcache.engine' ) == 'file_generic' ) {
+			if ( $c->get_boolean( 'pgcache.enabled' ) && 'file_generic' === $c->get_string( 'pgcache.engine' ) ) {
 				$php_php_requests_pagecache_hit_name = 'Cache fallback hit';
 			}
 
-			include  W3TC_DIR . '/UsageStatistics_Page_View.php';
+			include W3TC_DIR . '/UsageStatistics_Page_View.php';
 		}
 	}
 
-
-
+	/**
+	 * Displays a sortable link for the statistics table.
+	 *
+	 * This method generates a sortable link for the statistics page based on the specified column.
+	 * If the column is already the active sort column, it displays the name in bold. Otherwise, it
+	 * creates a link to sort by the specified column.
+	 *
+	 * @param array  $result      The result array containing current sorting information.
+	 * @param string $name        The name of the column to display.
+	 * @param string $sort_column The column name to sort by.
+	 *
+	 * @return void
+	 */
 	public function sort_link( $result, $name, $sort_column ) {
-		if ( $result['sort_column'] == $sort_column ) {
+		if ( $result['sort_column'] === $sort_column ) {
 			echo '<strong>' . esc_html( $name ) . '</strong>';
 			return;
 		}
 
-		$new_query_string = $_GET;
+		$new_query_string         = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 		$new_query_string['sort'] = sanitize_text_field( $sort_column );
 
 		echo '<a href="' . esc_url( 'admin.php?' . http_build_query( $new_query_string ) ) . '">' . esc_html( $name ) . '</a>';
 	}
 
-
-
+	/**
+	 * Displays a checkbox for a summary item on the usage statistics page.
+	 *
+	 * This method generates a checkbox input for a summary item, allowing the user to toggle
+	 * visibility in the chart. It includes additional options like background color and optional
+	 * linking to more detailed statistics.
+	 *
+	 * @param string $id                 The ID of the summary item.
+	 * @param string $name               The name of the summary item.
+	 * @param bool   $checked            Whether the checkbox is checked or not. Default is false.
+	 * @param string $extra_class        Extra CSS classes to apply to the item.
+	 * @param string $column_background  Background color for the column associated with the item.
+	 * @param string $link_key           Optional link key for generating a clickable link.
+	 *
+	 * @return void
+	 */
 	public function summary_item( $id, $name, $checked = false, $extra_class = '', $column_background = '', $link_key = '' ) {
 		echo '<div class="ustats_' . esc_attr( $id ) . ' ' . esc_attr( $extra_class ) . '"><br />';
 		echo '<label>';
@@ -167,8 +246,9 @@ public function summary_item( $id, $name, $checked = false, $extra_class = '', $
 		checked( $checked );
 		echo ' />';
 		if ( ! empty( $link_key ) ) {
-			echo '<a href="' . esc_url( 'admin.php?page=w3tc_stats&view=pagecache_requests&status=' . rawurlencode( $link_key ) .
-				'&status_name=' . rawurlencode( $name ) ) . '">' . esc_html( $name ) . '</a>';
+			$link_url = 'admin.php?page=w3tc_stats&view=pagecache_requests&status=' . rawurlencode( $link_key ) .
+				'&status_name=' . rawurlencode( $name );
+			echo '<a href="' . esc_url( $link_url ) . '">' . esc_html( $name ) . '</a>';
 		} else {
 			echo esc_html( $name );
 		}
@@ -177,5 +257,4 @@ public function summary_item( $id, $name, $checked = false, $extra_class = '', $
 		echo '</label>';
 		echo '</div>';
 	}
-
 }
diff --git a/UsageStatistics_Page_DbRequests_View.php b/UsageStatistics_Page_DbRequests_View.php
index fc5cca546..7d3978d54 100644
--- a/UsageStatistics_Page_DbRequests_View.php
+++ b/UsageStatistics_Page_DbRequests_View.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UsageStatistics_Page_DbRequests_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/UsageStatistics_Page_ObjectCacheLog_View.php b/UsageStatistics_Page_ObjectCacheLog_View.php
index 3f76675ef..6057297f3 100644
--- a/UsageStatistics_Page_ObjectCacheLog_View.php
+++ b/UsageStatistics_Page_ObjectCacheLog_View.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UsageStatistics_Page_ObjectCacheLog_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/UsageStatistics_Page_PageCacheRequests_View.php b/UsageStatistics_Page_PageCacheRequests_View.php
index c850f5a25..2b4ed1a67 100644
--- a/UsageStatistics_Page_PageCacheRequests_View.php
+++ b/UsageStatistics_Page_PageCacheRequests_View.php
@@ -1,4 +1,12 @@
 <?php
+/**
+ * File: UsageStatistics_Page_PageCacheRequests_View.php
+ *
+ * phpcs:disable WordPress.Security.NonceVerification.Recommended
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/UsageStatistics_Page_View.php b/UsageStatistics_Page_View.php
index 51b75f1d1..e987ee555 100644
--- a/UsageStatistics_Page_View.php
+++ b/UsageStatistics_Page_View.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UsageStatistics_Page_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/UsageStatistics_Page_View_Ad.php b/UsageStatistics_Page_View_Ad.php
index 9b5211371..18425f9b9 100644
--- a/UsageStatistics_Page_View_Ad.php
+++ b/UsageStatistics_Page_View_Ad.php
@@ -1,3 +1,13 @@
+<?php
+/**
+ * File: UsageStatistics_Page_View_Ad.php
+ *
+ * @package W3TC
+ */
+
+namespace W3TC;
+
+?>
 <p>
 	<?php esc_html_e( 'Users who upgrade to W3 Total Cache Pro will have access to the new Statistics page, which provides an in-depth view of the performance of your site.', 'w3-total-cache' ); ?>
 </p>
diff --git a/UsageStatistics_Page_View_Disabled.php b/UsageStatistics_Page_View_Disabled.php
index 0531bb06d..0ab351134 100644
--- a/UsageStatistics_Page_View_Disabled.php
+++ b/UsageStatistics_Page_View_Disabled.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UsageStatistics_Page_View_Disabled.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
@@ -11,7 +17,7 @@
 	<?php Util_Ui::postbox_header( esc_html__( 'Usage Statistics', 'w3-total-cache' ) ); ?>
 
 	<div class="ustats_ad">
-		<?php require __DIR__ . '/UsageStatistics_Page_View_Ad.php' ?>
+		<?php require __DIR__ . '/UsageStatistics_Page_View_Ad.php'; ?>
 
 		<a class="button-primary"
 			href="admin.php?page=w3tc_general#stats"><?php esc_html_e( 'Enable here', 'w3-total-cache' ); ?></a>
diff --git a/UsageStatistics_Page_View_Free.php b/UsageStatistics_Page_View_Free.php
index d28b52bd3..0fc4e8962 100644
--- a/UsageStatistics_Page_View_Free.php
+++ b/UsageStatistics_Page_View_Free.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UsageStatistics_Page_View_Free.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/UsageStatistics_Page_View_NoDebugMode.php b/UsageStatistics_Page_View_NoDebugMode.php
index daae0be92..4eccf713e 100644
--- a/UsageStatistics_Page_View_NoDebugMode.php
+++ b/UsageStatistics_Page_View_NoDebugMode.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UsageStatistics_Page_View_NoDebugMode.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
diff --git a/UsageStatistics_Plugin.php b/UsageStatistics_Plugin.php
index 0e492b700..50d5f5141 100644
--- a/UsageStatistics_Plugin.php
+++ b/UsageStatistics_Plugin.php
@@ -1,50 +1,79 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Plugin.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_Plugin
+ */
 class UsageStatistics_Plugin {
+	/**
+	 * Initializes the Usage Statistics functionality and hooks necessary actions and filters.
+	 *
+	 * This method sets up the core component for usage statistics and registers the shutdown handler.
+	 * It also hooks into various actions and filters for handling usage statistics of requests, metrics,
+	 * and metric values. It initializes the `UsageStatistics_Source_Wpdb` component for further handling
+	 * of data storage.
+	 *
+	 * @return void
+	 */
 	public function run() {
 		$core = Dispatcher::component( 'UsageStatistics_Core' );
 		$core->add_shutdown_handler();
 
-		// usage default statistics handling
-		add_action( 'w3tc_usage_statistics_of_request', array(
-				$this, 'w3tc_usage_statistics_of_request' ), 10, 1 );
-		add_filter( 'w3tc_usage_statistics_metrics', array(
-				$this, 'w3tc_usage_statistics_metrics' ) );
-		add_filter( 'w3tc_usage_statistics_metric_values', array(
-				'\W3TC\UsageStatistics_Sources',
-				'w3tc_usage_statistics_metric_values' ) );
-		add_filter( 'w3tc_usage_statistics_history_set', array(
-				'\W3TC\UsageStatistics_Sources',
-				'w3tc_usage_statistics_history_set' ) );
+		// usage default statistics handling.
+		add_action( 'w3tc_usage_statistics_of_request', array( $this, 'w3tc_usage_statistics_of_request' ), 10, 1 );
+		add_filter( 'w3tc_usage_statistics_metrics', array( $this, 'w3tc_usage_statistics_metrics' ) );
+		add_filter( 'w3tc_usage_statistics_metric_values', array( '\W3TC\UsageStatistics_Sources', 'w3tc_usage_statistics_metric_values' ) );
+		add_filter( 'w3tc_usage_statistics_history_set', array( '\W3TC\UsageStatistics_Sources', 'w3tc_usage_statistics_history_set' ) );
 
 		UsageStatistics_Source_Wpdb::init();
 	}
 
-
-
+	/**
+	 * Records usage statistics for the current request, including PHP memory usage and request counts.
+	 *
+	 * This method adds statistics to the provided `$storage` object, such as the amount of PHP memory used
+	 * (in 100KB increments) and the number of PHP requests. Additional statistics for specific environments
+	 * (e.g., WordPress Admin, AJAX) can be included but are currently commented out.
+	 *
+	 * @param object $storage The storage object to which the statistics are added.
+	 *
+	 * @return void
+	 */
 	public function w3tc_usage_statistics_of_request( $storage ) {
 		$used_100kb = memory_get_peak_usage( true ) / 1024 / 10.24;
 
 		$storage->counter_add( 'php_memory_100kb', $used_100kb );
 		$storage->counter_add( 'php_requests', 1 );
 
-/* keep for mode when pagecache not enabled, otherwise it shows own stats similar to that
+		/*
+		Keep for mode when pagecache not enabled, otherwise it shows own stats similar to that
 		if ( defined( 'WP_ADMIN' ) ) {
 			$storage->counter_add( 'php_requests_wp_admin', 1 );
 		}
 		if ( defined( 'DOING_AJAX' ) ) {
 			$storage->counter_add( 'php_requests_ajax', 1 );
 		}
-*/
+		*/
 	}
 
-
-
+	/**
+	 * Adds custom usage metrics to the list of existing metrics.
+	 *
+	 * This method extends the list of metrics by adding custom ones related to PHP memory usage and request counts.
+	 * The metrics include 'php_memory_100kb' and 'php_requests', which help track memory usage and the number
+	 * of PHP requests made during a session.
+	 *
+	 * @param array $metrics The existing list of metrics.
+	 *
+	 * @return array The updated list of metrics with the added custom metrics.
+	 */
 	public function w3tc_usage_statistics_metrics( $metrics ) {
-		return array_merge( $metrics, array(
-				'php_memory_100kb', 'php_requests' ) );
+		return array_merge( $metrics, array( 'php_memory_100kb', 'php_requests' ) );
 	}
 }
diff --git a/UsageStatistics_Plugin_Admin.php b/UsageStatistics_Plugin_Admin.php
index f606b9219..f68ff5364 100644
--- a/UsageStatistics_Plugin_Admin.php
+++ b/UsageStatistics_Plugin_Admin.php
@@ -1,95 +1,153 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Plugin_Admin.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_Plugin_Admin
+ */
 class UsageStatistics_Plugin_Admin {
-	function run() {
+	/**
+	 * Initializes and registers various hooks for the plugin.
+	 *
+	 * This method adds several actions and filters to hook into WordPress' event-driven model.
+	 * It enables AJAX endpoints, adds menu items, and sets up configuration handling,
+	 * all related to the usage statistics functionality.
+	 *
+	 * @return void
+	 */
+	public function run() {
 		$c = Dispatcher::config();
 
 		add_action( 'wp_ajax_ustats_access_log_test', array( $this, 'w3tc_ajax_ustats_access_log_test' ) );
 		add_filter( 'w3tc_admin_menu', array( $this, 'w3tc_admin_menu' ) );
 		add_action( 'w3tc_ajax_ustats_get', array( $this, 'w3tc_ajax_ustats_get' ) );
-		add_filter( 'w3tc_usage_statistics_summary_from_history', array(
-				'W3TC\UsageStatistics_Sources',
-				'w3tc_usage_statistics_summary_from_history'
-			), 5, 2 );
+		add_filter( 'w3tc_usage_statistics_summary_from_history', array( 'W3TC\UsageStatistics_Sources', 'w3tc_usage_statistics_summary_from_history' ), 5, 2 );
 
-		add_action( 'admin_init_w3tc_general', array(
-				'\W3TC\UsageStatistics_GeneralPage',
-				'admin_init_w3tc_general'
-			) );
+		add_action( 'admin_init_w3tc_general', array( '\W3TC\UsageStatistics_GeneralPage', 'admin_init_w3tc_general' ) );
 
-		add_action( 'w3tc_config_ui_save', array(
-				$this,
-				'w3tc_config_ui_save'
-			), 10, 2 );
+		add_action( 'w3tc_config_ui_save', array( $this, 'w3tc_config_ui_save' ), 10, 2 );
 
 		add_filter( 'w3tc_notes', array( $this, 'w3tc_notes' ) );
 	}
 
+	/**
+	 * Handles saving of the configuration when UI settings are changed.
+	 *
+	 * If the 'slot_seconds' value has changed in the configuration, this method
+	 * ensures that all existing statistics are flushed to maintain consistency.
+	 *
+	 * @param object $config     The current configuration object.
+	 * @param object $old_config The previous configuration object.
+	 *
+	 * @return void
+	 */
 	public function w3tc_config_ui_save( $config, $old_config ) {
-		if ( $config->get( 'stats.slot_seconds' ) !=
-				$old_config->get( 'stats.slot_seconds' ) ) {
-			// flush all stats otherwise will be inconsistent
+		if ( $config->get( 'stats.slot_seconds' ) !== $old_config->get( 'stats.slot_seconds' ) ) {
+			// flush all stats otherwise will be inconsistent.
 			$storage = new UsageStatistics_StorageWriter();
 			$storage->reset();
 		}
 	}
 
+	/**
+	 * Adds custom notes to the admin dashboard related to statistics collection.
+	 *
+	 * This method checks if statistics collection is enabled, and if so, it adds a
+	 * note to the WordPress dashboard to inform the user about the resource usage
+	 * and provide options to disable or hide the note.
+	 *
+	 * @param array $notes The current array of notes.
+	 *
+	 * @return array The modified array of notes with the statistics-related note added.
+	 */
 	public function w3tc_notes( $notes ) {
-		$c = Dispatcher::config();
+		$c            = Dispatcher::config();
 		$state_master = Dispatcher::config_state_master();
 
-		if ( $c->get_boolean( 'stats.enabled' ) &&
-				!$state_master->get_boolean( 'common.hide_note_stats_enabled' ) ) {
+		if ( $c->get_boolean( 'stats.enabled' ) && ! $state_master->get_boolean( 'common.hide_note_stats_enabled' ) ) {
 			$notes['stats_enabled'] = sprintf(
-				__( 'W3 Total Cache: Statistics collection is currently enabled. This consumes additional resources, and is not recommended to be run continuously. %s %s',
-					'w3-total-cache' ),
+				// Translators: 1 disable statistics button, 2 hide notes stats button.
+				__(
+					'W3 Total Cache: Statistics collection is currently enabled. This consumes additional resources, and is not recommended to be run continuously. %1$s %2$s',
+					'w3-total-cache'
+				),
 				Util_Ui::button_link(
 					__( 'Disable statistics', 'w3-total-cache' ),
 					Util_Ui::url( array( 'w3tc_ustats_note_disable' => 'y' ) ),
-					false, 'button',
-					'w3tc_note_stats_disable' ),
-				Util_Ui::button_hide_note2( array(
+					false,
+					'button',
+					'w3tc_note_stats_disable'
+				),
+				Util_Ui::button_hide_note2(
+					array(
 						'w3tc_default_config_state_master' => 'y',
-						'key' => 'common.hide_note_stats_enabled',
-						'value' => 'true' ) ) );
+						'key'                              => 'common.hide_note_stats_enabled',
+						'value'                            => 'true',
+					)
+				)
+			);
 		}
 
 		return $notes;
 	}
 
-
-
+	/**
+	 * Adds a custom menu item to the WordPress admin menu.
+	 *
+	 * This method adds a new 'Statistics' page to the admin menu. The page is
+	 * visible only when specifically enabled, and it is positioned with the appropriate
+	 * order in the menu hierarchy.
+	 *
+	 * @param array $menu The existing admin menu array.
+	 *
+	 * @return array The modified admin menu array with the new 'Statistics' item.
+	 */
 	public function w3tc_admin_menu( $menu ) {
 		$menu['w3tc_stats'] = array(
-			'page_title' => __( 'Statistics', 'w3-total-cache' ),
-			'menu_text' => __( 'Statistics', 'w3-total-cache' ),
+			'page_title'     => __( 'Statistics', 'w3-total-cache' ),
+			'menu_text'      => __( 'Statistics', 'w3-total-cache' ),
 			'visible_always' => false,
-			'order' => 2250
+			'order'          => 2250,
 		);
 
 		return $menu;
 	}
 
-
-
+	/**
+	 * Handles the AJAX request to retrieve usage statistics summary.
+	 *
+	 * This method is called when an AJAX request for statistics summary is made.
+	 * It fetches the summary data from storage and returns it as a JSON response.
+	 * The method includes a debug mode where the JSON is pretty-printed.
+	 *
+	 * @return void
+	 */
 	public function w3tc_ajax_ustats_get() {
 		$storage = new UsageStatistics_StorageReader();
 		$summary = $storage->get_history_summary();
 
 		if ( defined( 'W3TC_DEBUG' ) ) {
-			echo json_encode( $summary ,JSON_PRETTY_PRINT );
+			echo wp_json_encode( $summary, JSON_PRETTY_PRINT );
 			exit();
 		}
 
-		echo json_encode( $summary );
+		echo wp_json_encode( $summary );
 		exit();
 	}
 
 	/**
-	 * Ajax: Test access log path.
+	 * Handles the AJAX request to test access to the specified log file.
+	 *
+	 * This method verifies the nonce, checks if a log file path has been provided,
+	 * attempts to open the file, and returns a success or failure message based on
+	 * whether the file could be opened.
+	 *
+	 * @return void
 	 */
 	public function w3tc_ajax_ustats_access_log_test() {
 		$nonce_val = Util_Request::get_array( '_wpnonce' )[0];
@@ -104,7 +162,7 @@ public function w3tc_ajax_ustats_access_log_test() {
 		$filepath     = ! empty( $filename_val ) ? str_replace( '://', '/', $filename_val ) : null;
 
 		if ( $filepath ) {
-			$handle   = @fopen( $filepath, 'rb' ); // phpcs:ignore WordPress
+			$handle = @fopen( $filepath, 'rb' ); // phpcs:ignore WordPress
 		}
 
 		if ( $handle ) {
diff --git a/UsageStatistics_Source_AccessLog.php b/UsageStatistics_Source_AccessLog.php
index bb9aaad97..7bcc9764d 100644
--- a/UsageStatistics_Source_AccessLog.php
+++ b/UsageStatistics_Source_AccessLog.php
@@ -1,111 +1,198 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Plugin.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
+ * Class UsageStatistics_Source_AccessLog
+ *
  * Access log reader - provides statistics data from http server access log
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 class UsageStatistics_Source_AccessLog {
-	// configuration
+	/**
+	 * Regular expression for parsing access log lines.
+	 *
+	 * @var string
+	 */
 	private $line_regexp;
 
+	/**
+	 * The last processed log line during the statistics collection.
+	 *
+	 * @var string
+	 */
 	private $max_line = '';
-	private $max_time = 0;
-	private $min_time;
+
+	/**
+	 * The first processed log line during the statistics collection.
+	 *
+	 * @var string
+	 */
 	private $min_line = '';
 
-	// running values
+	/**
+	 * The maximum timestamp encountered during statistics collection.
+	 *
+	 * @var int
+	 */
+	private $max_time = 0;
+
+	/**
+	 * The minimum timestamp encountered during statistics collection.
+	 *
+	 * @var int
+	 */
+	private $min_time;
 
-	// read access log after that timestamp
+	/**
+	 * Timestamp up to which the access log has been processed already.
+	 * Used to avoid re-processing already counted log entries.
+	 *
+	 * @var int
+	 */
 	private $max_already_counted_timestamp;
 
-	// what was loaded now in this cycle
+	/**
+	 * Timestamp up to which log entries have been processed in the current cycle.
+	 *
+	 * @var int|null
+	 */
 	private $max_now_counted_timestamp = null;
 
-	// if need to read more access log chunks
+	/**
+	 * A flag indicating if more log data needs to be read from the access log file.
+	 *
+	 * @var bool
+	 */
 	private $more_log_needed = true;
 
-	// where data aggregated
+	/**
+	 * The array where aggregated usage statistics are stored.
+	 *
+	 * @var array
+	 */
 	private $history;
+
+	/**
+	 * The current position in the history array for processing log entries.
+	 *
+	 * @var int
+	 */
 	private $history_current_pos;
-	private $history_current_item;
-	private $history_current_timestamp_start;
-	private $history_current_timestamp_end;
 
+	/**
+	 * The current item in the history array representing a specific log entry's aggregated statistics.
+	 *
+	 * @var array
+	 */
+	private $history_current_item;
 
+	/**
+	 * The timestamp marking the start of the current time period for the log entry in history.
+	 *
+	 * @var int
+	 */
+	private $history_current_timestamp_start;
 
-	static public function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
-		$dynamic_requests_total = Util_UsageStatistics::sum( $history,
-			array( 'access_log', 'dynamic_count' ) );
-		$dynamic_timetaken_ms_total = Util_UsageStatistics::sum( $history,
-			array( 'access_log', 'dynamic_timetaken_ms' ) );
-		$static_requests_total = Util_UsageStatistics::sum( $history,
-			array( 'access_log', 'static_count' ) );
-		$static_timetaken_ms_total = Util_UsageStatistics::sum( $history,
-			array( 'access_log', 'static_timetaken_ms' ) );
+	/**
+	 * The timestamp marking the end of the current time period for the log entry in history.
+	 *
+	 * @var int
+	 */
+	private $history_current_timestamp_end;
 
+	/**
+	 * Processes the usage statistics from a history of access logs and adds relevant summary data.
+	 *
+	 * This method sums up dynamic and static request data and calculates average timings for each,
+	 * then integrates the statistics into a given summary array. It's essential for summarizing access log
+	 * statistics for the period represented by the history.
+	 *
+	 * @param array $summary The existing summary data, which will be updated with new information.
+	 * @param array $history The historical access log data to summarize.
+	 *
+	 * @return array The updated summary array with added statistics.
+	 */
+	public static function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
+		$dynamic_requests_total     = Util_UsageStatistics::sum( $history, array( 'access_log', 'dynamic_count' ) );
+		$dynamic_timetaken_ms_total = Util_UsageStatistics::sum( $history, array( 'access_log', 'dynamic_timetaken_ms' ) );
+		$static_requests_total      = Util_UsageStatistics::sum( $history, array( 'access_log', 'static_count' ) );
+		$static_timetaken_ms_total  = Util_UsageStatistics::sum( $history, array( 'access_log', 'static_timetaken_ms' ) );
 
 		$summary['access_log'] = array(
-			'dynamic_requests_total_v' => $dynamic_requests_total,
-			'dynamic_requests_total' => Util_UsageStatistics::integer(
-				$dynamic_requests_total ),
-			'dynamic_requests_per_second' => Util_UsageStatistics::value_per_period_seconds(
-				$dynamic_requests_total, $summary ),
-			'dynamic_requests_timing' => Util_UsageStatistics::integer_divideby(
-				$dynamic_timetaken_ms_total, $dynamic_requests_total ),
-			'static_requests_total' => Util_UsageStatistics::integer(
-				$static_requests_total ),
-			'static_requests_per_second' => Util_UsageStatistics::value_per_period_seconds(
-				$static_requests_total, $summary ),
-			'static_requests_timing' => Util_UsageStatistics::integer_divideby(
-				$static_timetaken_ms_total, $static_requests_total ),
+			'dynamic_requests_total_v'    => $dynamic_requests_total,
+			'dynamic_requests_total'      => Util_UsageStatistics::integer( $dynamic_requests_total ),
+			'dynamic_requests_per_second' => Util_UsageStatistics::value_per_period_seconds( $dynamic_requests_total, $summary ),
+			'dynamic_requests_timing'     => Util_UsageStatistics::integer_divideby( $dynamic_timetaken_ms_total, $dynamic_requests_total ),
+			'static_requests_total'       => Util_UsageStatistics::integer( $static_requests_total ),
+			'static_requests_per_second'  => Util_UsageStatistics::value_per_period_seconds( $static_requests_total, $summary ),
+			'static_requests_timing'      => Util_UsageStatistics::integer_divideby( $static_timetaken_ms_total, $static_requests_total ),
 		);
 
 		return $summary;
 	}
 
-
-
 	/**
-	 * array( 'webserver', 'format', 'filename' )
+	 * Initializes the access log handler with the provided data.
+	 *
+	 * This constructor sets up the necessary properties based on the provided data such as the log format,
+	 * webserver type, and log filename. It also generates a regular expression for parsing the log entries based
+	 * on the webserver type (Nginx or Apache).
+	 *
+	 * @param array $data Data array containing the log format, webserver type, and log filename.
 	 */
 	public function __construct( $data ) {
-		$format = $data['format'];
-		$webserver = $data['webserver'];
+		$format                   = $data['format'];
+		$webserver                = $data['webserver'];
 		$this->accesslog_filename = str_replace( '://', '/', $data['filename'] );
 
-		if ( $webserver == 'nginx' ) {
+		if ( 'nginx' === $webserver ) {
 			$line_regexp = $this->logformat_to_regexp_nginx( $format );
 		} else {
 			$line_regexp = $this->logformat_to_regexp_apache( $format );
 		}
 
-		$this->line_regexp = apply_filters( 'w3tc_ustats_access_log_format_regexp',
-			$line_regexp );
+		$this->line_regexp = apply_filters( 'w3tc_ustats_access_log_format_regexp', $line_regexp );
 	}
 
-
-
+	/**
+	 * Processes the history of access logs and sets the relevant usage statistics.
+	 *
+	 * This method loads the access log file, reads from it to collect usage statistics, and updates the history
+	 * array with data. It ensures that only the relevant logs (those not already processed) are parsed. If the
+	 * log file cannot be opened, it logs an error and returns the history unchanged.
+	 *
+	 * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log
+	 *
+	 * @param array $history The existing history data that will be updated with parsed log statistics.
+	 *
+	 * @return array The updated history data.
+	 */
 	public function w3tc_usage_statistics_history_set( $history ) {
-		$this->max_already_counted_timestamp = (int)get_site_option( 'w3tc_stats_history_access_log' );
-		if ( isset( $history[0]['timestamp_start'] ) &&
-				$history[0]['timestamp_start'] > $this->max_already_counted_timestamp ) {
+		$this->max_already_counted_timestamp = (int) get_site_option( 'w3tc_stats_history_access_log' );
+		if ( isset( $history[0]['timestamp_start'] ) && $history[0]['timestamp_start'] > $this->max_already_counted_timestamp ) {
 			$this->max_already_counted_timestamp = $history[0]['timestamp_start'] - 1;
 		}
 
-		$this->history = $history;
+		$this->history  = $history;
 		$this->min_time = time();
 		$this->setup_history_item( count( $history ) - 1 );
 
 		$h = @fopen( $this->accesslog_filename, 'rb' );
-		if ( !$h ) {
+		if ( ! $h ) {
 			error_log( 'Failed to open access log for usage statisics collection' );
 			return $history;
 		}
 
 		fseek( $h, 0, SEEK_END );
-		$pos = ftell( $h );
+		$pos           = ftell( $h );
 		$unparsed_head = '';
 
 		while ( $pos >= 0 && $this->more_log_needed ) {
@@ -113,6 +200,7 @@ public function w3tc_usage_statistics_history_set( $history ) {
 			if ( $pos <= 0 ) {
 				$pos = 0;
 			}
+
 			fseek( $h, $pos );
 
 			$s = fread( $h, 8192 );
@@ -124,66 +212,84 @@ public function w3tc_usage_statistics_history_set( $history ) {
 		}
 
 		if ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG ) {
-			Util_Debug::log( 'time',
-				"period " .
-				date( DATE_ATOM, $this->max_already_counted_timestamp ) . ' - ' .
-				date( DATE_ATOM, $this->max_now_counted_timestamp ) . "\n" .
-				"min line: " . $this->min_line . "\n" .
-				"max line: " . $this->max_line );
+			Util_Debug::log(
+				'time',
+				'period ' .
+					gmdate( DATE_ATOM, $this->max_already_counted_timestamp ) . ' - ' .
+					gmdate( DATE_ATOM, $this->max_now_counted_timestamp ) . "\n" .
+					'min line: ' . $this->min_line . "\n" .
+					'max line: ' . $this->max_line
+			);
 		}
 
-		if ( !is_null( $this->max_now_counted_timestamp ) ) {
-			update_site_option( 'w3tc_stats_history_access_log',
-				$this->max_now_counted_timestamp );
+		if ( ! is_null( $this->max_now_counted_timestamp ) ) {
+			update_site_option( 'w3tc_stats_history_access_log', $this->max_now_counted_timestamp );
 		}
 
 		return $this->history;
 	}
 
-
-
+	/**
+	 * Initializes a specific history item in the given position.
+	 *
+	 * This method sets up the access log item for the specific position within the history, initializing it with
+	 * default values if not already set. It's essential for tracking the access log statistics across multiple
+	 * history items.
+	 *
+	 * @param int $pos The position in the history array to set up.
+	 */
 	private function setup_history_item( $pos ) {
 		$this->history_current_pos = $pos;
 
-		if ( !isset( $this->history[$pos]['access_log'] ) ) {
-			$this->history[$pos]['access_log'] = array(
-				'dynamic_count' => 0,
+		if ( ! isset( $this->history[ $pos ]['access_log'] ) ) {
+			$this->history[ $pos ]['access_log'] = array(
+				'dynamic_count'        => 0,
 				'dynamic_timetaken_ms' => 0,
-				'static_count' => 0,
-				'static_timetaken_ms' => 0,
+				'static_count'         => 0,
+				'static_timetaken_ms'  => 0,
 			);
 		}
 
-		$this->history_current_item = &$this->history[$pos]['access_log'];
-		$this->history_current_timestamp_start = $this->history[$pos]['timestamp_start'];
-		$this->history_current_timestamp_end = $this->history[$pos]['timestamp_end'];
+		$this->history_current_item            = &$this->history[ $pos ]['access_log'];
+		$this->history_current_timestamp_start = $this->history[ $pos ]['timestamp_start'];
+		$this->history_current_timestamp_end   = $this->history[ $pos ]['timestamp_end'];
 	}
 
-
-
+	/**
+	 * Parses the given log string, processing its lines and collecting statistics.
+	 *
+	 * This method reads the log string, skips the first line if required, and processes each line to collect
+	 * data for usage statistics. It also handles the boundary checks for the collection period and logs
+	 * debugging information if needed.
+	 *
+	 * @param string $s               The log string to parse.
+	 * @param bool   $skip_first_line Whether to skip the first line when parsing.
+	 *
+	 * @return string Any unparsed head of the string.
+	 */
 	private function parse_string( $s, $skip_first_line ) {
-		$s_length = strlen( $s );
+		$s_length      = strlen( $s );
 		$unparsed_head = '';
-		$lines = array();
+		$lines         = array();
 
 		$n = 0;
 		if ( $skip_first_line ) {
 			for ( ; $n < $s_length; $n++ ) {
 				$c = substr( $s, $n, 1 );
-				if ( $c == "\r" || $c == "\n" ) {
+				if ( "\r" === $c || "\n" === $c ) {
 					$unparsed_head = substr( $s, 0, $n + 1 );
 					break;
 				}
 			}
 		}
 
-		$line_start = $n;
-		$line_elements = array();
+		$line_start         = $n;
+		$line_elements      = array();
 		$line_element_start = $n;
 
 		for ( ; $n < $s_length; $n++ ) {
 			$c = substr( $s, $n, 1 );
-			if ( $c == "\r" || $c == "\n" ) {
+			if ( "\r" === $c || "\n" === $c ) {
 				if ( $n > $line_start ) {
 					$lines[] = substr( $s, $line_start, $n - $line_start );
 				}
@@ -192,77 +298,87 @@ private function parse_string( $s, $skip_first_line ) {
 			}
 		}
 
-		// last line comes first, boundary checks logic based on that
+		// last line comes first, boundary checks logic based on that.
 		for ( $n = count( $lines ) - 1; $n >= 0; $n-- ) {
-			$this->push_line( $lines[$n] );
+			$this->push_line( $lines[ $n ] );
 		}
 
 		return $unparsed_head;
 	}
 
-
-
+	/**
+	 * Pushes a single line of log data into the history statistics.
+	 *
+	 * This method processes a single line from the access log, extracting relevant data (such as request time)
+	 * and categorizing the request as either dynamic or static. It updates the statistics for the current history item.
+	 *
+	 * @param string $line The line from the access log to process.
+	 */
 	private function push_line( $line ) {
 		$e = array();
 		preg_match( $this->line_regexp, $line, $e );
 
 		$e = apply_filters( 'w3tc_ustats_access_log_line_elements', $e, $line );
-		if ( !isset( $e['request_line'] ) || !isset( $e['date'] ) ) {
+		if ( ! isset( $e['request_line'] ) || ! isset( $e['date'] ) ) {
 			if ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG ) {
-				Util_Debug::log( 'time',
-					"line $line cant be parsed using regexp $this->line_regexp, request_line or date elements missing"
-				);
+				Util_Debug::log( 'time', "line $line cant be parsed using regexp $this->line_regexp, request_line or date elements missing" );
 			}
+
 			return;
 		}
 
 		$date_string = $e['date'];
-		$time = strtotime($date_string);
+		$time        = strtotime( $date_string );
 
-		// dont read more if we touched entries before timeperiod of collection
+		// dont read more if we touched entries before timeperiod of collection.
 		if ( $time <= $this->max_already_counted_timestamp ) {
 			$this->more_log_needed = false;
 			return;
 		}
+
 		if ( $time > $this->history_current_timestamp_end ) {
 			return;
 		}
+
 		while ( $time < $this->history_current_timestamp_start ) {
 			if ( $this->history_current_pos <= 0 ) {
 				$this->more_log_needed = false;
 				return;
 			}
+
 			$this->setup_history_item( $this->history_current_pos - 1 );
 		}
+
 		if ( is_null( $this->max_now_counted_timestamp ) ) {
 			$this->max_now_counted_timestamp = $time;
 		}
 
 		if ( defined( 'W3TC_DEBUG' ) && W3TC_DEBUG ) {
-			if ($time < $this->min_time) {
+			if ( $time < $this->min_time ) {
 				$this->min_line = $line;
 				$this->min_time = $time;
 			}
-			if ($time > $this->max_time) {
+
+			if ( $time > $this->max_time ) {
 				$this->max_line = $line;
 				$this->max_time = $time;
 			}
 		}
 
-		$http_request_line = $e['request_line'];
+		$http_request_line       = $e['request_line'];
 		$http_request_line_items = explode( ' ', $http_request_line );
-		$uri = $http_request_line_items[1];
+		$uri                     = $http_request_line_items[1];
 
 		$time_ms = 0;
 		if ( isset( $e['time_taken_microsecs'] ) ) {
-			$time_ms = (int)($e['time_taken_microsecs'] / 1000);
+			$time_ms = (int) ( $e['time_taken_microsecs'] / 1000 );
 		} elseif ( isset( $e['time_taken_ms'] ) ) {
-			$time_ms = (int)$e['time_taken_ms'];
+			$time_ms = (int) $e['time_taken_ms'];
 		}
 
 		$m = null;
-		preg_match('~\\.([a-zA-Z0-9]+)(\?.+)?$~', $uri, $m );
-		if ( $m && $m[1] != 'php') {
+		preg_match( '~\\.([a-zA-Z0-9]+)(\?.+)?$~', $uri, $m );
+		if ( $m && 'php' !== $m[1] ) {
 			$this->history_current_item['static_count']++;
 			$this->history_current_item['static_timetaken_ms'] += $time_ms;
 		} else {
@@ -271,112 +387,180 @@ private function push_line( $line ) {
 		}
 	}
 
-
-
-	// default: %h %l %u %t \"%r\" %>s %b
-	// common : %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"
+	/**
+	 * Converts an Apache log format into a regular expression.
+	 *
+	 * This method translates a given Apache log format into a regular expression that can be used to parse
+	 * Apache logs. It handles various Apache log format variables and removes unnecessary modifiers.
+	 *
+	 * default: %h %l %u %t \"%r\" %>s %b
+	 * common : %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"
+	 *
+	 * @param string $format The Apache log format string.
+	 *
+	 * @return string The regular expression to parse Apache logs.
+	 */
 	public function logformat_to_regexp_apache( $format ) {
-		// remove modifiers like %>s, %!400,501{User-agent}i
-		$format = preg_replace('~%[<>!0-9]([a-zA-Z{])~', '%$1', $format);
+		// remove modifiers like %>s, %!400,501{User-agent}i.
+		$format = preg_replace( '~%[<>!0-9]([a-zA-Z{])~', '%$1', $format );
 
-		// remove modifiers %{User-agent}^ti, %{User-agent}^to
-		$format = preg_replace('~%({[^}]+})(^ti|^to)~', '%$1z', $format);
+		// remove modifiers %{User-agent}^ti, %{User-agent}^to.
+		$format = preg_replace( '~%({[^}]+})(^ti|^to)~', '%$1z', $format );
 
-		// take all quoted vars
-		$format = preg_replace_callback('~\\\"(%[a-zA-Z%]|%{[^}]+}[a-zA-Z])\\\"~',
+		// take all quoted vars.
+		$format = preg_replace_callback(
+			'~\\\"(%[a-zA-Z%]|%{[^}]+}[a-zA-Z])\\\"~',
 			array( $this, 'logformat_to_regexp_apache_element_quoted' ),
-			$format);
+			$format
+		);
 
-		// take all remaining vars
-		$format = preg_replace_callback('~(%[a-zA-Z%]|%{[^}]+}[a-zA-Z])~',
+		// take all remaining vars.
+		$format = preg_replace_callback(
+			'~(%[a-zA-Z%]|%{[^}]+}[a-zA-Z])~',
 			array( $this, 'logformat_to_regexp_apache_element_naked' ),
-			$format);
+			$format
+		);
 
 		return '~' . $format . '~';
 	}
 
-
-
+	/**
+	 * Converts a quoted Apache log format element into a regular expression.
+	 *
+	 * This method handles the conversion of quoted log elements (e.g., request lines) from Apache log format
+	 * to the corresponding regular expression pattern.
+	 *
+	 * @param array $match The matched portion of the log format.
+	 *
+	 * @return string The regular expression for the quoted log element.
+	 */
 	public function logformat_to_regexp_apache_element_quoted( $match ) {
 		$v = $match[1];
 
-		if ( $v == '%r' ) {
+		if ( '%r' === $v ) {
 			return '\"(?<request_line>[^"]+)\"';
 		}
 
-		// default behavior, expected value doesnt contain spaces
+		// default behavior, expected value doesnt contain spaces.
 		return '\"([^"]+)\"';
 	}
 
-
-
+	/**
+	 * Converts a non-quoted Apache log format element into a regular expression.
+	 *
+	 * This method handles the conversion of unquoted log elements (e.g., timestamps or status codes) from
+	 * Apache log format to the corresponding regular expression pattern.
+	 *
+	 * @param array $match The matched portion of the log format.
+	 *
+	 * @return string The regular expression for the non-quoted log element.
+	 */
 	public function logformat_to_regexp_apache_element_naked( $match ) {
 		$v = $match[1];
 
-		if ( $v == '%t' ) {
+		if ( '%t' === $v ) {
 			return '\[(?<date>[^\]]+)\]';
-		} elseif ( $v == '%D' ) {
+		} elseif ( '%D' === $v ) {
 			return '(?<time_taken_microsecs>[0-9]+)';
 		}
 
-		// default behavior, expected value doesnt contain spaces
+		// default behavior, expected value doesnt contain spaces.
 		return '([^ ]+)';
 	}
 
-
-
-	// default: $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"
-	// w3tc: $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time
+	/**
+	 * Converts an Nginx log format into a regular expression.
+	 *
+	 * This method translates a given Nginx log format into a regular expression that can be used to parse
+	 * Nginx logs. It handles various Nginx log format variables and escapes any quotes or special characters.
+	 *
+	 * default: $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"
+	 * w3tc:    $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time
+	 *
+	 * @param string $format The Nginx log format string.
+	 *
+	 * @return string The regular expression to parse Nginx logs.
+	 */
 	public function logformat_to_regexp_nginx( $format ) {
-		// escape quotes
-		$format = preg_replace_callback('~([\"\[\]])~',
+		// escape quotes.
+		$format = preg_replace_callback(
+			'~([\"\[\]])~',
 			array( $this, 'logformat_to_regexp_nginx_quote' ),
-			$format);
+			$format
+		);
 
-		// take all quoted vars
-		$format = preg_replace_callback('~\\\"(\$[a-zA-Z0-9_]+)\\\"~',
+		// take all quoted vars.
+		$format = preg_replace_callback(
+			'~\\\"(\$[a-zA-Z0-9_]+)\\\"~',
 			array( $this, 'logformat_to_regexp_nginx_element_quoted' ),
-			$format);
+			$format
+		);
 
-		// take all remaining vars
-		$format = preg_replace_callback('~(\$[a-zA-Z0-9_]+)~',
+		// take all remaining vars.
+		$format = preg_replace_callback(
+			'~(\$[a-zA-Z0-9_]+)~',
 			array( $this, 'logformat_to_regexp_nginx_element_naked' ),
-			$format);
+			$format
+		);
 
 		return '~' . $format . '~';
 	}
 
-
-
+	/**
+	 * Escapes quotes in the Nginx log format.
+	 *
+	 * This method ensures that any quotes in the Nginx log format are properly escaped for use in a regular
+	 * expression.
+	 *
+	 * @param array $match The matched quote from the Nginx log format.
+	 *
+	 * @return string The escaped quote.
+	 */
 	public function logformat_to_regexp_nginx_quote( $match ) {
 		return '\\' . $match[1];
 	}
 
-
-
+	/**
+	 * Converts a quoted Nginx log format element into a regular expression.
+	 *
+	 * This method handles the conversion of quoted log elements (e.g., request lines) from Nginx log format
+	 * to the corresponding regular expression pattern.
+	 *
+	 * @param array $match The matched portion of the log format.
+	 *
+	 * @return string The regular expression for the quoted log element.
+	 */
 	public function logformat_to_regexp_nginx_element_quoted( $match ) {
 		$v = $match[1];
 
-		if ( $v == '$request' ) {
+		if ( '$request' === $v ) {
 			return '\"(?<request_line>[^"]+)\"';
 		}
 
-		// default behavior, expected value doesnt contain spaces
+		// default behavior, expected value doesnt contain spaces.
 		return '\"([^"]+)\"';
 	}
 
-
-
+	/**
+	 * Converts a non-quoted Nginx log format element into a regular expression.
+	 *
+	 * This method handles the conversion of unquoted log elements (e.g., timestamps or request times) from
+	 * Nginx log format to the corresponding regular expression pattern.
+	 *
+	 * @param array $match The matched portion of the log format.
+	 *
+	 * @return string The regular expression for the non-quoted log element.
+	 */
 	public function logformat_to_regexp_nginx_element_naked( $match ) {
 		$v = $match[1];
 
-		if ( $v == '$time_local' ) {
+		if ( '$time_local' === $v ) {
 			return '(?<date>[^\]]+)';
-		} elseif ( $v == '$request_time' ) {
+		} elseif ( '$request_time' === $v ) {
 			return '(?<time_taken_ms>[0-9.]+)';
 		}
 
-		// default behavior, expected value doesnt contain spaces
+		// default behavior, expected value doesnt contain spaces.
 		return '([^ ]+)';
 	}
 }
diff --git a/UsageStatistics_Source_DbQueriesLog.php b/UsageStatistics_Source_DbQueriesLog.php
index 7c31cc64f..e8de15d2b 100644
--- a/UsageStatistics_Source_DbQueriesLog.php
+++ b/UsageStatistics_Source_DbQueriesLog.php
@@ -1,40 +1,82 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Source_DbQueriesLog.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
- * database queries debug log reader - provides data from this logfile
+ * Class UsageStatistics_Source_DbQueriesLog
+ *
+ * Database queries debug log reader - provides data from this logfile
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 class UsageStatistics_Source_DbQueriesLog {
-	// running values
+	/**
+	 * The timestamp representing the start time for filtering log entries.
+	 *
+	 * @var int
+	 */
 	private $timestamp_start;
+
+	/**
+	 * The column by which the log entries should be sorted.
+	 *
+	 * @var string
+	 */
 	private $sort_column;
 
+	/**
+	 * The associative array holding query data by query string.
+	 *
+	 * @var array
+	 */
 	private $by_query = array();
 
-	/* if need to read more access log chunks */
+	/**
+	 * Flag indicating whether more log entries are needed for parsing.
+	 *
+	 * @var bool
+	 */
 	private $more_log_needed = true;
 
-
-
-	function __construct( $timestamp_start, $sort_column ) {
+	/**
+	 * Constructor for initializing the object with a start timestamp and sort column.
+	 *
+	 * @param int    $timestamp_start The timestamp representing the start time for filtering log entries.
+	 * @param string $sort_column     The column by which the log entries should be sorted.
+	 *
+	 * @return void
+	 */
+	public function __construct( $timestamp_start, $sort_column ) {
 		$this->timestamp_start = $timestamp_start;
-		$this->sort_column = $sort_column;
+		$this->sort_column     = $sort_column;
 	}
 
 	/**
-	 * Lists entries from log
-	 **/
+	 * Retrieves and processes log entries, sorting them based on the specified column, and returns the top 200 entries.
+	 *
+	 * This method reads the log file from the end, processes the data, and filters based on the timestamp.
+	 * The results are returned as an array containing various statistics such as query counts, average size, and time.
+	 *
+	 * @return array An array of sorted log entries containing statistics about queries such as total count, hit count,
+	 *               average size, average time, total time, and reasons.
+	 *
+	 * @throws \Exception If the log file cannot be opened.
+	 */
 	public function list_entries() {
 		$log_filename = Util_Debug::log_filename( 'dbcache-queries' );
-		$h = @fopen( $log_filename, 'rb' );
-		if ( !$h ) {
+		$h            = @fopen( $log_filename, 'rb' );
+		if ( ! $h ) {
 			throw new \Exception( 'Failed to open log file' . $log_filename );
 		}
 
 		fseek( $h, 0, SEEK_END );
-		$pos = ftell( $h );
+		$pos           = ftell( $h );
 		$unparsed_head = '';
 
 		while ( $pos >= 0 && $this->more_log_needed ) {
@@ -42,6 +84,7 @@ public function list_entries() {
 			if ( $pos <= 0 ) {
 				$pos = 0;
 			}
+
 			fseek( $h, $pos );
 
 			$s = fread( $h, 8192 );
@@ -55,36 +98,48 @@ public function list_entries() {
 		$output = array();
 		foreach ( $this->by_query as $query => $data ) {
 			$output[] = array(
-				'query' => $query,
+				'query'       => $query,
 				'count_total' => $data['count_total'],
-				'count_hit' => $data['count_hit'],
-				'avg_size' => (int)( $data['sum_size'] / $data['count_total'] ),
-				'avg_time_ms' => (int)( $data['sum_time_ms'] / $data['count_total'] ),
-				'sum_time_ms' => (int)$data['sum_time_ms'],
-				'reasons' => $data['reasons']
+				'count_hit'   => $data['count_hit'],
+				'avg_size'    => (int) ( $data['sum_size'] / $data['count_total'] ),
+				'avg_time_ms' => (int) ( $data['sum_time_ms'] / $data['count_total'] ),
+				'sum_time_ms' => (int) $data['sum_time_ms'],
+				'reasons'     => $data['reasons'],
 			);
 		}
 
-		usort( $output, function($a, $b) {
-			return (int)($b[$this->sort_column]) - (int)($a[$this->sort_column]);
-		});
+		usort(
+			$output,
+			function( $a, $b ) {
+				return (int) ( $b[ $this->sort_column ] ) - (int) ( $a[ $this->sort_column ] );
+			}
+		);
 
 		$output = array_slice( $output, 0, 200 );
 
 		return $output;
 	}
 
-
-
+	/**
+	 * Parses a string of log data, processing individual lines and pushing relevant information to be analyzed.
+	 *
+	 * This method processes a chunk of log data, handling the option to skip the first line and breaking the data into
+	 * individual lines for further analysis.
+	 *
+	 * @param string $s               The log data string to be parsed.
+	 * @param bool   $skip_first_line Whether to skip the first line of the string.
+	 *
+	 * @return string The unparsed head of the log data, if any.
+	 */
 	private function parse_string( $s, $skip_first_line ) {
-		$s_length = strlen( $s );
+		$s_length      = strlen( $s );
 		$unparsed_head = '';
 
 		$n = 0;
 		if ( $skip_first_line ) {
 			for ( ; $n < $s_length; $n++ ) {
 				$c = substr( $s, $n, 1 );
-				if ( $c == "\r" || $c == "\n" ) {
+				if ( "\r" === $c || "\n" === $c ) {
 					$unparsed_head = substr( $s, 0, $n + 1 );
 					break;
 				}
@@ -94,7 +149,7 @@ private function parse_string( $s, $skip_first_line ) {
 		$line_start = $n;
 		for ( ; $n < $s_length; $n++ ) {
 			$c = substr( $s, $n, 1 );
-			if ( $c == "\r" || $c == "\n" ) {
+			if ( "\r" === $c || "\n" === $c ) {
 				if ( $n > $line_start ) {
 					$this->push_line( substr( $s, $line_start, $n - $line_start ) );
 				}
@@ -106,48 +161,56 @@ private function parse_string( $s, $skip_first_line ) {
 		return $unparsed_head;
 	}
 
-
-
+	/**
+	 * Processes a single line of log data, extracting relevant information and updating the query statistics.
+	 *
+	 * This method parses a line of log data, updating the query statistics for the given query (e.g., count, size, time, etc.).
+	 * It also checks if more log data is needed based on the timestamp and ensures that data for each query is stored appropriately.
+	 *
+	 * @param string $line The log line to be processed.
+	 *
+	 * @return void
+	 */
 	private function push_line( $line ) {
 		$matches = str_getcsv( $line, "\t" );
 
-		if ( !$matches ) {
+		if ( ! $matches ) {
 			return;
 		}
 
-		$date_string = $matches[0];
-		$query = $matches[2];
-		$time_taken_ms = isset( $matches[3] ) ? (float)$matches[3] / 1000 : 0;
-		$reason = isset( $matches[4] ) ? $matches[4] : '';
-		$hit = isset( $matches[5] ) ? $matches[5] : false;
-		$size = isset( $matches[6] ) ? $matches[6] : 0;
+		$date_string   = $matches[0];
+		$query         = $matches[2];
+		$time_taken_ms = isset( $matches[3] ) ? (float) $matches[3] / 1000 : 0;
+		$reason        = isset( $matches[4] ) ? $matches[4] : '';
+		$hit           = isset( $matches[5] ) ? $matches[5] : false;
+		$size          = isset( $matches[6] ) ? $matches[6] : 0;
 
-		$time = strtotime($date_string);
+		$time = strtotime( $date_string );
 
-		// dont read more if we touched entries before timeperiod of collection
+		// dont read more if we touched entries before timeperiod of collection.
 		if ( $time < $this->timestamp_start ) {
 			$this->more_log_needed = false;
 		}
 
-		if ( !isset( $this->by_query[$query] ) ) {
-			$this->by_query[$query] = array(
+		if ( ! isset( $this->by_query[ $query ] ) ) {
+			$this->by_query[ $query ] = array(
 				'count_total' => 0,
-				'count_hit' => 0,
-				'sum_size' => 0,
+				'count_hit'   => 0,
+				'sum_size'    => 0,
 				'sum_time_ms' => 0,
-				'reasons' => array()
+				'reasons'     => array(),
 			);
 		}
 
-		$this->by_query[$query]['count_total']++;
-		if ($hit) {
-			$this->by_query[$query]['count_hit']++;
+		$this->by_query[ $query ]['count_total']++;
+		if ( $hit ) {
+			$this->by_query[ $query ]['count_hit']++;
 		}
-		$this->by_query[$query]['sum_size'] += $size;
-		$this->by_query[$query]['sum_time_ms'] += $time_taken_ms;
+		$this->by_query[ $query ]['sum_size']    += $size;
+		$this->by_query[ $query ]['sum_time_ms'] += $time_taken_ms;
 
-		if ( !in_array( $reason, $this->by_query[$query]['reasons']) ) {
-			$this->by_query[$query]['reasons'][] = $reason;
+		if ( ! in_array( $reason, $this->by_query[ $query ]['reasons'], true ) ) {
+			$this->by_query[ $query ]['reasons'][] = $reason;
 		}
 	}
 }
diff --git a/UsageStatistics_Source_ObjectCacheLog.php b/UsageStatistics_Source_ObjectCacheLog.php
index 4a4d46b37..3d2e4fec5 100644
--- a/UsageStatistics_Source_ObjectCacheLog.php
+++ b/UsageStatistics_Source_ObjectCacheLog.php
@@ -1,40 +1,79 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Source_DbQueriesLog.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
- * database queries debug log reader - provides data from this logfile
+ * Class UsageStatistics_Source_ObjectCacheLog
+ *
+ * Database queries debug log reader - provides data from this logfile
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 class UsageStatistics_Source_ObjectCacheLog {
-	// running values
+	/**
+	 * The timestamp marking the start time for log entries to process.
+	 *
+	 * @var int
+	 */
 	private $timestamp_start;
+
+	/**
+	 * The column used to sort the output of log entries.
+	 *
+	 * @var string
+	 */
 	private $sort_column;
 
+	/**
+	 * Stores the log data grouped by category for analysis.
+	 *
+	 * @var array
+	 */
 	private $by_group = array();
 
-	/* if need to read more access log chunks */
+	/**
+	 * Flag to determine if more log data needs to be read.
+	 *
+	 * @var bool
+	 */
 	private $more_log_needed = true;
 
-
-
-	function __construct( $timestamp_start, $sort_column ) {
+	/**
+	 * Constructor to initialize the object cache log processing.
+	 *
+	 * @param int    $timestamp_start The timestamp marking the start of the log entry range.
+	 * @param string $sort_column     The column name to sort the log entries.
+	 *
+	 * @return void
+	 */
+	public function __construct( $timestamp_start, $sort_column ) {
 		$this->timestamp_start = $timestamp_start;
-		$this->sort_column = $sort_column;
+		$this->sort_column     = $sort_column;
 	}
 
 	/**
-	 * Lists entries from log
-	 **/
+	 * Lists the entries from the log file, processing and grouping them.
+	 * The entries are filtered, parsed, and then sorted according to the provided column.
+	 *
+	 * @return array The processed log entries, sorted and grouped as per the configuration.
+	 *
+	 * @throws \Exception If the log file cannot be opened.
+	 */
 	public function list_entries() {
 		$log_filename = Util_Debug::log_filename( 'objectcache-calls' );
-		$h = @fopen( $log_filename, 'rb' );
-		if ( !$h ) {
+		$h            = @fopen( $log_filename, 'rb' );
+		if ( ! $h ) {
 			throw new \Exception( 'Failed to open log file' . $log_filename );
 		}
 
 		fseek( $h, 0, SEEK_END );
-		$pos = ftell( $h );
+		$pos           = ftell( $h );
 		$unparsed_head = '';
 
 		while ( $pos >= 0 && $this->more_log_needed ) {
@@ -42,6 +81,7 @@ public function list_entries() {
 			if ( $pos <= 0 ) {
 				$pos = 0;
 			}
+
 			fseek( $h, $pos );
 
 			$s = fread( $h, 8192 );
@@ -55,37 +95,46 @@ public function list_entries() {
 		$output = array();
 		foreach ( $this->by_group as $group => $data ) {
 			$output[] = array(
-				'group' => $group,
-				'count_total' => $data['count_total'],
+				'group'           => $group,
+				'count_total'     => $data['count_total'],
 				'count_get_total' => $data['count_get_total'],
-				'count_get_hit' => $data['count_get_hit'],
-				'count_set' => $data['count_set'],
-				'sum_size' => $data['sum_size'],
-				'avg_size' => $data['count_total'] ? (int)( $data['sum_size'] / $data['count_total'] ) : 0,
-				'sum_time_ms' => (int)$data['sum_time_ms']
+				'count_get_hit'   => $data['count_get_hit'],
+				'count_set'       => $data['count_set'],
+				'sum_size'        => $data['sum_size'],
+				'avg_size'        => $data['count_total'] ? (int) ( $data['sum_size'] / $data['count_total'] ) : 0,
+				'sum_time_ms'     => (int) $data['sum_time_ms'],
 			);
 		}
 
-		usort( $output, function($a, $b) {
-			return (int)($b[$this->sort_column]) - (int)($a[$this->sort_column]);
-		});
+		usort(
+			$output,
+			function( $a, $b ) {
+				return (int) ( $b[ $this->sort_column ] ) - (int) ( $a[ $this->sort_column ] );
+			}
+		);
 
 		$output = array_slice( $output, 0, 200 );
 
 		return $output;
 	}
 
-
-
+	/**
+	 * Parses the string data from the log file and pushes individual lines to the processing function.
+	 *
+	 * @param string $s               The raw string to parse.
+	 * @param bool   $skip_first_line Flag to indicate if the first line should be skipped.
+	 *
+	 * @return string The unparsed portion of the string, if any.
+	 */
 	private function parse_string( $s, $skip_first_line ) {
-		$s_length = strlen( $s );
+		$s_length      = strlen( $s );
 		$unparsed_head = '';
 
 		$n = 0;
 		if ( $skip_first_line ) {
 			for ( ; $n < $s_length; $n++ ) {
 				$c = substr( $s, $n, 1 );
-				if ( $c == "\r" || $c == "\n" ) {
+				if ( "\r" === $c || "\n" === $c ) {
 					$unparsed_head = substr( $s, 0, $n + 1 );
 					break;
 				}
@@ -95,7 +144,7 @@ private function parse_string( $s, $skip_first_line ) {
 		$line_start = $n;
 		for ( ; $n < $s_length; $n++ ) {
 			$c = substr( $s, $n, 1 );
-			if ( $c == "\r" || $c == "\n" ) {
+			if ( "\r" === $c || "\n" === $c ) {
 				if ( $n > $line_start ) {
 					$this->push_line( substr( $s, $line_start, $n - $line_start ) );
 				}
@@ -107,58 +156,62 @@ private function parse_string( $s, $skip_first_line ) {
 		return $unparsed_head;
 	}
 
-
-
+	/**
+	 * Processes a single line from the log file, extracting relevant details and updating group statistics.
+	 *
+	 * @param string $line The log line to process.
+	 *
+	 * @return void
+	 */
 	private function push_line( $line ) {
 		$matches = str_getcsv( $line, "\t" );
 
-		if ( !$matches ) {
+		if ( ! $matches ) {
 			return;
 		}
 
-		$date_string = $matches[0];
-		$op = $matches[1];
-		$group = $matches[2];
-		$id = $matches[3];
-		$reason = $matches[4];
-		$size = (int)$matches[5];
-		$time_taken_ms = isset( $matches[6] ) ? (float)$matches[6] / 1000 : 0;
+		$date_string   = $matches[0];
+		$op            = $matches[1];
+		$group         = $matches[2];
+		$id            = $matches[3];
+		$reason        = $matches[4];
+		$size          = (int) $matches[5];
+		$time_taken_ms = isset( $matches[6] ) ? (float) $matches[6] / 1000 : 0;
 
-		$time = strtotime($date_string);
+		$time = strtotime( $date_string );
 
-		// dont read more if we touched entries before timeperiod of collection
+		// dont read more if we touched entries before timeperiod of collection.
 		if ( $time < $this->timestamp_start ) {
 			$this->more_log_needed = false;
 		}
 
-		if ( $reason == 'not tried cache' ||
-			substr( $reason, 0, 7 ) == 'not set' ) {
-			return;   // it's not cache-related activity
+		if ( 'not tried cache' === $reason || 'not set' === substr( $reason, 0, 7 ) ) {
+			return; // it's not cache-related activity.
 		}
 
-		if ( !isset( $this->by_group[$group] ) ) {
-			$this->by_group[$group] = array(
-				'count_total' => 0,
+		if ( ! isset( $this->by_group[ $group ] ) ) {
+			$this->by_group[ $group ] = array(
+				'count_total'     => 0,
 				'count_get_total' => 0,
-				'count_get_hit' => 0,
-				'count_set' => 0,
-				'sum_size' => 0,
-				'sum_time_ms' => 0
+				'count_get_hit'   => 0,
+				'count_set'       => 0,
+				'sum_size'        => 0,
+				'sum_time_ms'     => 0,
 			);
 		}
 
-		if ( $op == 'get' ) {
-			$this->by_group[$group]['count_total']++;
-			$this->by_group[$group]['count_get_total']++;
-			if ($reason == 'from persistent cache') {
-				$this->by_group[$group]['count_get_hit']++;
+		if ( 'get' === $op ) {
+			$this->by_group[ $group ]['count_total']++;
+			$this->by_group[ $group ]['count_get_total']++;
+			if ( 'from persistent cache' === $reason ) {
+				$this->by_group[ $group ]['count_get_hit']++;
 			}
-		} elseif ( $op == 'set' ) {
-			$this->by_group[$group]['count_total']++;
-			$this->by_group[$group]['count_set']++;
+		} elseif ( 'set' === $op ) {
+			$this->by_group[ $group ]['count_total']++;
+			$this->by_group[ $group ]['count_set']++;
 		}
 
-		$this->by_group[$group]['sum_size'] += $size;
-		$this->by_group[$group]['sum_time_ms'] += $time_taken_ms;
+		$this->by_group[ $group ]['sum_size']    += $size;
+		$this->by_group[ $group ]['sum_time_ms'] += $time_taken_ms;
 	}
 }
diff --git a/UsageStatistics_Source_PageCacheLog.php b/UsageStatistics_Source_PageCacheLog.php
index 52651bf88..f2e18d9b6 100644
--- a/UsageStatistics_Source_PageCacheLog.php
+++ b/UsageStatistics_Source_PageCacheLog.php
@@ -1,42 +1,92 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Source_DbQueriesLog.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
+ * Class UsageStatistics_Source_PageCacheLog
+ *
  * PageCache debug log reader - provides data from this logfile
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.AlternativeFunctions
  */
 class UsageStatistics_Source_PageCacheLog {
-	// running values
+	/**
+	 * Timestamp indicating the start time for log processing.
+	 *
+	 * @var int
+	 */
 	private $timestamp_start;
+
+	/**
+	 * Current process status used to filter logs.
+	 *
+	 * @var string
+	 */
 	private $process_status;
+
+	/**
+	 * Column used for sorting the final log entries output.
+	 *
+	 * @var string
+	 */
 	private $sort_column;
 
+	/**
+	 * Holds URI data parsed from the log file, including count, sum size, sum time, and reasons.
+	 *
+	 * @var array
+	 */
 	private $by_uri = array();
 
-	/* if need to read more access log chunks */
+	/**
+	 * Flag indicating whether more log entries are required to be processed.
+	 *
+	 * @var bool
+	 */
 	private $more_log_needed = true;
 
-
-
-	function __construct( $timestamp_start, $process_status, $sort_column ) {
+	/**
+	 * Constructor to initialize the class attributes.
+	 *
+	 * @param int    $timestamp_start The start timestamp for the log processing.
+	 * @param string $process_status  The process status to filter the logs by.
+	 * @param string $sort_column     The column to sort the final results by.
+	 *
+	 * @return void
+	 */
+	public function __construct( $timestamp_start, $process_status, $sort_column ) {
 		$this->timestamp_start = $timestamp_start;
-		$this->process_status = $process_status;
-		$this->sort_column = $sort_column;
+		$this->process_status  = $process_status;
+		$this->sort_column     = $sort_column;
 	}
 
 	/**
-	 * Lists entries from log with specified cache reject reason code
-	 **/
+	 * Lists all the parsed log entries, sorted by the specified column.
+	 *
+	 * This method reads the log file, processes it in reverse order, and accumulates the relevant data
+	 * about each URI, such as the count of occurrences, average size, average time taken,
+	 * and unique reasons for the status. It returns a sorted list of the data based on the selected column.
+	 *
+	 * @return array List of log entries, each containing URI, count, average size,
+	 *               average time in milliseconds, total time, and reasons.
+	 *
+	 * @throws \Exception If the log file cannot be opened.
+	 */
 	public function list_entries() {
 		$log_filename = Util_Debug::log_filename( 'pagecache' );
-		$h = @fopen( $log_filename, 'rb' );
-		if ( !$h ) {
+		$h            = @fopen( $log_filename, 'rb' );
+		if ( ! $h ) {
 			throw new \Exception( 'Failed to open pagecache log file' . $log_filename );
 		}
 
 		fseek( $h, 0, SEEK_END );
-		$pos = ftell( $h );
+		$pos           = ftell( $h );
 		$unparsed_head = '';
 
 		while ( $pos >= 0 && $this->more_log_needed ) {
@@ -44,6 +94,7 @@ public function list_entries() {
 			if ( $pos <= 0 ) {
 				$pos = 0;
 			}
+
 			fseek( $h, $pos );
 
 			$s = fread( $h, 8192 );
@@ -57,33 +108,45 @@ public function list_entries() {
 		$output = array();
 		foreach ( $this->by_uri as $uri => $data ) {
 			$output[] = array(
-				'uri' => $uri,
-				'count' => $data['count'],
-				'avg_size' => (int)( $data['sum_size'] / $data['count'] ),
-				'avg_time_ms' => (int)( $data['sum_time_ms'] / $data['count'] ),
+				'uri'         => $uri,
+				'count'       => $data['count'],
+				'avg_size'    => (int) ( $data['sum_size'] / $data['count'] ),
+				'avg_time_ms' => (int) ( $data['sum_time_ms'] / $data['count'] ),
 				'sum_time_ms' => $data['sum_time_ms'],
-				'reasons' => $data['reasons']
+				'reasons'     => $data['reasons'],
 			);
 		}
 
-		usort( $output, function($a, $b) {
-			return (int)($b[$this->sort_column]) - (int)($a[$this->sort_column]);
-		});
+		usort(
+			$output,
+			function( $a, $b ) {
+				return (int) ( $b[ $this->sort_column ] ) - (int) ( $a[ $this->sort_column ] );
+			}
+		);
 
 		return $output;
 	}
 
-
-
+	/**
+	 * Parses the provided string and processes each line of log data.
+	 *
+	 * This method processes the log data in chunks and parses each line for relevant information.
+	 * It will skip the first line if required and handle the raw log string by calling `push_line` for each parsed line.
+	 *
+	 * @param string $s               The string to be parsed.
+	 * @param bool   $skip_first_line Flag to indicate whether the first line should be skipped.
+	 *
+	 * @return string Unparsed head of the log data that remains after parsing.
+	 */
 	private function parse_string( $s, $skip_first_line ) {
-		$s_length = strlen( $s );
+		$s_length      = strlen( $s );
 		$unparsed_head = '';
 
 		$n = 0;
 		if ( $skip_first_line ) {
 			for ( ; $n < $s_length; $n++ ) {
 				$c = substr( $s, $n, 1 );
-				if ( $c == "\r" || $c == "\n" ) {
+				if ( "\r" === $c || "\n" === $c ) {
 					$unparsed_head = substr( $s, 0, $n + 1 );
 					break;
 				}
@@ -93,7 +156,7 @@ private function parse_string( $s, $skip_first_line ) {
 		$line_start = $n;
 		for ( ; $n < $s_length; $n++ ) {
 			$c = substr( $s, $n, 1 );
-			if ( $c == "\r" || $c == "\n" ) {
+			if ( "\r" === $c || "\n" === $c ) {
 				if ( $n > $line_start ) {
 					$this->push_line( substr( $s, $line_start, $n - $line_start ) );
 				}
@@ -105,50 +168,61 @@ private function parse_string( $s, $skip_first_line ) {
 		return $unparsed_head;
 	}
 
-
-
+	/**
+	 * Processes and stores the data from a single log line.
+	 *
+	 * This method matches the log line against a regular expression and extracts details such as the URI,
+	 * time taken, size, process status, and the reason. If the log line meets the filter criteria (e.g.,
+	 * matching the process status and timestamp), the relevant information is added to the `$by_uri` attribute.
+	 *
+	 * @param string $line A single line of log data to be processed.
+	 *
+	 * @return void
+	 */
 	private function push_line( $line ) {
 		$matches = null;
 		preg_match(
 			'/\[([^>\]]+)\] \[([^>\]]+)\] \[([^>\]]+)\] finished in (\d+) size (\d+) with process status ([^ ]+) reason (.*)/',
-			$line, $matches);
+			$line,
+			$matches
+		);
 
-		if ( !$matches ) {
+		if ( ! $matches ) {
 			return;
 		}
 
-		$date_string = $matches[1];
-		$uri = $matches[2];
+		$date_string   = $matches[1];
+		$uri           = $matches[2];
 		$time_taken_ms = $matches[4];
-		$size = $matches[5];
-		$status = $matches[6];
-		$reason = $matches[7];
-		$time = strtotime($date_string);
+		$size          = $matches[5];
+		$status        = $matches[6];
+		$reason        = $matches[7];
+		$time          = strtotime( $date_string );
 
-		// dont read more if we touched entries before timeperiod of collection
+		// dont read more if we touched entries before timeperiod of collection.
 		if ( $time < $this->timestamp_start ) {
 			$this->more_log_needed = false;
 		}
 
-		if ( $status != $this->process_status ) {
+		if ( $status !== $this->process_status ) {
 			return;
 		}
 
-		if ( !isset( $this->by_uri[$uri] ) ) {
-			$this->by_uri[$uri] = array(
-				'count' => 0,
-				'sum_size' => 0,
+		if ( ! isset( $this->by_uri[ $uri ] ) ) {
+			$this->by_uri[ $uri ] = array(
+				'count'       => 0,
+				'sum_size'    => 0,
 				'sum_time_ms' => 0,
-				'reasons' => array()
+				'reasons'     => array(),
 			);
 		}
 
-		$this->by_uri[$uri]['count']++;
-		$this->by_uri[$uri]['sum_size'] += $size;
-		$this->by_uri[$uri]['sum_time_ms'] += $time_taken_ms;
+		$this->by_uri[ $uri ]['count']++;
+		$this->by_uri[ $uri ]['sum_size']    += $size;
+		$this->by_uri[ $uri ]['sum_time_ms'] += $time_taken_ms;
 
-		if ( !in_array( $reason, $this->by_uri[$uri]['reasons']) ) {
-			$this->by_uri[$uri]['reasons'][] = $reason;
+		if ( ! in_array( $reason, $this->by_uri[ $uri ]['reasons'], true ) ) {
+			$this->by_uri[ $uri ]['reasons'][] = $reason;
 		}
 	}
 }
diff --git a/UsageStatistics_Source_Wpdb.php b/UsageStatistics_Source_Wpdb.php
index 9b34d1e35..68fbb5d76 100644
--- a/UsageStatistics_Source_Wpdb.php
+++ b/UsageStatistics_Source_Wpdb.php
@@ -1,59 +1,108 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Source_DbQueriesLog.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
 /**
+ * Class UsageStatistics_Source_Wpdb
+ *
  * Provides statistics data about requests made to mysql server
  */
 class UsageStatistics_Source_Wpdb {
+	/**
+	 * Total number of WPDB queries executed.
+	 *
+	 * @var int
+	 */
 	private $query_total = 0;
 
-
-
-	static public function init() {
+	/**
+	 * Initializes the usage statistics by registering filters and actions.
+	 *
+	 * This method sets up the necessary WordPress hooks for gathering usage statistics
+	 * related to WPDB calls. It adds filters and actions to track query data and metrics
+	 * as well as handle historical statistics.
+	 *
+	 * @return void
+	 */
+	public static function init() {
 		$o = new UsageStatistics_Source_Wpdb();
 
 		add_filter( 'query', array( $o, 'query' ) );
-		add_action( 'w3tc_usage_statistics_of_request', array(
-			$o, 'w3tc_usage_statistics_of_request' ), 10, 1 );
-		add_filter( 'w3tc_usage_statistics_metrics', array(
-			$o, 'w3tc_usage_statistics_metrics' ) );
-		add_filter( 'w3tc_usage_statistics_summary_from_history', array(
-			$o, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
+		add_action( 'w3tc_usage_statistics_of_request', array( $o, 'w3tc_usage_statistics_of_request' ), 10, 1 );
+		add_filter( 'w3tc_usage_statistics_metrics', array( $o, 'w3tc_usage_statistics_metrics' ) );
+		add_filter( 'w3tc_usage_statistics_summary_from_history', array( $o, 'w3tc_usage_statistics_summary_from_history' ), 10, 2 );
 	}
 
-
-
+	/**
+	 * Adds custom metrics for usage statistics.
+	 *
+	 * This method extends the default metrics with custom values, such as the total number
+	 * of WPDB queries executed. This allows for the gathering of additional statistics related
+	 * to database queries during usage reporting.
+	 *
+	 * @param array $metrics Existing metrics to be extended.
+	 *
+	 * @return array Updated array of metrics including custom metrics.
+	 */
 	public function w3tc_usage_statistics_metrics( $metrics ) {
 		return array_merge( $metrics, array( 'wpdb_calls_total' ) );
 	}
 
-
-
+	/**
+	 * Summarizes usage statistics from historical data.
+	 *
+	 * This method calculates the total number of WPDB queries from the historical data
+	 * and includes it in the summary. It also calculates the rate of queries per second
+	 * over the given history period.
+	 *
+	 * @param array $summary Existing summary of usage statistics.
+	 * @param array $history Historical usage data.
+	 *
+	 * @return array Updated summary with WPDB statistics.
+	 */
 	public function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
-		// counters
-		$wpdb_calls_total = Util_UsageStatistics::sum( $history,
-			'wpdb_calls_total' );
+		// counters.
+		$wpdb_calls_total = Util_UsageStatistics::sum( $history, 'wpdb_calls_total' );
 
 		$summary['wpdb'] = array(
-			'calls_total' => Util_UsageStatistics::integer(
-				$wpdb_calls_total ),
-			'calls_per_second' => Util_UsageStatistics::value_per_period_seconds(
-				$wpdb_calls_total, $summary )
+			'calls_total'      => Util_UsageStatistics::integer( $wpdb_calls_total ),
+			'calls_per_second' => Util_UsageStatistics::value_per_period_seconds( $wpdb_calls_total, $summary ),
 		);
 
 		return $summary;
 	}
 
-
-
+	/**
+	 * Tracks usage statistics for the current request.
+	 *
+	 * This method adds the total number of WPDB queries executed during the current request
+	 * to the storage object for reporting purposes. It is triggered at the end of a request
+	 * to ensure accurate tracking.
+	 *
+	 * @param object $storage The storage object where statistics are recorded.
+	 *
+	 * @return void
+	 */
 	public function w3tc_usage_statistics_of_request( $storage ) {
 		$storage->counter_add( 'wpdb_calls_total', $this->query_total );
 	}
 
-
-
+	/**
+	 * Intercepts a database query and tracks the number of queries.
+	 *
+	 * This method is called every time a WPDB query is executed. It increments the total
+	 * query count (`$query_total`) for the current request and returns the query unchanged.
+	 * This allows for tracking the number of WPDB queries executed.
+	 *
+	 * @param string $q The SQL query being executed.
+	 *
+	 * @return string The original SQL query.
+	 */
 	public function query( $q ) {
 		$this->query_total++;
 		return $q;
diff --git a/UsageStatistics_Sources.php b/UsageStatistics_Sources.php
index 134e1185b..9f28284eb 100644
--- a/UsageStatistics_Sources.php
+++ b/UsageStatistics_Sources.php
@@ -1,106 +1,124 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Sources.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_Sources
+ */
 class UsageStatistics_Sources {
-	static public function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
-		// php data
+	/**
+	 * Generates a summary of usage statistics based on historical data.
+	 *
+	 * This method processes the provided usage history and compiles statistics for various sources, including
+	 * PHP, APC, Memcached, Redis, CPU, and access logs.The summary is populated with the relevant metrics for
+	 * each source, such as memory usage, request counts, and CPU averages. It is designed to be used for
+	 * generating a comprehensive view of the system's resource usage over time.
+	 *
+	 * @param array $summary   The current summary to be updated with usage statistics.
+	 * @param array $history   The historical data to process for generating the summary.
+	 *
+	 * @return array The updated summary with the compiled usage statistics.
+	 */
+	public static function w3tc_usage_statistics_summary_from_history( $summary, $history ) {
+		// php data.
 		$php_memory_100kb = Util_UsageStatistics::sum( $history, 'php_memory_100kb' );
-		$php_requests = Util_UsageStatistics::sum( $history, 'php_requests' );
+		$php_requests     = Util_UsageStatistics::sum( $history, 'php_requests' );
 
 		if ( $php_requests > 0 ) {
-			if ( !isset( $summary['php'] ) ) {
+			if ( ! isset( $summary['php'] ) ) {
 				$summary['php'] = array();
 			}
 
-			$summary['php']['memory'] = Util_UsageStatistics::bytes_to_size(
-				$php_memory_100kb / $php_requests * 1024 * 10.24 );
-
-			$summary['php']['php_requests_v'] = $php_requests;
-			$summary['php']['php_requests'] =
-				Util_UsageStatistics::integer( $php_requests );
-			$summary['php']['php_requests_per_second'] =
-				Util_UsageStatistics::value_per_period_seconds( $php_requests,
-				$summary );
+			$summary['php']['memory']                  = Util_UsageStatistics::bytes_to_size( $php_memory_100kb / $php_requests * 1024 * 10.24 );
+			$summary['php']['php_requests_v']          = $php_requests;
+			$summary['php']['php_requests']            = Util_UsageStatistics::integer( $php_requests );
+			$summary['php']['php_requests_per_second'] = Util_UsageStatistics::value_per_period_seconds( $php_requests, $summary );
 		}
 
-		// apc
+		// apc.
 		if ( count( $summary['apc_servers'] ) > 0 ) {
-			$apc = new UsageStatistics_Sources_Apc(
-				$summary['apc_servers'] );
+			$apc            = new UsageStatistics_Sources_Apc( $summary['apc_servers'] );
 			$summary['apc'] = $apc->get_summary();
 		}
 
-		// memcached
+		// memcached.
 		if ( count( $summary['memcached_servers'] ) > 0 ) {
-			$memcached = new UsageStatistics_Sources_Memcached(
-				$summary['memcached_servers'] );
+			$memcached            = new UsageStatistics_Sources_Memcached( $summary['memcached_servers'] );
 			$summary['memcached'] = $memcached->get_summary();
 		}
 
-		// redis
+		// redis.
 		if ( count( $summary['redis_servers'] ) > 0 ) {
-			$redis = new UsageStatistics_Sources_Redis(
-				$summary['redis_servers'] );
+			$redis            = new UsageStatistics_Sources_Redis( $summary['redis_servers'] );
 			$summary['redis'] = $redis->get_summary();
 		}
 
-		// cpu snapshot
+		// cpu snapshot.
 		$c = Dispatcher::config();
 		if ( $c->get_boolean( 'stats.cpu.enabled' ) ) {
 			$summary['cpu'] = array(
-				'avg' => round( Util_UsageStatistics::avg( $history, 'cpu' ), 2 )
+				'avg' => round( Util_UsageStatistics::avg( $history, 'cpu' ), 2 ),
 			);
 		}
 
-		// access log data
+		// access log data.
 		if ( $c->get_boolean( 'stats.access_log.enabled' ) ) {
-			$o = new UsageStatistics_Source_AccessLog( array(
-				'webserver' => $c->get_string( 'stats.access_log.webserver' ),
-				'filename' => $c->get_string( 'stats.access_log.filename' ),
-				'format' => $c->get_string( 'stats.access_log.format' )
-			) );
-
-			$summary = $o->w3tc_usage_statistics_summary_from_history(
-				$summary, $history );
+			$o = new UsageStatistics_Source_AccessLog(
+				array(
+					'webserver' => $c->get_string( 'stats.access_log.webserver' ),
+					'filename'  => $c->get_string( 'stats.access_log.filename' ),
+					'format'    => $c->get_string( 'stats.access_log.format' ),
+				)
+			);
+
+			$summary = $o->w3tc_usage_statistics_summary_from_history( $summary, $history );
 		}
 
 		return $summary;
 	}
 
-
-
-	static public function w3tc_usage_statistics_metric_values( $metric_values ) {
+	/**
+	 * Retrieves the current metric values for various usage statistics sources.
+	 *
+	 * This method fetches real-time data for Memcached, Redis, APC, and CPU usage. It aggregates these
+	 * metrics into an array and returns it. This is useful for generating up-to-date metric snapshots.
+	 *
+	 * @param array $metric_values   The current metric values to be populated with real-time statistics.
+	 *
+	 * @return array The updated metric values with data from the available sources.
+	 */
+	public static function w3tc_usage_statistics_metric_values( $metric_values ) {
 		$sources = array(
 			'memcached_servers' => array(),
-			'redis_servers' => array(),
-			'apc_servers' => array()
+			'redis_servers'     => array(),
+			'apc_servers'       => array(),
 		);
 
-		$sources = apply_filters( 'w3tc_usage_statistics_sources',
-			$sources );
+		$sources = apply_filters( 'w3tc_usage_statistics_sources', $sources );
 
 		if ( count( $sources['memcached_servers'] ) > 0 ) {
-			$memcached = new UsageStatistics_Sources_Memcached(
-				$sources['memcached_servers'] );
+			$memcached                  = new UsageStatistics_Sources_Memcached( $sources['memcached_servers'] );
 			$metric_values['memcached'] = $memcached->get_snapshot();
 		}
+
 		if ( count( $sources['apc_servers'] ) > 0 ) {
-			$apc = new UsageStatistics_Sources_Apc(
-				$sources['apc_servers']
-			);
+			$apc                  = new UsageStatistics_Sources_Apc( $sources['apc_servers'] );
 			$metric_values['apc'] = $apc->get_snapshot();
 		}
+
 		if ( count( $sources['redis_servers'] ) > 0 ) {
-			$redis = new UsageStatistics_Sources_Redis(
-				$sources['redis_servers'] );
+			$redis                  = new UsageStatistics_Sources_Redis( $sources['redis_servers'] );
 			$metric_values['redis'] = $redis->get_snapshot();
 		}
 
 		$c = Dispatcher::config();
 		if ( $c->get_boolean( 'stats.cpu.enabled' ) ) {
-			// cpu snapshot
+			// cpu snapshot.
 			$cpu = sys_getloadavg();
 			if ( isset( $cpu[0] ) ) {
 				$metric_values['cpu'] = $cpu[0];
@@ -110,17 +128,27 @@ static public function w3tc_usage_statistics_metric_values( $metric_values ) {
 		return $metric_values;
 	}
 
-
-
-	static public function w3tc_usage_statistics_history_set( $history ) {
+	/**
+	 * Sets the usage history based on the provided historical data.
+	 *
+	 * This method processes access log data if enabled and adds it to the history.
+	 * It updates the provided history with the relevant data for future analysis or reporting.
+	 *
+	 * @param array $history   The history to be updated with the usage statistics.
+	 *
+	 * @return array The updated history with additional data.
+	 */
+	public static function w3tc_usage_statistics_history_set( $history ) {
 		$c = Dispatcher::config();
 		if ( $c->get_boolean( 'stats.access_log.enabled' ) ) {
-			// read access log
-			$o = new UsageStatistics_Source_AccessLog( array(
-				'webserver' => $c->get_string( 'stats.access_log.webserver' ),
-				'filename' => $c->get_string( 'stats.access_log.filename' ),
-				'format' => $c->get_string( 'stats.access_log.format' )
-			) );
+			// read access log.
+			$o = new UsageStatistics_Source_AccessLog(
+				array(
+					'webserver' => $c->get_string( 'stats.access_log.webserver' ),
+					'filename'  => $c->get_string( 'stats.access_log.filename' ),
+					'format'    => $c->get_string( 'stats.access_log.format' ),
+				)
+			);
 
 			$history = $o->w3tc_usage_statistics_history_set( $history );
 		}
diff --git a/UsageStatistics_Sources_Apc.php b/UsageStatistics_Sources_Apc.php
index 286766c93..41ad3c012 100644
--- a/UsageStatistics_Sources_Apc.php
+++ b/UsageStatistics_Sources_Apc.php
@@ -1,62 +1,103 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Sources_Apc.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_Sources_Apc
+ */
 class UsageStatistics_Sources_Apc {
+	/**
+	 * An array that stores the names of modules.
+	 *
+	 * @var array
+	 */
 	private $module_names = array();
 
+	/**
+	 * Constructor for initializing the module names from the given server descriptors.
+	 *
+	 * This method iterates over the provided `$server_descriptors` array and extracts the 'name'
+	 * of each module to populate the `$module_names` array. The names are stored to keep track of
+	 * which modules are associated with the current object instance.
+	 *
+	 * @param array $server_descriptors An array of server descriptors, where each descriptor is
+	 *                                  an associative array containing module details.
+	 */
 	public function __construct( $server_descriptors ) {
 		foreach ( $server_descriptors as $module_key => $i ) {
 			$this->module_names[] = $i['name'];
 		}
 	}
 
-
-
+	/**
+	 * Retrieves a snapshot of the current APCu cache statistics.
+	 *
+	 * This method fetches the current cache information using `apcu_cache_info()` and returns
+	 * a summary of the cache's statistics such as the number of entries, memory size, number of hits,
+	 * and the total cache accesses (hits + misses).
+	 *
+	 * @return array An associative array containing the total 'items', 'size_used', 'get_hits', and 'get_total'.
+	 */
 	public function get_snapshot() {
 		$cache = apcu_cache_info();
 
 		return array(
-			'items' => $cache['num_entries'],
+			'items'     => $cache['num_entries'],
 			'size_used' => $cache['mem_size'],
-			'get_hits' => $cache['num_hits'],
-			'get_total' => ( $cache['num_hits'] + $cache['num_misses'] )
+			'get_hits'  => $cache['num_hits'],
+			'get_total' => ( $cache['num_hits'] + $cache['num_misses'] ),
 		);
 	}
 
-
-
+	/**
+	 * Retrieves a summary of the APCu cache and memory statistics.
+	 *
+	 * This method provides a detailed summary of the cache usage, including:
+	 * - The modules using the cache.
+	 * - The number of cache entries.
+	 * - The total memory used and the percentage of memory used.
+	 * - Cache hit and miss statistics.
+	 * - The uptime of the cache in seconds.
+	 * - The number of cache evictions.
+	 * - Requests per second based on the cache runtime.
+	 *
+	 * The method also calculates hit rate percentage and converts memory usage into a more readable format.
+	 *
+	 * @return array An associative array containing 'used_by', 'items', 'size_used', 'get_hits', 'get_total',
+	 *               'runtime_secs', 'evictions', 'size_percent', 'requests_per_second', and 'get_hit_rate'
+	 */
 	public function get_summary() {
 		$cache = apcu_cache_info();
 
-		$time = time();
+		$time    = time();
 		$runtime = $time - $cache['start_time'];
 
-		$mem = apcu_sma_info();
-		$mem_size = $mem['num_seg'] * $mem['seg_size'];
+		$mem       = apcu_sma_info();
+		$mem_size  = $mem['num_seg'] * $mem['seg_size'];
 		$mem_avail = $mem['avail_mem'];
-		$mem_used = $mem_size - $mem_avail;
+		$mem_used  = $mem_size - $mem_avail;
 
 		$sum = array(
-			'used_by' => implode( ',', $this->module_names ),
-			'items' => $cache['num_entries'],
-			'size_used' => Util_UsageStatistics::bytes_to_size( $cache['mem_size'] ),
-			'get_hits' => $cache['num_hits'],
-			'get_total' => ( $cache['num_hits'] + $cache['num_misses'] ),
+			'used_by'      => implode( ',', $this->module_names ),
+			'items'        => $cache['num_entries'],
+			'size_used'    => Util_UsageStatistics::bytes_to_size( $cache['mem_size'] ),
+			'get_hits'     => $cache['num_hits'],
+			'get_total'    => ( $cache['num_hits'] + $cache['num_misses'] ),
 			'runtime_secs' => $runtime,
-			'evictions' => $cache['expunges'],
-			'size_percent' => Util_UsageStatistics::percent(
-				$mem_used, $mem_avail )
+			'evictions'    => $cache['expunges'],
+			'size_percent' => Util_UsageStatistics::percent( $mem_used, $mem_avail ),
 		);
 
-		if ( $sum['runtime_secs'] != 0 ) {
-			$sum['requests_per_second'] = sprintf( '%.2f',
-				$sum['get_total'] / $sum['runtime_secs'] );
+		if ( 0 !== $sum['runtime_secs'] ) {
+			$sum['requests_per_second'] = sprintf( '%.2f', $sum['get_total'] / $sum['runtime_secs'] );
 		}
 
-		$sum['get_hit_rate'] = Util_UsageStatistics::percent2(
-			$sum, 'get_hits', 'get_total' );
+		$sum['get_hit_rate'] = Util_UsageStatistics::percent2( $sum, 'get_hits', 'get_total' );
 
 		return $sum;
 	}
diff --git a/UsageStatistics_Sources_Memcached.php b/UsageStatistics_Sources_Memcached.php
index 2d8b751a8..68b9afd6d 100644
--- a/UsageStatistics_Sources_Memcached.php
+++ b/UsageStatistics_Sources_Memcached.php
@@ -1,102 +1,142 @@
 <?php
-namespace W3TC;
-
+/**
+ * File: UsageStatistics_Sources_Memcached.php
+ *
+ * @package W3TC
+ */
 
+namespace W3TC;
 
+/**
+ * Class UsageStatistics_Sources_Memcached
+ */
 class UsageStatistics_Sources_Memcached {
+	/**
+	 * Stores server configurations indexed by host and port.
+	 *
+	 * @var array
+	 */
 	private $servers;
 
-
-
+	/**
+	 * Constructor for initializing the Memcached server configurations.
+	 *
+	 * This method takes an array of server descriptors, processes each one to extract
+	 * necessary information, and stores the server configuration in the `$servers`
+	 * attribute, ensuring that the configuration for each unique host-port pair is
+	 * only added once.
+	 *
+	 * @param array $server_descriptors Array of server descriptors containing server details.
+	 *                                  Each item should contain 'servers', 'username', 'password', and 'name' attributes.
+	 *
+	 * @return void
+	 */
 	public function __construct( $server_descriptors ) {
 		$this->servers = array();
 
 		foreach ( $server_descriptors as $i ) {
 			foreach ( $i['servers'] as $host_port ) {
-				if ( !isset( $this->servers[$host_port] ) )
-					$this->servers[$host_port] = array(
-						'username' => $i['username'],
-						'password' => $i['password'],
-						'module_names' => array( $i['name'] )
+				if ( ! isset( $this->servers[ $host_port ] ) ) {
+					$this->servers[ $host_port ] = array(
+						'username'     => $i['username'],
+						'password'     => $i['password'],
+						'module_names' => array( $i['name'] ),
 					);
-				else
-					$this->servers[$host_port]['module_names'][] = $i['name'];
+				} else {
+					$this->servers[ $host_port ]['module_names'][] = $i['name'];
+				}
 			}
 		}
 	}
 
-
-
+	/**
+	 * Retrieves a snapshot of the Memcached statistics across all servers.
+	 *
+	 * This method iterates over the list of servers, collects Memcached statistics
+	 * (such as memory usage and cache hits), and accumulates the data. The method
+	 * returns an array containing the total memory usage, total 'get' commands, and
+	 * total cache hits across all servers.
+	 *
+	 * @return array An associative array containing the total 'size_used', 'get_calls', and 'get_hits'.
+	 */
 	public function get_snapshot() {
 		$size_used = 0;
 		$get_calls = 0;
-		$get_hits = 0;
+		$get_hits  = 0;
 
 		foreach ( $this->servers as $host_port => $i ) {
-			$cache = Cache::instance( 'memcached',
+			$cache = Cache::instance(
+				'memcached',
 				array(
-					'servers' => array( $host_port ),
+					'servers'  => array( $host_port ),
 					'username' => $i['username'],
-					'password' => $i['password']
-				) );
+					'password' => $i['password'],
+				)
+			);
 
 			$stats = $cache->get_statistics();
 
 			$size_used += Util_UsageStatistics::v( $stats, 'bytes' );
 			$get_calls += Util_UsageStatistics::v( $stats, 'cmd_get' );
-			$get_hits += Util_UsageStatistics::v( $stats, 'get_hits' );
+			$get_hits  += Util_UsageStatistics::v( $stats, 'get_hits' );
 		}
 
 		return array(
 			'size_used' => $size_used,
 			'get_calls' => $get_calls,
-			'get_hits' => $get_hits
+			'get_hits'  => $get_hits,
 		);
 	}
 
-
-
+	/**
+	 * Retrieves a summary of Memcached statistics across all servers.
+	 *
+	 * This method iterates over the list of servers, gathers various Memcached statistics
+	 * (such as total memory used, maximum memory limit, cache hits, and uptime), and
+	 * calculates additional derived metrics such as hit rate and evictions per second.
+	 * The method returns a summary of these metrics, including the list of module names.
+	 *
+	 * @return array An associative array containing summary metrics such as 'module_names',
+	 *               'size_percent', 'size_used', 'get_hit_rate', and 'evictions_per_second'.
+	 */
 	public function get_summary() {
 		$sum = array(
-			'module_names' => array(),
-			'size_used' => 0,
+			'module_names'  => array(),
+			'size_used'     => 0,
 			'size_maxbytes' => 0,
-			'get_total' => 0,
-			'get_hits' => 0,
-			'evictions' => 0,
-			'uptime' => 0
+			'get_total'     => 0,
+			'get_hits'      => 0,
+			'evictions'     => 0,
+			'uptime'        => 0,
 		);
 
 		foreach ( $this->servers as $host_port => $i ) {
-			$cache = Cache::instance( 'memcached',
+			$cache = Cache::instance(
+				'memcached',
 				array(
-					'servers' => array( $host_port ),
+					'servers'  => array( $host_port ),
 					'username' => $i['username'],
-					'password' => $i['password']
-				) );
+					'password' => $i['password'],
+				)
+			);
 
 			$stats = $cache->get_statistics();
 
-			$sum['module_names'] =
-				array_merge( $sum['module_names'], $i['module_names'] );
-			$sum['size_used'] += Util_UsageStatistics::v3( $stats, 'bytes');
+			$sum['module_names']   = array_merge( $sum['module_names'], $i['module_names'] );
+			$sum['size_used']     += Util_UsageStatistics::v3( $stats, 'bytes' );
 			$sum['size_maxbytes'] += Util_UsageStatistics::v3( $stats, 'limit_maxbytes' );
-			$sum['get_total'] += Util_UsageStatistics::v3( $stats, 'cmd_get' );
-			$sum['get_hits'] += Util_UsageStatistics::v3( $stats, 'get_hits' );
-			$sum['evictions'] += Util_UsageStatistics::v3( $stats, 'evictions' );
-			$sum['uptime'] += Util_UsageStatistics::v3( $stats, 'uptime' );
+			$sum['get_total']     += Util_UsageStatistics::v3( $stats, 'cmd_get' );
+			$sum['get_hits']      += Util_UsageStatistics::v3( $stats, 'get_hits' );
+			$sum['evictions']     += Util_UsageStatistics::v3( $stats, 'evictions' );
+			$sum['uptime']        += Util_UsageStatistics::v3( $stats, 'uptime' );
 		}
 
 		$summary = array(
-			'module_names' => implode( ',', $sum['module_names'] ),
-			'size_percent' => Util_UsageStatistics::percent2(
-				$sum, 'size_used', 'size_maxbytes' ),
-			'size_used' => Util_UsageStatistics::bytes_to_size2(
-				$sum, 'size_used' ),
-			'get_hit_rate' => Util_UsageStatistics::percent2(
-				$sum, 'get_hits', 'get_total' ),
-			'evictions_per_second' => Util_UsageStatistics::value_per_second(
-				$sum, 'evictions', 'uptime' )
+			'module_names'         => implode( ',', $sum['module_names'] ),
+			'size_percent'         => Util_UsageStatistics::percent2( $sum, 'size_used', 'size_maxbytes' ),
+			'size_used'            => Util_UsageStatistics::bytes_to_size2( $sum, 'size_used' ),
+			'get_hit_rate'         => Util_UsageStatistics::percent2( $sum, 'get_hits', 'get_total' ),
+			'evictions_per_second' => Util_UsageStatistics::value_per_second( $sum, 'evictions', 'uptime' ),
 		);
 
 		return $summary;
diff --git a/UsageStatistics_Sources_Redis.php b/UsageStatistics_Sources_Redis.php
index 0d00f4846..4a9c1addf 100644
--- a/UsageStatistics_Sources_Redis.php
+++ b/UsageStatistics_Sources_Redis.php
@@ -8,20 +8,28 @@
 namespace W3TC;
 
 /**
+ * Class UsageStatistics_Sources_Redis
+ *
  * Usage Statistics Sources for Redis
  */
 class UsageStatistics_Sources_Redis {
 	/**
-	 * Servers.
+	 * An associative array holding Redis server configurations, indexed by host and port.
 	 *
 	 * @var array
 	 */
 	private $servers;
 
 	/**
-	 * Constructor.
+	 * Constructor for initializing Redis server configurations.
+	 *
+	 * This method processes the given server descriptors and sets up a mapping of server configurations,
+	 * where each server is identified by its host and port, along with associated module names, password,
+	 * and database ID. This allows for organized management of Redis server connections.
 	 *
-	 * @param array $server_descriptors Server desriptors.
+	 * @param array $server_descriptors An array of server descriptor arrays, each containing 'servers', 'password', 'dbid', and 'name'.
+	 *
+	 * @return void
 	 */
 	public function __construct( $server_descriptors ) {
 		$this->servers = array();
@@ -42,7 +50,13 @@ public function __construct( $server_descriptors ) {
 	}
 
 	/**
-	 * Get snapshot stats.
+	 * Retrieves a snapshot of Redis memory usage and keyspace statistics across all servers.
+	 *
+	 * This method aggregates memory usage, total get calls, and get hits from all configured Redis servers.
+	 * It connects to each Redis server, fetches its statistics, and updates the totals accordingly.
+	 * The result is an array containing the total memory used, total get calls, and get hits.
+	 *
+	 * @return array An associative array containing the total 'size_used', 'get_calls', and 'get_hits'.
 	 */
 	public function get_snapshot() {
 		$size_used = 0;
@@ -79,7 +93,14 @@ public function get_snapshot() {
 	}
 
 	/**
-	 * Get stats summary.
+	 * Retrieves a summary of Redis usage statistics across all servers.
+	 *
+	 * This method gathers a variety of statistics from each Redis server, including module names,
+	 * memory usage, keyspace hit/miss statistics, eviction rates, and uptime. It aggregates these statistics
+	 * and formats them into a summary for reporting.
+	 *
+	 * @return array An associative array containing a summary of Redis statistics, including 'module_names', 'size_used',
+	 *               'get_hit_rate', and 'evictions_per_second'.
 	 */
 	public function get_summary() {
 		$sum = array(
diff --git a/UsageStatistics_StorageReader.php b/UsageStatistics_StorageReader.php
index e9ce5258f..849f51250 100644
--- a/UsageStatistics_StorageReader.php
+++ b/UsageStatistics_StorageReader.php
@@ -1,29 +1,54 @@
 <?php
+/**
+ * File: UsageStatistics_StorageReader.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * Manages data statistics.
- * Metrics:
+ * Class UsageStatistics_StorageReader
  *
+ * Manages data statistics.
  */
 class UsageStatistics_StorageReader {
+	/**
+	 * This attribute determines how many historical records are included in the returned history array.
+	 * The value can be adjusted to retrieve more or fewer records.
+	 *
+	 * @var int
+	 */
 	private $items_to_return = 60;
 
+	/**
+	 * Retrieves a summary of the usage statistics history, including server information and time periods.
+	 *
+	 * This method fetches the usage statistics history from the WordPress site options, decodes it, and builds a summary
+	 * of the statistics. The summary includes the start and end timestamps, the time period in minutes, and any available
+	 * server information (Memcached, Redis, and APC). It applies relevant filters to allow customization and returns the
+	 * summary of the statistics. It also ensures that the history array is returned with a predefined number of items.
+	 *
+	 * @return array The summary of usage statistics history, including period, timeout time, and history.
+	 */
 	public function get_history_summary() {
 		$w = new UsageStatistics_StorageWriter();
 		$w->maybe_flush_hotspot_data();
 
 		$history_encoded = get_site_option( 'w3tc_stats_history' );
-		$history = null;
-		if ( !empty( $history_encoded ) )
+		$history         = null;
+		if ( ! empty( $history_encoded ) ) {
 			$history = json_decode( $history_encoded, true );
-		if ( !is_array( $history ) )
+		}
+
+		if ( ! is_array( $history ) ) {
 			$history = array();
+		}
 
 		$summary = array(
 			'memcached_servers' => array(),
-			'redis_servers' => array(),
-			'apc_servers' => array()
+			'redis_servers'     => array(),
+			'apc_servers'       => array(),
 		);
 
 		$summary = apply_filters( 'w3tc_usage_statistics_sources', $summary );
@@ -32,35 +57,34 @@ public function get_history_summary() {
 			$summary = array( 'period' => array() );
 		} else {
 			$timestamp_start = $history[0]['timestamp_start'];
-			$timestamp_end = $history[count( $history ) - 1]['timestamp_end'];
+			$timestamp_end   = $history[ count( $history ) - 1 ]['timestamp_end'];
 
 			$period = array(
-				'timestamp_start' => $timestamp_start,
-				'timestamp_start_mins' =>
-				Util_UsageStatistics::time_mins( $timestamp_start ),
-				'timestamp_end' => $timestamp_end,
-				'timestamp_end_mins' =>
-				Util_UsageStatistics::time_mins( $timestamp_end ),
+				'timestamp_start'      => $timestamp_start,
+				'timestamp_start_mins' => Util_UsageStatistics::time_mins( $timestamp_start ),
+				'timestamp_end'        => $timestamp_end,
+				'timestamp_end_mins'   => Util_UsageStatistics::time_mins( $timestamp_end ),
 			);
 
-			$period['seconds'] = $timestamp_end - $timestamp_start;
-			$summary['period'] = $period;
+			$period['seconds']       = $timestamp_end - $timestamp_start;
+			$summary['period']       = $period;
 			$summary['timeout_time'] = time() + 15;
 
-			$summary = apply_filters( 'w3tc_usage_statistics_summary_from_history',
-				$summary, $history );
+			$summary = apply_filters( 'w3tc_usage_statistics_summary_from_history', $summary, $history );
 		}
 
-		$summary['period']['to_update_secs'] = (int)$w->get_hotspot_end() - time() + 1;
+		$summary['period']['to_update_secs'] = (int) $w->get_hotspot_end() - time() + 1;
 
 		unset( $summary['memcached_servers'] );
 		unset( $summary['redis_servers'] );
 
-		while ( count($history) < $this->items_to_return ) {
+		$history_count = count( $history );
+		while ( $history_count < $this->items_to_return ) {
 			array_unshift( $history, array() );
 		}
 
 		$summary['history'] = $history;
+
 		return $summary;
 	}
 }
diff --git a/UsageStatistics_StorageWriter.php b/UsageStatistics_StorageWriter.php
index 6e248d501..c7b9ac563 100644
--- a/UsageStatistics_StorageWriter.php
+++ b/UsageStatistics_StorageWriter.php
@@ -1,368 +1,504 @@
 <?php
+/**
+ * File: UsageStatistics_StorageReader.php
+ *
+ * phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
+ * phpcs:disable PEAR.NamingConventions.ValidClassName.StartWithCapital
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 /**
- * Manages data statistics.
- * Metrics:
+ * Class UsageStatistics_StorageWriter
  *
+ * Manages data statistics.
  */
 class UsageStatistics_StorageWriter {
+	/**
+	 * The interval in seconds for each slot in the statistics collection.
+	 *
+	 * @var int
+	 */
 	private $slot_interval_seconds;
+
+	/**
+	 * The total number of slots to maintain for the usage statistics.
+	 *
+	 * @var int
+	 */
 	private $slots_count;
+
+	/**
+	 * The interval in seconds to keep historical data.
+	 *
+	 * @var int
+	 */
 	private $keep_history_interval_seconds;
 
+	/**
+	 * The cache storage for usage statistics.
+	 *
+	 * @var CacheStorage|null
+	 */
 	private $cache_storage;
 
 	/**
-	 * Cached values, just keep state between calls
+	 * The end time for the current hotspot period.
+	 *
+	 * @var int|null
 	 */
 	private $hotspot_endtime;
+
+	/**
+	 * The end time for the new hotspot period.
+	 *
+	 * @var float
+	 */
 	private $new_hotspot_endtime = 0;
+
+	/**
+	 * The current timestamp at the time of the operation.
+	 *
+	 * @var int
+	 */
 	private $now;
 
 	/**
-	 * begin_ sets the state what should it perform later
-	 * finish reacts to that state and finishes flushing
-	 * values:
-	 *   not_needed - no flushinig required now
-	 *   require_db - database access has to be available to decide
-	 *   flushing_began_by_cache - that process has been selected to
-	 *     flush hotspot data based on cache data state, still that has to be
-	 *     verified in database
+	 * The state of the flushing process.
+	 *
+	 * @var string
 	 */
 	private $flush_state;
 
-
-
+	/**
+	 * Constructor for initializing the UsageStatistics_StorageWriter.
+	 *
+	 * Initializes the cache storage and configuration options based on the provided settings.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 		$this->cache_storage = Dispatcher::get_usage_statistics_cache();
 
-		$c = Dispatcher::config();
+		$c                           = Dispatcher::config();
 		$this->slot_interval_seconds = $c->get_integer( 'stats.slot_seconds' );
 
-		$this->keep_history_interval_seconds =
-			$c->get_integer( 'stats.slots_count' ) *
-			$this->slot_interval_seconds;
-		$this->slots_count = $c->get_integer( 'stats.slots_count' );
+		$this->keep_history_interval_seconds = $c->get_integer( 'stats.slots_count' ) * $this->slot_interval_seconds;
+		$this->slots_count                   = $c->get_integer( 'stats.slots_count' );
 	}
 
-
-
+	/**
+	 * Resets the usage statistics, clearing the cache and site options.
+	 *
+	 * Resets the history and start time for the hotspot.
+	 *
+	 * @return void
+	 */
 	public function reset() {
-		if ( !is_null( $this->cache_storage ) ) {
-			$this->cache_storage->set( 'hotspot_endtime', 
-			array( 'content' => 0 ) );
+		if ( ! is_null( $this->cache_storage ) ) {
+			$this->cache_storage->set( 'hotspot_endtime', array( 'content' => 0 ) );
 		}
 
 		update_site_option( 'w3tc_stats_hotspot_start', time() );
 		update_site_option( 'w3tc_stats_history', '' );
 	}
 
-
-
+	/**
+	 * Adds a specified value to a counter metric in the cache.
+	 *
+	 * This method will increment a metric counter by the given value, if the cache storage is not null.
+	 *
+	 * @param string $metric The metric name to increment.
+	 * @param int    $value  The value to add to the metric counter.
+	 *
+	 * @return void
+	 */
 	public function counter_add( $metric, $value ) {
-		if ( !is_null( $this->cache_storage ) ) {
+		if ( ! is_null( $this->cache_storage ) ) {
 			$this->cache_storage->counter_add( $metric, $value );
 		}
 	}
 
-
-
+	/**
+	 * Retrieves the end time for the current hotspot.
+	 *
+	 * If the hotspot end time is not cached, it will fetch it from the cache and store it.
+	 *
+	 * @return int The hotspot end time.
+	 */
 	public function get_hotspot_end() {
 		if ( is_null( $this->hotspot_endtime ) ) {
-			$v = $this->cache_storage->get( 'hotspot_endtime' );
+			$v                     = $this->cache_storage->get( 'hotspot_endtime' );
 			$this->hotspot_endtime = ( isset( $v['content'] ) ? $v['content'] : 0 );
 		}
 
 		return $this->hotspot_endtime;
 	}
 
-
-
+	/**
+	 * Returns an appropriate option storage handler based on whether the environment is multisite or not.
+	 *
+	 * @return _OptionStorageWpmu|_OptionStorageSingleSite The option storage handler.
+	 */
 	private function get_option_storage() {
-		if ( is_multisite() )
+		if ( is_multisite() ) {
 			return new _OptionStorageWpmu();
-		else
+		} else {
 			return new _OptionStorageSingleSite();
+		}
 	}
 
-
+	/**
+	 * May trigger the flushing of the hotspot data if needed.
+	 *
+	 * Determines if the data should be flushed and initiates the process.
+	 *
+	 * @return void
+	 */
 	public function maybe_flush_hotspot_data() {
 		$result = $this->begin_flush_hotspot_data();
-		if ( $result == 'not_needed' )
+		if ( 'not_needed' === $result ) {
 			return;
+		}
 
 		$this->finish_flush_hotspot_data();
 	}
 
-
-
 	/**
-	 * Returns if finish_* should be called.
-	 * It tries to pass as litte processes as possible to
-	 * flushing_begin if multiple processes come here
-	 * at the same time when hotspot time ended.
+	 * Begins the process of flushing the hotspot data.
+	 *
+	 * Checks the current hotspot end time and prepares to flush data based on various conditions.
+	 *
+	 * @return string The state of the flush process.
 	 */
 	public function begin_flush_hotspot_data() {
 		$hotspot_endtime = $this->get_hotspot_end();
 		if ( is_null( $hotspot_endtime ) ) {
-			// if cache not recognized - means nothing is cached at all
-			// so stats not collected
+			// if cache not recognized - means nothing is cached at all so stats not collected.
 			return 'not_needed';
 		}
 
-		$hotspot_endtime_int = (int)$hotspot_endtime;
-		$this->now = time();
+		$hotspot_endtime_int = (int) $hotspot_endtime;
+		$this->now           = time();
 
 		if ( $hotspot_endtime_int <= 0 ) {
 			$this->flush_state = 'require_db';
 		} elseif ( $this->now < $hotspot_endtime_int ) {
 			$this->flush_state = 'not_needed';
 		} else {
-			// rand value makes value unique for each process,
-			// so as a result next replace works as a lock
-			// passing only single process further
-			$this->new_hotspot_endtime = $this->now + $this->slot_interval_seconds +
-				( rand( 1, 9999 ) / 10000.0 );
+			// rand value makes value unique for each process, so as a result next replace works as a lock
+			// passing only single process further.
+			$this->new_hotspot_endtime = $this->now + $this->slot_interval_seconds + ( wp_rand( 1, 9999 ) / 10000.0 );
 
-			$succeeded = $this->cache_storage->set_if_maybe_equals( 'hotspot_endtime',
+			$succeeded         = $this->cache_storage->set_if_maybe_equals(
+				'hotspot_endtime',
 				array( 'content' => $hotspot_endtime ),
-				array( 'content' => $this->new_hotspot_endtime ) );
-			$this->flush_state =
-				( $succeeded ? 'flushing_began_by_cache' : 'not_needed' );
+				array( 'content' => $this->new_hotspot_endtime )
+			);
+			$this->flush_state = ( $succeeded ? 'flushing_began_by_cache' : 'not_needed' );
 		}
 
 		return $this->flush_state;
 	}
 
 
-
+	/**
+	 * Completes the flushing of the hotspot data.
+	 *
+	 * This method will attempt to flush the collected metrics data to the storage and update the history.
+	 *
+	 * @return void
+	 *
+	 * @throws Exception If the flushing state is unknown.
+	 */
 	public function finish_flush_hotspot_data() {
 		$option_storage = $this->get_option_storage();
 
-		if ( $this->flush_state == 'not_needed' )
+		if ( 'not_needed' === $this->flush_state ) {
 			return;
+		}
 
-		if ( $this->flush_state != 'require_db' &&
-			$this->flush_state != 'flushing_began_by_cache' )
+		if ( 'require_db' !== $this->flush_state && 'flushing_began_by_cache' !== $this->flush_state ) {
 			throw new Exception( 'unknown usage stats state ' . $this->flush_state );
+		}
 
-		// check whats there in db
+		// check whats there in db.
 		$this->hotspot_endtime = $option_storage->get_hotspot_end();
-		$hotspot_endtime_int = (int)$this->hotspot_endtime;
+		$hotspot_endtime_int   = (int) $this->hotspot_endtime;
 
 		if ( $this->now < $hotspot_endtime_int ) {
-			// update cache, since there is something old/missing in cache
-			$this->cache_storage->set( 'hotspot_endtime',
-				array( 'content' => $this->hotspot_endtime ) );
-			return;   // not neeeded really, db state after
+			// update cache, since there is something old/missing in cache.
+			$this->cache_storage->set( 'hotspot_endtime', array( 'content' => $this->hotspot_endtime ) );
+			return; // not neeeded really, db state after.
+		}
+		if ( $this->new_hotspot_endtime <= 0 ) {
+			$this->new_hotspot_endtime = $this->now + $this->slot_interval_seconds + ( wp_rand( 1, 9999 ) / 10000.0 );
 		}
-		if ( $this->new_hotspot_endtime <= 0 )
-			$this->new_hotspot_endtime = $this->now +
-				$this->slot_interval_seconds +
-				( rand( 1, 9999 ) / 10000.0 );
 
 		if ( $hotspot_endtime_int <= 0 ) {
-			// no data in options, initialization
-			$this->cache_storage->set( 'hotspot_endtime',
-				array( 'content' => $this->new_hotspot_endtime ) );
+			// no data in options, initialization.
+			$this->cache_storage->set( 'hotspot_endtime', array( 'content' => $this->new_hotspot_endtime ) );
 			update_site_option( 'w3tc_stats_hotspot_start', time() );
 			$option_storage->set_hotspot_end( $this->new_hotspot_endtime );
 			return;
 		}
 
-		// try to become the process who makes flushing by
-		// performing atomic database update
-
-		// rand value makes value unique for each process,
-		// so as a result next replace works as a lock
-		// passing only single process further
-		$succeeded = $option_storage->prolong_hotspot_end(
-			$this->hotspot_endtime, $this->new_hotspot_endtime );
-		if ( !$succeeded )
+		// try to become the process who makes flushing by performing atomic database update.
+		// rand value makes value unique for each process, so as a result next replace works as a lock
+		// passing only single process further.
+		$succeeded = $option_storage->prolong_hotspot_end( $this->hotspot_endtime, $this->new_hotspot_endtime );
+		if ( ! $succeeded ) {
 			return;
+		}
 
-		$this->cache_storage->set( 'hotspot_endtime',
-			array( 'content' => $this->new_hotspot_endtime ) );
-
+		$this->cache_storage->set( 'hotspot_endtime', array( 'content' => $this->new_hotspot_endtime ) );
 
-		// flush data
+		// flush data.
 		$metrics = array();
 		$metrics = apply_filters( 'w3tc_usage_statistics_metrics', $metrics );
 
-		$metric_values = array();
+		$metric_values                    = array();
 		$metric_values['timestamp_start'] = get_site_option( 'w3tc_stats_hotspot_start' );
-		$metric_values['timestamp_end'] = $hotspot_endtime_int;
+		$metric_values['timestamp_end']   = $hotspot_endtime_int;
 
-		// try to limit time between get and reset of counter value
-		// to loose as small as posssible
+		// try to limit time between get and reset of counter value to loose as small as posssible.
 		foreach ( $metrics as $metric ) {
-			$metric_values[$metric] = $this->cache_storage->counter_get( $metric );
+			$metric_values[ $metric ] = $this->cache_storage->counter_get( $metric );
 			$this->cache_storage->counter_set( $metric, 0 );
 		}
 
-		$metric_values = apply_filters( 'w3tc_usage_statistics_metric_values',
-			$metric_values );
+		$metric_values = apply_filters( 'w3tc_usage_statistics_metric_values', $metric_values );
 
 		$history_encoded = get_site_option( 'w3tc_stats_history' );
-		$history = null;
-		if ( !empty( $history_encoded ) )
+		$history         = null;
+		if ( ! empty( $history_encoded ) ) {
 			$history = json_decode( $history_encoded, true );
-		if ( !is_array( $history ) )
+		}
+
+		if ( ! is_array( $history ) ) {
 			$history = array();
+		}
 
 		$time_keep_border = time() - $this->keep_history_interval_seconds;
 
-		if ( $hotspot_endtime_int < $time_keep_border )
+		if ( $hotspot_endtime_int < $time_keep_border ) {
 			$history = array(
 				array(
 					'timestamp_start' => $time_keep_border,
-					'timestamp_end' => (int)$this->new_hotspot_endtime -
-					$this->slot_interval_seconds - 1
-				)
-			);   // this was started too much time from now
-		else {
-			// add collected
+					'timestamp_end'   => (int) $this->new_hotspot_endtime - $this->slot_interval_seconds - 1,
+				),
+			); // this was started too much time from now.
+		} else {
+			// add collected.
 			$history[] = $metric_values;
 
-			// if we empty place later - fill it
+			// if we empty place later - fill it.
 			for ( ;; ) {
-				$metric_values = array(
-					'timestamp_start' => $metric_values['timestamp_end']
+				$metric_values                  = array(
+					'timestamp_start' => $metric_values['timestamp_end'],
 				);
-				$metric_values['timestamp_end'] =
-					$metric_values['timestamp_start'] + $this->slot_interval_seconds;
-				if ( $metric_values['timestamp_end'] < $this->now )
+				$metric_values['timestamp_end'] = $metric_values['timestamp_start'] + $this->slot_interval_seconds;
+				if ( $metric_values['timestamp_end'] < $this->now ) {
 					$history[] = $metric_values;
-				else
+				} else {
 					break;
+				}
 			}
 
-			// make sure we have at least one value in history
-			for ( ;count( $history ) > $this->slots_count; ) {
-				if ( !isset( $history[0]['timestamp_end'] ) ||
-					$history[0]['timestamp_end'] < $time_keep_border )
+			// make sure we have at least one value in history.
+			$history_count = count( $history );
+			while ( $history_count > $this->slots_count ) {
+				if ( ! isset( $history[0]['timestamp_end'] ) || $history[0]['timestamp_end'] < $time_keep_border ) {
 					array_shift( $history );
-				else
+				} else {
 					break;
+				}
+
+				// Update the history count after modification.
+				$history_count = count( $history );
 			}
 		}
 
-		$history = apply_filters(
-			'w3tc_usage_statistics_history_set', $history );
+		$history = apply_filters( 'w3tc_usage_statistics_history_set', $history );
 
 		update_site_option( 'w3tc_stats_hotspot_start', $this->now );
-		update_site_option( 'w3tc_stats_history', json_encode( $history ) );
+		update_site_option( 'w3tc_stats_history', wp_json_encode( $history ) );
 	}
 }
 
-
-
 /**
- * Can update option by directly incrementing current value,
- * not via get+set operation
+ * Class _OptionStorageSingleSite
+ *
+ * Can update option by directly incrementing current value, not via get+set operation
+ *
+ * phpcs:disable WordPress.DB.DirectDatabaseQuery
+ * phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
  */
 class _OptionStorageSingleSite {
+	/**
+	 * The option name for storing the hotspot end value.
+	 *
+	 * @var string
+	 */
 	private $option_hotspot_end = 'w3tc_stats_hotspot_end';
 
-
-
+	/**
+	 * Retrieves the current value of the hotspot end option from the database.
+	 *
+	 * This method queries the WordPress options table for the value associated with the
+	 * `option_hotspot_end` key and returns it if found. If the option does not exist,
+	 * it returns false.
+	 *
+	 * @return mixed The value of the hotspot end option if found, otherwise false.
+	 */
 	public function get_hotspot_end() {
 		global $wpdb;
 
-		$row = $wpdb->get_row( $wpdb->prepare(
-				'SELECT option_value ' .
-				'FROM ' . $wpdb->options . ' ' .
-				'WHERE option_name = %s LIMIT 1',
-				$this->option_hotspot_end ) );
+		$row = $wpdb->get_row(
+			$wpdb->prepare(
+				'SELECT option_value FROM ' . $wpdb->options . ' WHERE option_name = %s LIMIT 1',
+				$this->option_hotspot_end
+			)
+		);
 
-		if ( !is_object( $row ) )
+		if ( ! is_object( $row ) ) {
 			return false;
+		}
 
 		$v = $row->option_value;
+
 		return $v;
 	}
 
-
-
+	/**
+	 * Updates the value of the hotspot end option in the database.
+	 *
+	 * This method updates the WordPress site option associated with the
+	 * `option_hotspot_end` key with the provided new value.
+	 *
+	 * @param mixed $new_value The new value to set for the hotspot end option.
+	 *
+	 * @return void
+	 */
 	public function set_hotspot_end( $new_value ) {
 		update_site_option( $this->option_hotspot_end, $new_value );
 	}
 
-
-
 	/**
-	 * Performs atomic update of option value
-	 * from old to new value. Makes sure that only single process updates it.
-	 * Only single process gets true return value when multiple tries to do that.
+	 * Prolongs the hotspot end value by updating it in the database if the old value matches.
+	 *
+	 * This method updates the WordPress site option associated with the `option_hotspot_end` key,
+	 * changing its value from the old value to the new value. If the old value matches the current
+	 * value stored in the options table, the update is performed.
+	 *
+	 * @param mixed $old_value The current value to be replaced.
+	 * @param mixed $new_value The new value to set for the hotspot end option.
+	 *
+	 * @return bool True if the update succeeded, false otherwise.
 	 */
 	public function prolong_hotspot_end( $old_value, $new_value ) {
 		global $wpdb;
 
 		$q = $wpdb->prepare(
-			'UPDATE ' . $wpdb->options . ' ' .
-			'SET option_value = %s ' .
-			'WHERE option_name = %s AND option_value = %s', $new_value,
-			$this->option_hotspot_end, $old_value );
+			'UPDATE ' . $wpdb->options . ' SET option_value = %s WHERE option_name = %s AND option_value = %s',
+			$new_value,
+			$this->option_hotspot_end,
+			$old_value
+		);
 
-		$result = $wpdb->query( $q );
+		$result    = $wpdb->query( $q );
 		$succeeded = ( $result > 0 );
 
 		return $succeeded;
 	}
 }
 
-
-
 /**
- * Can update option by directly incrementing current value,
- * not via get+set operation
+ * Class _OptionStorageWpmu
+ *
+ * Can update option by directly incrementing current value, not via get+set operation
+ *
+ * phpcs:disable WordPress.DB.DirectDatabaseQuery
  */
 class _OptionStorageWpmu {
+	/**
+	 * The option key for the hotspot end setting.
+	 *
+	 * @var string
+	 */
 	private $option_hotspot_end = 'w3tc_stats_hotspot_end';
 
-
-
+	/**
+	 * Retrieves the value of the hotspot end option.
+	 *
+	 * This method queries the `sitemeta` table in the WordPress database to fetch
+	 * the value associated with the `w3tc_stats_hotspot_end` meta key for the current site.
+	 * It returns the stored value if available, or false if not.
+	 *
+	 * @return mixed The hotspot end value if it exists, or false if not found.
+	 */
 	public function get_hotspot_end() {
 		global $wpdb;
 
-		$row = $wpdb->get_row( $wpdb->prepare(
-				'SELECT meta_value ' .
-				'FROM ' . $wpdb->sitemeta . ' ' .
-				'WHERE site_id = %d AND meta_key = %s',
-				$wpdb->siteid, $this->option_hotspot_end ) );
+		$row = $wpdb->get_row(
+			$wpdb->prepare(
+				'SELECT meta_value FROM ' . $wpdb->sitemeta . ' WHERE site_id = %d AND meta_key = %s',
+				$wpdb->siteid,
+				$this->option_hotspot_end
+			)
+		);
 
-		if ( !is_object( $row ) )
+		if ( ! is_object( $row ) ) {
 			return false;
+		}
 
 		$v = $row->meta_value;
+
 		return $v;
 	}
 
 	/**
-	 * Performs atomic update of option value
-	 * from old to new value. Makes sure that only single process updates it.
-	 * Only single process gets true return value when multiple tries to do that.
+	 * Sets the value of the hotspot end option.
+	 *
+	 * This method updates the `w3tc_stats_hotspot_end` option with a new value
+	 * in the WordPress site options. It ensures that the option is updated with the
+	 * provided value for the current site.
+	 *
+	 * @param mixed $new_value The new value to set for the hotspot end option.
+	 *
+	 * @return void
 	 */
 	public function set_hotspot_end( $new_value ) {
 		update_site_option( $this->option_hotspot_end, $new_value );
 	}
 
-
-
 	/**
-	 * Performs atomic update of option value
-	 * from old to new value. Makes sure that only single process updates it.
-	 * Only single process gets true return value when multiple tries to do that.
+	 * Prolongs the hotspot end option by updating its value.
+	 *
+	 * This method updates the `w3tc_stats_hotspot_end` option in the `sitemeta` table,
+	 * changing the old value to the new value for the current site. It checks for the
+	 * specific old value and performs an update if it matches. The method returns true
+	 * if the update was successful and false otherwise.
+	 *
+	 * @param mixed $old_value The old value to match in the database.
+	 * @param mixed $new_value The new value to set for the hotspot end option.
+	 *
+	 * @return bool True if the update was successful, false otherwise.
 	 */
 	public function prolong_hotspot_end( $old_value, $new_value ) {
 		global $wpdb;
 
-		$result = $wpdb->query( $wpdb->prepare(
-				'UPDATE ' . $wpdb->sitemeta . ' ' .
-				'SET meta_value = %s ' .
-				'WHERE site_id = %d AND meta_key = %s AND meta_value = %s',
-				$new_value, $wpdb->siteid, $this->option_hotspot_end, $old_value ) );
+		$result    = $wpdb->query(
+			$wpdb->prepare(
+				'UPDATE ' . $wpdb->sitemeta . ' SET meta_value = %s WHERE site_id = %d AND meta_key = %s AND meta_value = %s',
+				$new_value,
+				$wpdb->siteid,
+				$this->option_hotspot_end,
+				$old_value
+			)
+		);
 		$succeeded = ( $result > 0 );
 
 		return $succeeded;
diff --git a/UserExperience_DeferScripts_Extension.php b/UserExperience_DeferScripts_Extension.php
index 8d1e6efde..1ece0e013 100644
--- a/UserExperience_DeferScripts_Extension.php
+++ b/UserExperience_DeferScripts_Extension.php
@@ -14,20 +14,22 @@
 /**
  * UserExperience DeferScripts Extension.
  *
+ * phpcs:disable WordPress.WP.AlternativeFunctions
+ *
  * @since 2.4.2
  */
 class UserExperience_DeferScripts_Extension {
 	/**
 	 * Config.
 	 *
-	 * @var object
+	 * @var Config
 	 */
 	private $config;
 
 	/**
 	 * Mutator.
 	 *
-	 * @var object
+	 * @var UserExperience_DeferScripts_Mutator
 	 */
 	private $mutator;
 
diff --git a/UserExperience_DeferScripts_Page_View.php b/UserExperience_DeferScripts_Page_View.php
index 5e0aaccec..fa4491574 100644
--- a/UserExperience_DeferScripts_Page_View.php
+++ b/UserExperience_DeferScripts_Page_View.php
@@ -32,6 +32,7 @@
 		<?php
 		echo wp_kses(
 			sprintf(
+				// Translators: 1 opening HTML a tag to pagespeed settings page, 2 closing HTML a tag.
 				__(
 					'To identify render-blocking JavaScript sources, use the %1$sGoogle PageSpeed%2$s tool and add appropirate URLs from the "Eliminate render-blocking resources" section to the Delay List textarea below.',
 					'w3-total-cache'
diff --git a/UserExperience_Emoji_Extension.php b/UserExperience_Emoji_Extension.php
index 695d4a2d2..a8c53fad8 100644
--- a/UserExperience_Emoji_Extension.php
+++ b/UserExperience_Emoji_Extension.php
@@ -1,7 +1,25 @@
 <?php
+/**
+ * File: UserExperience_Emoji_Extension.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_Emoji_Extension
+ */
 class UserExperience_Emoji_Extension {
+	/**
+	 * Executes the necessary actions to disable emoji functionality in WordPress.
+	 *
+	 * This method removes WordPress's default emoji-related actions and filters to prevent emojis from being added
+	 * to the HTML output, email content, and RSS feeds. Additionally, it hooks into other filters to manage TinyMCE
+	 * plugins and resource hints related to emojis.
+	 *
+	 * @return void
+	 */
 	public function run() {
 		remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
 		remove_action( 'wp_print_styles', 'print_emoji_styles' );
@@ -14,41 +32,57 @@ public function run() {
 		remove_action( 'admin_print_styles', 'print_emoji_styles' );
 
 		add_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ) );
-		add_filter( 'wp_resource_hints',
-			array( $this, 'wp_resource_hints' ), 10, 2 );
+		add_filter( 'wp_resource_hints', array( $this, 'wp_resource_hints' ), 10, 2 );
 	}
 
-
-
+	/**
+	 * Filters TinyMCE plugins to remove the emoji plugin.
+	 *
+	 * This method checks if the provided `$plugins` array is valid, then filters it to remove the 'wpemoji' plugin
+	 * from the list, which disables the emoji plugin in the TinyMCE editor.
+	 *
+	 * @param array $plugins An array of TinyMCE plugins.
+	 *
+	 * @return array The filtered array of TinyMCE plugins with 'wpemoji' removed.
+	 */
 	public function tiny_mce_plugins( $plugins ) {
-		if ( !is_array( $plugins ) ) {
+		if ( ! is_array( $plugins ) ) {
 			return array();
 		}
 
-		return array_filter( $plugins,
+		return array_filter(
+			$plugins,
 			function( $v ) {
-				return $v != 'wpemoji';
+				return 'wpemoji' !== $v;
 			}
 		);
 	}
 
-
-
+	/**
+	 * Filters the resource hints to remove unnecessary DNS prefetch for emoji-related resources.
+	 *
+	 * This method checks if the provided `$urls` is a valid array and if the `$relation_type` is 'dns-prefetch'.
+	 * It then filters out the 'https://s.w.org/' URL used by WordPress for emoji DNS prefetching.
+	 *
+	 * @param array  $urls          An array of resource URLs.
+	 * @param string $relation_type The type of relation for the resource hints (e.g., 'dns-prefetch').
+	 *
+	 * @return array The filtered array of resource URLs, excluding the emoji DNS prefetch URL.
+	 */
 	public function wp_resource_hints( $urls, $relation_type ) {
-		if ( !is_array( $urls ) || $relation_type != 'dns-prefetch' ) {
+		if ( ! is_array( $urls ) || 'dns-prefetch' !== $relation_type ) {
 			return $urls;
 		}
 
-		// remove s.w.org dns-prefetch used by emojis
-		return array_filter( $urls,
+		// remove s.w.org dns-prefetch used by emojis.
+		return array_filter(
+			$urls,
 			function( $v ) {
-				return ( substr( $v, 0, 16) != 'https://s.w.org/' );
+				return ( 'https://s.w.org/' !== substr( $v, 0, 16 ) );
 			}
 		);
 	}
 }
 
-
-
 $o = new UserExperience_Emoji_Extension();
 $o->run();
diff --git a/UserExperience_GeneralPage.php b/UserExperience_GeneralPage.php
index a8e3ccf5c..5d90152de 100644
--- a/UserExperience_GeneralPage.php
+++ b/UserExperience_GeneralPage.php
@@ -1,32 +1,62 @@
 <?php
+/**
+ * File: UserExperience_GeneralPage.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_GeneralPage
+ */
 class UserExperience_GeneralPage {
 	/**
-	 * W3TC General settings page modifications
+	 * Initializes the admin hooks and filters for the general settings page.
+	 *
+	 * This method sets up the necessary filters and actions to integrate
+	 * the User Experience functionality into the W3TC general settings page.
+	 *
+	 * @return void
 	 */
-	static public function admin_init_w3tc_general() {
+	public static function admin_init_w3tc_general() {
 		$o = new UserExperience_GeneralPage();
 
-		add_filter( 'w3tc_settings_general_anchors',
-			array( $o, 'w3tc_settings_general_anchors' ) );
-		add_action( 'w3tc_settings_general_boxarea_userexperience',
-			array( $o, 'w3tc_settings_general_boxarea_userexperience' ) );
+		add_filter( 'w3tc_settings_general_anchors', array( $o, 'w3tc_settings_general_anchors' ) );
+		add_action( 'w3tc_settings_general_boxarea_userexperience', array( $o, 'w3tc_settings_general_boxarea_userexperience' ) );
 	}
 
-
-
-
+	/**
+	 * Modifies the anchors used in the W3TC general settings navigation.
+	 *
+	 * Adds the "User Experience" section to the list of anchors displayed
+	 * in the general settings page, enabling users to quickly navigate
+	 * to the relevant section.
+	 *
+	 * @param array $anchors Existing anchors in the general settings navigation.
+	 *
+	 * @return array Updated list of anchors including the User Experience section.
+	 */
 	public function w3tc_settings_general_anchors( $anchors ) {
-		$anchors[] = array( 'id' => 'userexperience', 'text' => 'User Experience' );
+		$anchors[] = array(
+			'id'   => 'userexperience',
+			'text' => 'User Experience',
+		);
+
 		return $anchors;
 	}
 
-
-
+	/**
+	 * Displays the User Experience settings box area on the W3TC general settings page.
+	 *
+	 * Includes the necessary view file to render the User Experience settings
+	 * section in the W3TC general settings interface.
+	 *
+	 * @return void
+	 */
 	public function w3tc_settings_general_boxarea_userexperience() {
 		$config = Dispatcher::config();
 
-		include  W3TC_DIR . '/UserExperience_GeneralPage_View.php';
+		include W3TC_DIR . '/UserExperience_GeneralPage_View.php';
 	}
 }
diff --git a/UserExperience_GeneralPage_View.php b/UserExperience_GeneralPage_View.php
index e1d086085..7bbabe88b 100644
--- a/UserExperience_GeneralPage_View.php
+++ b/UserExperience_GeneralPage_View.php
@@ -78,7 +78,7 @@
 			'score'             => '+10',
 			'score_label'       => __( 'Points', 'w3-total-cache' ),
 			'score_description' => __( 'In a recent test, using the Lazy Load Google Maps feature added 10 points to the Google PageSpeed mobile score!', 'w3-total-cache' ),
-			'score_link'        => 'https://www.boldgrid.com/support/w3-total-cache/pagespeed-tests/lazy-load-maps/?utm_source=w3tc&utm_medium=lazy-load-maps&utm_campaign=proof'
+			'score_link'        => 'https://www.boldgrid.com/support/w3-total-cache/pagespeed-tests/lazy-load-maps/?utm_source=w3tc&utm_medium=lazy-load-maps&utm_campaign=proof',
 		)
 	);
 
diff --git a/UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy.php b/UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy.php
index 24439fcf2..dfa9c7f97 100644
--- a/UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy.php
+++ b/UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy.php
@@ -1,47 +1,90 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy
+ */
 class UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy {
+	/**
+	 * Stores the URL of the script to be preloaded.
+	 *
+	 * @var string
+	 */
 	private $preload_url = '';
 
-
-
+	/**
+	 * Modifies the buffer to optimize script loading for Google Maps integration.
+	 *
+	 * This method adjusts the output buffer to include a preload tag for the script associated with
+	 * Google Maps if the script URL matches certain criteria. It also ensures the buffer is updated
+	 * for lazy loading and adds necessary filters.
+	 *
+	 * @param array $data An array containing the buffer and a modified flag.
+	 *                    - `buffer` (string): The HTML buffer to be modified.
+	 *                    - `modified` (bool): A flag indicating if the buffer was modified.
+	 *
+	 * @return array The modified `$data` array.
+	 */
 	public function w3tc_lazyload_mutator_before( $data ) {
 		$buffer = $data['buffer'];
 		$buffer = preg_replace_callback(
 			'~(<script\s[^>]+>)~i',
-			array( $this, 'tag_script' ), $buffer
+			array( $this, 'tag_script' ),
+			$buffer
 		);
 
-		if ( !empty( $this->preload_url ) ) {
+		if ( ! empty( $this->preload_url ) ) {
 			$preload_html = '<link rel="preload" href="' . esc_url( $this->preload_url ) . '" as="script">';
 
-			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui',
-				'\\0' . $preload_html, $buffer, 1 );
+			$buffer = preg_replace(
+				'~<head(\s+[^>]*)*>~Ui',
+				'\\0' . $preload_html,
+				$buffer,
+				1
+			);
 
-			add_filter( 'w3tc_lazyload_on_initialized_javascript', array(
-				$this, 'w3tc_lazyload_on_initialized_javascript' ) );
+			add_filter( 'w3tc_lazyload_on_initialized_javascript', array( $this, 'w3tc_lazyload_on_initialized_javascript' ) );
 		}
 
-		$data['buffer'] = $buffer;
-		$data['modified'] |= !empty( $this->preload_url );
+		$data['buffer']    = $buffer;
+		$data['modified'] |= ! empty( $this->preload_url );
 
 		return $data;
 	}
 
-
-
+	/**
+	 * Processes a script tag to identify and handle specific Google Maps scripts.
+	 *
+	 * This method examines the script tag to check if it matches the Google Maps Easy plugin's
+	 * frontend script. If a match is found, it updates the `$preload_url` and removes the tag from the buffer.
+	 *
+	 * @param array $m Matches from the regular expression applied to the buffer.
+	 *                 - $m[0] (string): The full matched script tag.
+	 *
+	 * @return string The modified or original script tag.
+	 */
 	public function tag_script( $m ) {
 		$script_tag = $m[0];
-		if ( !preg_match( '~<script\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is',
-				$script_tag, $match ) ) {
+		if (
+			! preg_match(
+				'~<script\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is',
+				$script_tag,
+				$match
+			)
+		) {
 			return $script_tag;
 		}
 
 		$script_src = $match[1];
 		$script_src = Util_Environment::url_relative_to_full( $script_src );
 
-		if ( !$this->starts_with( $script_src, WP_PLUGIN_URL . '/google-maps-easy/modules/gmap/js/frontend.gmap.js' ) ) {
+		if ( ! $this->starts_with( $script_src, WP_PLUGIN_URL . '/google-maps-easy/modules/gmap/js/frontend.gmap.js' ) ) {
 			return $script_tag;
 		}
 
@@ -49,20 +92,35 @@ public function tag_script( $m ) {
 		return '';
 	}
 
-
-
+	/**
+	 * Checks if a string starts with a given prefix.
+	 *
+	 * Utility function to determine if the provided string begins with the specified prefix.
+	 *
+	 * @param string $v      The string to check.
+	 * @param string $prefix The prefix to look for.
+	 *
+	 * @return bool True if the string starts with the prefix, false otherwise.
+	 */
 	private function starts_with( $v, $prefix ) {
-		return substr( $v, 0, strlen( $prefix ) ) == $prefix;
+		return substr( $v, 0, strlen( $prefix ) ) === $prefix;
 	}
 
-
-
+	/**
+	 * Generates the JavaScript initialization code for lazy loading Google Maps.
+	 *
+	 * This method returns the JavaScript code that initializes lazy loading for Google Maps
+	 * using the LazyLoad library. It includes a callback to dynamically load the required script
+	 * when the map element enters the viewport.
+	 *
+	 * @return string The JavaScript code for initializing lazy loading.
+	 */
 	public function w3tc_lazyload_on_initialized_javascript() {
 		return 'window.w3tc_lazyLazy_googlemaps_wpmaps = new LazyLoad({' .
-			'elements_selector: ".gmp_map_opts",'.
+			'elements_selector: ".gmp_map_opts",' .
 			'callback_enter: function(e){' .
 
-				// w3tc_load_js function
+				// w3tc_load_js function.
 				'function w3tc_load_js(t,n){"use strict";var o=document.getElementsByTagName("script")[0],r=document.createElement("script");return r.src=t,r.async=!0,o.parentNode.insertBefore(r,o),n&&"function"==typeof n&&(r.onload=n),r};' .
 
 				'w3tc_load_js("' . esc_url( $this->preload_url ) . '");' .
diff --git a/UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin.php b/UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin.php
index dd2f83b9d..a1779f6d3 100644
--- a/UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin.php
+++ b/UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin.php
@@ -1,10 +1,32 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin
+ */
 class UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin {
+	/**
+	 * Filters the output buffer to modify Google Maps script initialization for compatibility with
+	 * W3 Total Cache lazy loading.
+	 *
+	 * This method checks the output buffer for a specific Google Maps initialization script. If found,
+	 * it modifies the script to enable lazy loading of the maps using W3 Total Cache's lazy load
+	 * functionality. Additionally, it registers a callback for lazy loading initialization.
+	 *
+	 * @param array $data An associative array containing buffer data. The 'buffer' key holds the HTML
+	 *                    content to process.
+	 *
+	 * @return array Modified buffer data with Google Maps lazy load compatibility adjustments.
+	 */
 	public function w3tc_lazyload_mutator_before( $data ) {
 		$buffer = $data['buffer'];
-		if (strpos( $buffer, '<script>jQuery(document).ready(function($) {var map' ) === false ) {
+		if ( strpos( $buffer, '<script>jQuery(document).ready(function($) {var map' ) === false ) {
 			return $data;
 		}
 
@@ -14,22 +36,28 @@ public function w3tc_lazyload_mutator_before( $data ) {
 			$buffer
 		);
 
-		add_filter( 'w3tc_lazyload_on_initialized_javascript', array(
-			$this, 'w3tc_lazyload_on_initialized_javascript' ) );
+		add_filter( 'w3tc_lazyload_on_initialized_javascript', array( $this, 'w3tc_lazyload_on_initialized_javascript' ) );
 
-		$data['buffer'] = $buffer;
+		$data['buffer']   = $buffer;
 		$data['modified'] = true;
 
 		return $data;
 	}
 
-
-
+	/**
+	 * Generates the JavaScript code for initializing the lazy loading of Google Maps.
+	 *
+	 * This method provides the required JavaScript code for integrating Google Maps with W3 Total
+	 * Cache's lazy load functionality. It sets up lazy loading for map containers and defines a
+	 * callback to initialize maps when they enter the viewport.
+	 *
+	 * @return string JavaScript code for initializing lazy loading of Google Maps.
+	 */
 	public function w3tc_lazyload_on_initialized_javascript() {
 		return 'window.w3tc_lazyLazy_googlemaps_wpmapplugin = new LazyLoad({' .
-			'elements_selector: ".wpgmp_map_container",'.
+			'elements_selector: ".wpgmp_map_container",' .
 			'callback_enter: function(e){' .
-				'window.w3tc_wpgmp_load(jQuery)'.
+				'window.w3tc_wpgmp_load(jQuery)' .
 			'}});';
 	}
 }
diff --git a/UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps.php b/UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps.php
index 59afd9bcf..514b9cc0e 100644
--- a/UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps.php
+++ b/UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps.php
@@ -1,71 +1,128 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps
+ */
 class UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps {
+	/**
+	 * The URL of the script to preload. Set when a specific script is identified for lazy loading.
+	 *
+	 * @var string
+	 */
 	private $preload_url = '';
 
-
-
+	/**
+	 * Modifies the buffer before the lazy load mutator processes it.
+	 * This method identifies and processes `<script>` tags in the buffer to determine if a specific
+	 * script (e.g., wp-google-maps JavaScript) needs to be preloaded. If a preload URL is set, it
+	 * injects a `<link>` tag for preloading the script.
+	 *
+	 * @param array $data {
+	 *     Array of data passed to the mutator.
+	 *
+	 *     @type string $buffer  The HTML buffer to modify.
+	 *     @type bool   $modified Whether the buffer has been modified.
+	 * }
+	 *
+	 * @return array Modified data with updated buffer and modified flag.
+	 */
 	public function w3tc_lazyload_mutator_before( $data ) {
 		$buffer = $data['buffer'];
 		$buffer = preg_replace_callback(
 			'~(<script\s[^>]+>)~i',
-			array( $this, 'tag_script' ), $buffer
+			array( $this, 'tag_script' ),
+			$buffer
 		);
 
-		if ( !empty( $this->preload_url ) ) {
+		if ( ! empty( $this->preload_url ) ) {
 			$preload_html = '<link rel="preload" href="' . esc_url( $this->preload_url ) . '" as="script">';
 
-			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui',
-				'\\0' . $preload_html, $buffer, 1 );
+			$buffer = preg_replace(
+				'~<head(\s+[^>]*)*>~Ui',
+				'\\0' . $preload_html,
+				$buffer,
+				1
+			);
 
-			add_filter( 'w3tc_lazyload_on_initialized_javascript', array(
-				$this, 'w3tc_lazyload_on_initialized_javascript' ) );
+			add_filter( 'w3tc_lazyload_on_initialized_javascript', array( $this, 'w3tc_lazyload_on_initialized_javascript' ) );
 		}
 
-		$data['buffer'] = $buffer;
-		$data['modified'] |= !empty( $this->preload_url );
+		$data['buffer']    = $buffer;
+		$data['modified'] |= ! empty( $this->preload_url );
 
 		return $data;
 	}
 
-
-
+	/**
+	 * Callback function to process `<script>` tags.
+	 * This method checks if a `<script>` tag matches a specific JavaScript file (e.g., wp-google-maps).
+	 * If it matches, it sets the preload URL and removes the `<script>` tag from the buffer.
+	 *
+	 * @param array $m Array of matches from the regex callback.
+	 *
+	 * @return string Modified `<script>` tag or an empty string if the script is processed for preload.
+	 */
 	public function tag_script( $m ) {
 		$script_tag = $m[0];
-		if ( !preg_match( '~<script\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is',
-				$script_tag, $match ) ) {
+		if (
+			! preg_match(
+				'~<script\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is',
+				$script_tag,
+				$match
+			)
+		) {
 			return $script_tag;
 		}
 
 		$script_src = $match[1];
 		$script_src = Util_Environment::url_relative_to_full( $script_src );
 
-		if ( !$this->starts_with( $script_src, WP_PLUGIN_URL . '/wp-google-maps/js/wpgmaps.js' ) ) {
+		if ( ! $this->starts_with( $script_src, WP_PLUGIN_URL . '/wp-google-maps/js/wpgmaps.js' ) ) {
 			return $script_tag;
 		}
 
 		$this->preload_url = $script_src;
+
 		return '';
 	}
 
-
-
+	/**
+	 * Determines if a string starts with a given prefix.
+	 * Utility function to check if a string starts with a specific prefix.
+	 *
+	 * @param string $v      The string to check.
+	 * @param string $prefix The prefix to check against.
+	 *
+	 * @return bool True if the string starts with the prefix, false otherwise.
+	 */
 	private function starts_with( $v, $prefix ) {
-		return substr( $v, 0, strlen( $prefix ) ) == $prefix;
+		return substr( $v, 0, strlen( $prefix ) ) === $prefix;
 	}
 
 
-
+	/**
+	 * Generates JavaScript code for lazy loading Google Maps.
+	 * This method returns JavaScript code that initializes a `LazyLoad` instance for Google Maps.
+	 * The code dynamically loads the Google Maps script when the map element is in view.
+	 *
+	 * @return string JavaScript code for lazy loading Google Maps.
+	 */
 	public function w3tc_lazyload_on_initialized_javascript() {
 		return 'window.w3tc_lazyLazy_googlemaps_wpmaps = new LazyLoad({' .
-			'elements_selector: "#wpgmza_map",'.
+			'elements_selector: "#wpgmza_map",' .
 			'callback_enter: function(e){' .
 
-				// w3tc_load_js function
+				// w3tc_load_js function.
 				'function w3tc_load_js(t,n){"use strict";var o=document.getElementsByTagName("script")[0],r=document.createElement("script");return r.src=t,r.async=!0,o.parentNode.insertBefore(r,o),n&&"function"==typeof n&&(r.onload=n),r};' .
 
-				// hack to allow initialize-on-load script pass
+				// hack to allow initialize-on-load script pass.
 				'MYMAP = {init: function() {},placeMarkers: function() {}};' .
 
 				'w3tc_load_js("' . esc_url( $this->preload_url ) . '", function() {InitMap()});' .
diff --git a/UserExperience_LazyLoad_Mutator.php b/UserExperience_LazyLoad_Mutator.php
index 586d44ca9..8f89e9431 100644
--- a/UserExperience_LazyLoad_Mutator.php
+++ b/UserExperience_LazyLoad_Mutator.php
@@ -1,50 +1,98 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_Mutator.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_Mutator
+ */
 class UserExperience_LazyLoad_Mutator {
+	/**
+	 * Configuration settings for lazy loading.
+	 *
+	 * @var Config
+	 */
 	private $config;
+
+	/**
+	 * Tracks whether the content was modified during processing.
+	 *
+	 * @var bool
+	 */
 	private $modified = false;
-	private $excludes;
-	private $posts_by_url;
 
+	/**
+	 * List of content patterns to exclude from lazy loading.
+	 *
+	 * @var array
+	 */
+	private $excludes;
 
+	/**
+	 * Map of post URLs to their corresponding post IDs.
+	 *
+	 * @var array
+	 */
+	private $posts_by_url;
 
+	/**
+	 * Constructor for UserExperience_LazyLoad_Mutator.
+	 *
+	 * @param array $config       Configuration settings for lazy loading.
+	 * @param array $posts_by_url Map of post URLs to their corresponding post IDs.
+	 *
+	 * @return void
+	 */
 	public function __construct( $config, $posts_by_url ) {
-		$this->config = $config;
+		$this->config       = $config;
 		$this->posts_by_url = $posts_by_url;
 	}
 
-
-
+	/**
+	 * Runs the lazy loading mutator process on the provided buffer.
+	 *
+	 * @param string $buffer The HTML content to process for lazy loading.
+	 *
+	 * @return string The modified buffer with lazy loading applied.
+	 */
 	public function run( $buffer ) {
-		$this->excludes = apply_filters( 'w3tc_lazyload_excludes',
-			$this->config->get_array( 'lazyload.exclude' ) );
-
-		$r = apply_filters( 'w3tc_lazyload_mutator_before', array(
-			'buffer' => $buffer,
-			'modified' => $this->modified
-		) );
-		$buffer = $r['buffer'];
+		$this->excludes = apply_filters( 'w3tc_lazyload_excludes', $this->config->get_array( 'lazyload.exclude' ) );
+
+		$r              = apply_filters(
+			'w3tc_lazyload_mutator_before',
+			array(
+				'buffer'   => $buffer,
+				'modified' => $this->modified,
+			)
+		);
+		$buffer         = $r['buffer'];
 		$this->modified = $r['modified'];
 
 		$unmutable = new UserExperience_LazyLoad_Mutator_Unmutable();
-		$buffer = $unmutable->remove_unmutable( $buffer );
+		$buffer    = $unmutable->remove_unmutable( $buffer );
 
 		if ( $this->config->get_boolean( 'lazyload.process_img' ) ) {
 			$buffer = preg_replace_callback(
 				'~<picture(\s[^>]+)*>(.*?)</picture>~is',
-				array( $this, 'tag_picture' ), $buffer
+				array( $this, 'tag_picture' ),
+				$buffer
 			);
 			$buffer = preg_replace_callback(
 				'~<img\s[^>]+>~is',
-				array( $this, 'tag_img' ), $buffer
+				array( $this, 'tag_img' ),
+				$buffer
 			);
 		}
 
 		if ( $this->config->get_boolean( 'lazyload.process_background' ) ) {
 			$buffer = preg_replace_callback(
 				'~<[^>]+background(-image)?:\s*url[^>]+>~is',
-				array( $this, 'tag_with_background' ), $buffer
+				array( $this, 'tag_with_background' ),
+				$buffer
 			);
 		}
 
@@ -53,14 +101,22 @@ public function run( $buffer ) {
 		return $buffer;
 	}
 
-
-
+	/**
+	 * Checks if the content has been modified during processing.
+	 *
+	 * @return bool True if the content was modified; otherwise, false.
+	 */
 	public function content_modified() {
 		return $this->modified;
 	}
 
-
-
+	/**
+	 * Processes <picture> tags for lazy loading.
+	 *
+	 * @param array $matches Regex matches for the <picture> tag.
+	 *
+	 * @return string The modified <picture> tag with lazy loading applied.
+	 */
 	public function tag_picture( $matches ) {
 		$content = $matches[0];
 
@@ -69,11 +125,17 @@ public function tag_picture( $matches ) {
 		}
 
 		$m = new UserExperience_LazyLoad_Mutator_Picture( $this );
+
 		return $m->run( $content );
 	}
 
-
-
+	/**
+	 * Processes <img> tags for lazy loading.
+	 *
+	 * @param array $matches Regex matches for the <img> tag.
+	 *
+	 * @return string The modified <img> tag with lazy loading applied.
+	 */
 	public function tag_img( $matches ) {
 		$content = $matches[0];
 
@@ -81,63 +143,84 @@ public function tag_img( $matches ) {
 			return $content;
 		}
 
-		// get image dimensions
+		// get image dimensions.
 		$dim = $this->tag_get_dimensions( $content );
 		return $this->tag_img_content_replace( $content, $dim );
 	}
 
-
-
 	/**
-	 * Common replace code for picture and img tags
+	 * Replaces <img> content with placeholders and adds lazy loading attributes.
+	 *
+	 * @param string $content The <img> tag content.
+	 * @param array  $dim     The dimensions of the image (width and height).
+	 *
+	 * @return string The modified <img> tag.
 	 */
 	public function tag_img_content_replace( $content, $dim ) {
-		// do replace
-		$count = 0;
-		$content = preg_replace( '~(\s)src=~is',
-			'$1src="' . $this->placeholder( $dim['w'], $dim['h'] ) .
-			'" data-src=', $content, -1, $count );
+		// do replace.
+		$count   = 0;
+		$content = preg_replace(
+			'~(\s)src=~is',
+			'$1src="' . $this->placeholder( $dim['w'], $dim['h'] ) . '" data-src=',
+			$content,
+			-1,
+			$count
+		);
 
 		if ( $count > 0 ) {
-			$content = preg_replace( '~(\s)(srcset|sizes)=~is',
-				'$1data-$2=', $content );
+			$content = preg_replace(
+				'~(\s)(srcset|sizes)=~is',
+				'$1data-$2=',
+				$content
+			);
 
-			$content = $this->add_class_lazy( $content );
-			$content = $this->remove_native_lazy( $content );
+			$content        = $this->add_class_lazy( $content );
+			$content        = $this->remove_native_lazy( $content );
 			$this->modified = true;
 		}
 
 		return $content;
 	}
 
-
-
 	/**
-	 * Common get dimensions of image
+	 * Extracts image dimensions from <img> content or associated metadata.
+	 *
+	 * @param string $content The <img> tag content.
+	 *
+	 * @return array The dimensions of the image (width and height).
 	 */
 	public function tag_get_dimensions( $content ) {
-		$dim = array( 'w' => 1, 'h' => 1 );
-		$m = null;
+		$dim = array(
+			'w' => 1,
+			'h' => 1,
+		);
+		$m   = null;
 		if ( preg_match( '~\swidth=[\s\'"]*([0-9]+)~is', $content, $m ) ) {
-			$dim['h'] = $dim['w'] = (int)$m[1];
+			$dim['w'] = (int) $m[1];
+			$dim['h'] = $dim['w'];
 
 			if ( preg_match( '~\sheight=[\s\'"]*([0-9]+)~is', $content, $m ) ) {
-				$dim['h'] = (int)$m[1];
+				$dim['h'] = (int) $m[1];
 				return $dim;
 			}
 		}
 
-		// if not in attributes - try to find via url
-		if ( !preg_match( '~\ssrc=(\'([^\']*)\'|"([^"]*)"|([^\'"][^\\s]*))~is',
-				$content, $m ) ) {
+		// if not in attributes - try to find via url.
+		if (
+			! preg_match(
+				'~\ssrc=(\'([^\']*)\'|"([^"]*)"|([^\'"][^\\s]*))~is',
+				$content,
+				$m
+			)
+		) {
 			return $dim;
 		}
 
-		$url = ( !empty( $m[4] ) ? $m[4] : ( ( !empty( $m[3] ) ? $m[3] : $m[2] ) ) );
+		$url = ( ! empty( $m[4] ) ? $m[4] : ( ( ! empty( $m[3] ) ? $m[3] : $m[2] ) ) );
 
-		// full url found
-		if ( isset( $this->posts_by_url[$url] ) ) {
-			$post_id = $this->posts_by_url[$url];
+		// full url found.
+		if ( isset( $this->posts_by_url[ $url ] ) ) {
+			$post_id = $this->posts_by_url[ $url ];
 
 			$image = wp_get_attachment_image_src( $post_id, 'full' );
 			if ( $image ) {
@@ -148,23 +231,30 @@ public function tag_get_dimensions( $content ) {
 			return $dim;
 		}
 
-		// try resized url by format
+		// try resized url by format.
 		static $base_url = null;
 		if ( is_null( $base_url ) ) {
 			$base_url = wp_get_upload_dir()['baseurl'];
 		}
 
-		if ( substr( $url, 0, strlen( $base_url ) ) == $base_url &&
-				 preg_match( '~(.+)-(\\d+)x(\\d+)(\\.[a-z0-9]+)$~is', $url, $m ) ) {
-			$dim['w'] = (int)$m[2];
-			$dim['h'] = (int)$m[3];
+		if (
+			substr( $url, 0, strlen( $base_url ) ) === $base_url &&
+			preg_match( '~(.+)-(\\d+)x(\\d+)(\\.[a-z0-9]+)$~is', $url, $m )
+		) {
+			$dim['w'] = (int) $m[2];
+			$dim['h'] = (int) $m[3];
 		}
 
 		return $dim;
 	}
 
-
-
+	/**
+	 * Processes elements with background styles for lazy loading.
+	 *
+	 * @param array $matches Regex matches for elements with background styles.
+	 *
+	 * @return string The modified element with lazy loading applied.
+	 */
 	public function tag_with_background( $matches ) {
 		$content = $matches[0];
 
@@ -173,68 +263,95 @@ public function tag_with_background( $matches ) {
 		}
 
 		$quote_match = null;
-		if ( !preg_match( '~\s+style\s*=\s*([\"\'])~is', $content, $quote_match ) ) {
+		if ( ! preg_match( '~\s+style\s*=\s*([\"\'])~is', $content, $quote_match ) ) {
 			return $content;
 		}
+
 		$quote = $quote_match[1];
 
-		$count = 0;
+		$count   = 0;
 		$content = preg_replace_callback(
 			'~(\s+)(style\s*=\s*[' . $quote . '])(.*?)([' . $quote . '])~is',
-			array( $this, 'style_offload_background' ), $content, -1, $count
+			array( $this, 'style_offload_background' ),
+			$content,
+			-1,
+			$count
 		);
 
 		if ( $count > 0 ) {
-			$content = $this->add_class_lazy( $content );
+			$content        = $this->add_class_lazy( $content );
 			$this->modified = true;
 		}
 
 		return $content;
 	}
 
-
-
+	/**
+	 * Offloads background styles for lazy loading.
+	 *
+	 * @param array $matches Regex matches for background styles.
+	 *
+	 * @return string The modified style attribute with lazy loading applied.
+	 */
 	public function style_offload_background( $matches ) {
 		list( $match, $v1, $v2, $v, $quote ) = $matches;
-		$url_match = null;
+		$url_match                           = null;
 		preg_match( '~background(-image)?:\s*(url\([^>]+\))~is', $v, $url_match );
 		$v = preg_replace( '~background(-image)?:\s*url\([^>]+\)[;]?\s*~is', '', $v );
 
 		return $v1 . $v2 . $v . $quote . ' data-bg=' . $quote . ( isset( $url_match[2] ) ? $url_match[2] : '' ) . $quote;
 	}
 
-
-
+	/**
+	 * Adds the "lazy" class to the provided content if not already present.
+	 *
+	 * @param string $content The content to modify.
+	 *
+	 * @return string The modified content with the "lazy" class applied.
+	 */
 	private function add_class_lazy( $content ) {
-		$count = 0;
+		$count   = 0;
 		$content = preg_replace_callback(
 			'~(\s+)(class=)([\"\'])(.*?)([\"\'])~is',
-			array( $this, 'class_process' ), $content, -1, $count
+			array( $this, 'class_process' ),
+			$content,
+			-1,
+			$count
 		);
 
-		if ( $count <= 0) {
+		if ( $count <= 0 ) {
 			$content = preg_replace(
-				'~<(\S+)(\s+)~is', '<$1$2class="lazy" ', $content
+				'~<(\S+)(\s+)~is',
+				'<$1$2class="lazy" ',
+				$content
 			);
 		}
 
 		return $content;
 	}
 
-
-
 	/**
-	 * In safari javascript lazy-loaded image with loading="lazy"
-	 * dont fire events, i.e. image not loaded
+	 * Removes native lazy loading attributes from the content.
+	 *
+	 * @param string $content The content to modify.
+	 *
+	 * @return string The modified content with native lazy loading removed.
 	 */
 	public function remove_native_lazy( $content ) {
 		return preg_replace(
-			'~(\s+)loading=[\'"]lazy[\'"]~is', '', $content
+			'~(\s+)loading=[\'"]lazy[\'"]~is',
+			'',
+			$content
 		);
 	}
 
-
-
+	/**
+	 * Processes class attributes to include the "lazy" class.
+	 *
+	 * @param array $matches Regex matches for class attributes.
+	 *
+	 * @return string The modified class attribute.
+	 */
 	public function class_process( $matches ) {
 		list( $match, $v1, $v2, $quote, $v ) = $matches;
 		if ( preg_match( '~(^|\\s)lazy(\\s|$)~is', $v ) ) {
@@ -246,12 +363,17 @@ public function class_process( $matches ) {
 		return $v1 . $v2 . $quote . $v . $quote;
 	}
 
-
-
+	/**
+	 * Determines if the content should be excluded from lazy loading.
+	 *
+	 * @param string $content The content to check.
+	 *
+	 * @return bool True if the content is excluded; otherwise, false.
+	 */
 	private function is_content_excluded( $content ) {
 		foreach ( $this->excludes as $w ) {
-			if ( !empty($w) ) {
-				if ( strpos( $content, $w ) !== FALSE ) {
+			if ( ! empty( $w ) ) {
+				if ( strpos( $content, $w ) !== false ) {
 					return true;
 				}
 			}
@@ -260,10 +382,16 @@ private function is_content_excluded( $content ) {
 		return false;
 	}
 
-
-
+	/**
+	 * Generates a placeholder SVG for an image with the given dimensions.
+	 *
+	 * @param int $w The width of the image.
+	 * @param int $h The height of the image.
+	 *
+	 * @return string The SVG placeholder.
+	 */
 	public function placeholder( $w, $h ) {
 		return 'data:image/svg+xml,%3Csvg%20xmlns=\'http://www.w3.org/2000/svg\'%20viewBox=\'0%200%20' .
-			$w . '%20'. $h . '\'%3E%3C/svg%3E';
+			$w . '%20' . $h . '\'%3E%3C/svg%3E';
 	}
 }
diff --git a/UserExperience_LazyLoad_Mutator_Picture.php b/UserExperience_LazyLoad_Mutator_Picture.php
index 515c879fa..2e84428a2 100644
--- a/UserExperience_LazyLoad_Mutator_Picture.php
+++ b/UserExperience_LazyLoad_Mutator_Picture.php
@@ -1,51 +1,97 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_Mutator_Picture.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_Mutator_Picture
+ */
 class UserExperience_LazyLoad_Mutator_Picture {
+	/**
+	 * Constructor for the UserExperience_LazyLoad_Mutator_Picture class.
+	 *
+	 * An instance of a common utility class used to process image and source tags.
+	 *
+	 * @var object
+	 */
 	private $common;
 
-
-
+	/**
+	 * Initializes the class with a common utility instance.
+	 *
+	 * @param object $common An instance of a utility class for handling image and source tag processing.
+	 *
+	 * @return void
+	 */
 	public function __construct( $common ) {
 		$this->common = $common;
 	}
 
-
-
+	/**
+	 * Processes the provided content to modify `<img>` and `<source>` tags.
+	 *
+	 * This method replaces the `srcset` and `sizes` attributes in `<source>` tags with `data-srcset` and `data-sizes`,
+	 * and applies custom modifications to `<img>` tags using utility methods.
+	 *
+	 * @param string $content The content containing `<img>` and `<source>` tags to be processed.
+	 *
+	 * @return string The modified content with lazy-loading attributes applied.
+	 */
 	public function run( $content ) {
 		$content = preg_replace_callback(
 			'~(<img\s[^>]+>)~i',
-			array( $this, 'tag_img' ), $content
+			array( $this, 'tag_img' ),
+			$content
 		);
 
 		$content = preg_replace_callback(
 			'~(<source\s[^>]+>)~i',
-			array( $this, 'tag_source' ), $content
+			array( $this, 'tag_source' ),
+			$content
 		);
 
 		return $content;
 	}
 
-
-
+	/**
+	 * Processes a matched `<img>` tag.
+	 *
+	 * This method retrieves the dimensions of the image and replaces its attributes with lazy-loading compatible attributes.
+	 *
+	 * @param array $matches The matches from the regular expression containing the `<img>` tag.
+	 *
+	 * @return string The modified `<img>` tag with lazy-loading attributes applied.
+	 */
 	public function tag_img( $matches ) {
 		$content = $matches[0];
 
-		// get image dimensions
+		// get image dimensions.
 		$dim = $this->common->tag_get_dimensions( $content );
 		return $this->common->tag_img_content_replace( $content, $dim );
 	}
 
-
-
 	/**
-	 * Common replace code for picture and img tags
+	 * Processes a matched `<source>` tag.
+	 *
+	 * This method replaces the `srcset` and `sizes` attributes with `data-srcset` and `data-sizes`
+	 * to delay loading the sources until needed.
+	 *
+	 * @param array $matches The matches from the regular expression containing the `<source>` tag.
+	 *
+	 * @return string The modified `<source>` tag with lazy-loading attributes applied.
 	 */
 	private function tag_source( $matches ) {
 		$content = $matches[0];
 
-		$content = preg_replace( '~(\s)(srcset|sizes)=~i',
-			'$1data-$2=', $content );
+		$content = preg_replace(
+			'~(\s)(srcset|sizes)=~i',
+			'$1data-$2=',
+			$content
+		);
 
 		return $content;
 	}
diff --git a/UserExperience_LazyLoad_Mutator_Unmutable.php b/UserExperience_LazyLoad_Mutator_Unmutable.php
index b51c0166f..748ffa318 100644
--- a/UserExperience_LazyLoad_Mutator_Unmutable.php
+++ b/UserExperience_LazyLoad_Mutator_Unmutable.php
@@ -1,34 +1,80 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_Mutator_Unmutable.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_Mutator_Unmutable
+ */
 class UserExperience_LazyLoad_Mutator_Unmutable {
+	/**
+	 * An array mapping unique keys to unmutable content (e.g., scripts and styles).
+	 *
+	 * @var array
+	 */
 	private $placeholders = array();
-	private $placeholder_base = '';
 
+	/**
+	 * A base string used to create unique keys for placeholders.
+	 *
+	 * @var string
+	 */
+	private $placeholder_base = '';
 
+	/**
+	 * Constructor for the UserExperience_LazyLoad_Mutator_Unmutable class.
+	 *
+	 * Initializes the placeholder base using a hash generated from the server's request time.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
-		$this->placeholder_base = 'w3tc_lazyload_' .
-			md5( isset( $_SERVER['REQUEST_TIME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_TIME'] ) ) : '' ) . '_';
+		$this->placeholder_base = 'w3tc_lazyload_' . md5(
+			isset( $_SERVER['REQUEST_TIME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_TIME'] ) ) : ''
+		) . '_';
 	}
 
-
-
+	/**
+	 * Replaces unmutable content (e.g., scripts and styles) in the provided buffer with placeholders.
+	 *
+	 * This method identifies `<script>` and `<style>` tags in the buffer and replaces them
+	 * with unique placeholders to allow lazy loading or other transformations.
+	 *
+	 * @param string $buffer The HTML content buffer to process.
+	 *
+	 * @return string The modified buffer with placeholders replacing the unmutable content.
+	 */
 	public function remove_unmutable( $buffer ) {
-		// scripts
+		// scripts.
 		$buffer = preg_replace_callback(
 			'~<script(\b[^>]*)>(.*?)</script>~is',
-			array( $this, 'placeholder' ), $buffer );
+			array( $this, 'placeholder' ),
+			$buffer
+		);
 
-		// styles
+		// styles.
 		$buffer = preg_replace_callback(
 			'~\s*<style(\b[^>]*)>(.*?)</style>~is',
-			array($this, 'placeholder'), $buffer);
+			array( $this, 'placeholder' ),
+			$buffer
+		);
 
 		return $buffer;
 	}
 
-
-
+	/**
+	 * Restores unmutable content in the provided buffer by replacing placeholders with their original content.
+	 *
+	 * This method replaces previously added placeholders with their associated content stored in `$placeholders`.
+	 *
+	 * @param string $buffer The HTML content buffer containing placeholders.
+	 *
+	 * @return string The restored buffer with original unmutable content.
+	 */
 	public function restore_unmutable( $buffer ) {
 		return str_replace(
 			array_keys( $this->placeholders ),
@@ -37,11 +83,20 @@ public function restore_unmutable( $buffer ) {
 		);
 	}
 
-
-
+	/**
+	 * Generates a unique placeholder for a matched piece of unmutable content and stores it.
+	 *
+	 * This method is called internally by `remove_unmutable` to replace matches (e.g., scripts and styles)
+	 * with unique placeholders. The original content is stored in `$placeholders`.
+	 *
+	 * @param array $matches The matches found by the `preg_replace_callback` function,
+	 *                       where the full match is at index 0.
+	 *
+	 * @return string The generated placeholder key.
+	 */
 	public function placeholder( $matches ) {
-		$key = '{' .$this->placeholder_base . count( $this->placeholders ) . '}';
-		$this->placeholders[$key] = $matches[0];
+		$key                        = '{' . $this->placeholder_base . count( $this->placeholders ) . '}';
+		$this->placeholders[ $key ] = $matches[0];
 		return $key;
 	}
 }
diff --git a/UserExperience_LazyLoad_Page_View.php b/UserExperience_LazyLoad_Page_View.php
index c3e990390..b2cbefcd8 100644
--- a/UserExperience_LazyLoad_Page_View.php
+++ b/UserExperience_LazyLoad_Page_View.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_Page_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
 if ( ! defined( 'W3TC' ) ) {
@@ -8,10 +14,10 @@
 $c      = Dispatcher::config();
 $is_pro = Util_Environment::is_w3tc_pro( $c );
 
-$plugins                 = get_option( 'active_plugins' );
-$is_wp_google_maps       = ( in_array( 'wp-google-maps/wpGoogleMaps.php', $plugins, true ) );
-$is_wp_google_map_plugin = ( in_array( 'wp-google-map-plugin/wp-google-map-plugin.php', $plugins, true ) );
-$is_google_maps_easy     = ( in_array( 'google-maps-easy/gmp.php', $plugins, true ) );
+$active_plugins          = get_option( 'active_plugins' );
+$is_wp_google_maps       = ( in_array( 'wp-google-maps/wpGoogleMaps.php', $active_plugins, true ) );
+$is_wp_google_map_plugin = ( in_array( 'wp-google-map-plugin/wp-google-map-plugin.php', $active_plugins, true ) );
+$is_google_maps_easy     = ( in_array( 'google-maps-easy/gmp.php', $active_plugins, true ) );
 
 ?>
 <?php Util_Ui::postbox_header( esc_html__( 'Lazy Loading', 'w3-total-cache' ), '', 'lazy-loading' ); ?>
diff --git a/UserExperience_LazyLoad_Plugin.php b/UserExperience_LazyLoad_Plugin.php
index 17dcab565..27c49cbd7 100644
--- a/UserExperience_LazyLoad_Plugin.php
+++ b/UserExperience_LazyLoad_Plugin.php
@@ -1,17 +1,49 @@
 <?php
+/**
+ * File: UserExperience_LazyLoad_Plugin.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_LazyLoad_Plugin
+ */
 class UserExperience_LazyLoad_Plugin {
+	/**
+	 * Configuration object for lazy loading plugin.
+	 *
+	 * @var Config
+	 */
 	private $config;
-	private $posts_by_url = array();
 
+	/**
+	 * Mapping of attachment URLs to post IDs.
+	 *
+	 * @var array
+	 */
+	private $posts_by_url = array();
 
+	/**
+	 * Constructor to initialize the UserExperience_LazyLoad_Plugin class.
+	 *
+	 * Sets up the configuration object for managing plugin settings.
+	 *
+	 * @return void
+	 */
 	public function __construct() {
 		$this->config = Dispatcher::config();
 	}
 
-
-
+	/**
+	 * Runs the lazy loading plugin.
+	 *
+	 * Initializes output buffer callbacks, hooks for various Google Maps plugins,
+	 * and registers necessary WordPress filters.
+	 *
+	 * @return void
+	 */
 	public function run() {
 		Util_Bus::add_ob_callback( 'lazyload', array( $this, 'ob_callback' ) );
 		$this->metaslider_hooks();
@@ -19,65 +51,71 @@ public function run() {
 		if ( $this->config->get_boolean( 'lazyload.googlemaps.google_maps_easy' ) ) {
 			$p = new UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy();
 
-			add_filter( 'w3tc_lazyload_mutator_before',
-				array( $p, 'w3tc_lazyload_mutator_before' ) );
+			add_filter( 'w3tc_lazyload_mutator_before', array( $p, 'w3tc_lazyload_mutator_before' ) );
 		}
+
 		if ( $this->config->get_boolean( 'lazyload.googlemaps.wp_google_maps' ) ) {
-			add_filter( 'w3tc_lazyload_mutator_before', array(
-				new UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps(),
-				'w3tc_lazyload_mutator_before'
-			) );
+			add_filter(
+				'w3tc_lazyload_mutator_before',
+				array(
+					new UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps(),
+					'w3tc_lazyload_mutator_before',
+				)
+			);
 		}
+
 		if ( $this->config->get_boolean( 'lazyload.googlemaps.wp_google_map_plugin' ) ) {
 			$p = new UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin();
 
-			add_filter( 'w3tc_lazyload_mutator_before',
-				array( $p, 'w3tc_lazyload_mutator_before' ) );
+			add_filter( 'w3tc_lazyload_mutator_before', array( $p, 'w3tc_lazyload_mutator_before' ) );
 		}
 
-		add_filter( 'wp_get_attachment_url',
-			array( $this, 'wp_get_attachment_url' ), 10, 2 );
-		add_filter( 'w3tc_footer_comment',
-			array( $this, 'w3tc_footer_comment' ) );
-
+		add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 10, 2 );
+		add_filter( 'w3tc_footer_comment', array( $this, 'w3tc_footer_comment' ) );
 	}
 
-
-
+	/**
+	 * Output buffer callback for processing HTML content.
+	 *
+	 * Modifies the HTML buffer to include lazy loading functionality, embeds the
+	 * lazy loading script, and processes content through a mutator.
+	 *
+	 * @param string $buffer The output buffer content.
+	 *
+	 * @return string The modified or unmodified buffer content.
+	 */
 	public function ob_callback( $buffer ) {
-		if ( $buffer == '' || !\W3TC\Util_Content::is_html_xml( $buffer ) ) {
+		if ( '' === $buffer || ! \W3TC\Util_Content::is_html_xml( $buffer ) ) {
 			return $buffer;
 		}
 
 		$can_process = array(
 			'enabled' => true,
-			'buffer' => $buffer,
-			'reason' => null
+			'buffer'  => $buffer,
+			'reason'  => null,
 		);
 
 		$can_process = $this->can_process( $can_process );
 		$can_process = apply_filters( 'w3tc_lazyload_can_process', $can_process );
 
-		// set reject reason in comment
+		// set reject reason in comment.
 		if ( $can_process['enabled'] ) {
 			$reject_reason = '';
 		} else {
-			$reject_reason = empty( $can_process['reason'] ) ?
-				' (not specified)' : ' (' . $can_process['reason'] . ')';
+			$reject_reason = empty( $can_process['reason'] ) ? ' (not specified)' : ' (' . $can_process['reason'] . ')';
 		}
 
-		$buffer = str_replace( '{w3tc_lazyload_reject_reason}',
-			$reject_reason, $buffer );
+		$buffer = str_replace( '{w3tc_lazyload_reject_reason}', $reject_reason, $buffer );
 
-		// processing
-		if ( !$can_process['enabled'] ) {
+		// processing.
+		if ( ! $can_process['enabled'] ) {
 			return $buffer;
 		}
 
 		$mutator = new UserExperience_LazyLoad_Mutator( $this->config, $this->posts_by_url );
-		$buffer = $mutator->run( $buffer );
+		$buffer  = $mutator->run( $buffer );
 
-		// embed lazyload script
+		// embed lazyload script.
 		if ( $mutator->content_modified() ) {
 			$buffer = apply_filters( 'w3tc_lazyload_embed_script', $buffer );
 
@@ -90,26 +128,34 @@ public function ob_callback( $buffer ) {
 		return $buffer;
 	}
 
-
-
+	/**
+	 * Checks if lazy loading can process the current request.
+	 *
+	 * Determines if lazy loading should be enabled based on context such as
+	 * admin area, feed, or short initialization.
+	 *
+	 * @param array $can_process Array with processing status, buffer content, and reason.
+	 *
+	 * @return array Updated array with processing status and reason.
+	 */
 	private function can_process( $can_process ) {
 		if ( defined( 'WP_ADMIN' ) ) {
 			$can_process['enabled'] = false;
-			$can_process['reason'] = 'WP_ADMIN';
+			$can_process['reason']  = 'WP_ADMIN';
 
 			return $can_process;
 		}
 
 		if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
 			$can_process['enabled'] = false;
-			$can_process['reason'] = 'SHORTINIT';
+			$can_process['reason']  = 'SHORTINIT';
 
 			return $can_process;
 		}
 
 		if ( function_exists( 'is_feed' ) && is_feed() ) {
 			$can_process['enabled'] = false;
-			$can_process['reason'] = 'feed';
+			$can_process['reason']  = 'feed';
 
 			return $can_process;
 		}
@@ -117,36 +163,53 @@ private function can_process( $can_process ) {
 		return $can_process;
 	}
 
-
-
+	/**
+	 * Appends a lazy loading footer comment to strings.
+	 *
+	 * Adds a footer comment indicating the use of lazy loading and any reject reasons.
+	 *
+	 * @param array $strings Existing footer comments.
+	 *
+	 * @return array Modified footer comments.
+	 */
 	public function w3tc_footer_comment( $strings ) {
 		$strings[] = __( 'Lazy Loading', 'w3-total-cache' ) . '{w3tc_lazyload_reject_reason}';
 		return $strings;
 	}
 
-
-
+	/**
+	 * Embeds the lazy loading script into the HTML content.
+	 *
+	 * Adds the lazy loading JavaScript code and configuration to the appropriate
+	 * section of the HTML buffer.
+	 *
+	 * phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
+	 * phpcs:disable WordPress.WP.AlternativeFunctions
+	 *
+	 * @param string $buffer The HTML content buffer.
+	 *
+	 * @return string The modified buffer with the embedded script.
+	 */
 	private function embed_script( $buffer ) {
 		$js_url = plugins_url( 'pub/js/lazyload.min.js', W3TC_FILE );
 		$method = $this->config->get_string( 'lazyload.embed_method' );
 
-		$fireEvent = 'function(t){var e;try{e=new CustomEvent("w3tc_lazyload_loaded",{detail:{e:t}})}catch(a){(e=document.createEvent("CustomEvent")).initCustomEvent("w3tc_lazyload_loaded",!1,!1,{e:t})}window.dispatchEvent(e)}';
+		$fire_event = 'function(t){var e;try{e=new CustomEvent("w3tc_lazyload_loaded",{detail:{e:t}})}catch(a){(e=document.createEvent("CustomEvent")).initCustomEvent("w3tc_lazyload_loaded",!1,!1,{e:t})}window.dispatchEvent(e)}';
 
-		$thresholds = '';
+		$thresholds       = '';
 		$config_threshold = $this->config->get_string( 'lazyload.threshold' );
-		if ( !empty( $config_threshold ) ) {
-			$thresholds = 'thresholds:' . json_encode( $config_threshold ) . ',';
+		if ( ! empty( $config_threshold ) ) {
+			$thresholds = 'thresholds:' . wp_json_encode( $config_threshold ) . ',';
 		}
 
-		$config = '{elements_selector:".lazy",' . $thresholds . 'callback_loaded:' . $fireEvent . '}';
+		$config = '{elements_selector:".lazy",' . $thresholds . 'callback_loaded:' . $fire_event . '}';
 
 		$on_initialized_javascript = apply_filters( 'w3tc_lazyload_on_initialized_javascript', '' );
 
-		if ( $method == 'async_head' ) {
+		if ( 'async_head' === $method ) {
 			$on_initialized_javascript_wrapped = '';
-			if ( !empty( $on_initialized_javascript ) ) {
-				// LazyLoad::Initialized fired just before making LazyLoad global
-				// so next execution cycle have it
+			if ( ! empty( $on_initialized_javascript ) ) {
+				// LazyLoad::Initialized fired just before making LazyLoad global so next execution cycle have it.
 				$on_initialized_javascript_wrapped =
 					'window.addEventListener("LazyLoad::Initialized", function(){' .
 						'setTimeout(function() {' .
@@ -159,10 +222,14 @@ private function embed_script( $buffer ) {
 				'<style>img.lazy{min-height:1px}</style>' .
 				'<link href="' . esc_url( $js_url ) . '" as="script">';
 
-			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui',
-				'\\0' . $embed_script, $buffer, 1 );
+			$buffer = preg_replace(
+				'~<head(\s+[^>]*)*>~Ui',
+				'\\0' . $embed_script,
+				$buffer,
+				1
+			);
 
-			// load lazyload in footer to make sure DOM is ready at the moment of initialization
+			// load lazyload in footer to make sure DOM is ready at the moment of initialization.
 			$footer_script =
 				'<script>' .
 					$on_initialized_javascript_wrapped .
@@ -170,10 +237,15 @@ private function embed_script( $buffer ) {
 					'window.lazyLoadOptions=' . $config .
 				'</script>' .
 				'<script async src="' . esc_url( $js_url ) . '"></script>';
-			$buffer = preg_replace( '~</body(\s+[^>]*)*>~Ui',
-				$footer_script . '\\0', $buffer, 1 );
 
-		} elseif ( $method == 'inline_footer' ) {
+			$buffer = preg_replace(
+				'~</body(\s+[^>]*)*>~Ui',
+				$footer_script . '\\0',
+				$buffer,
+				1
+			);
+
+		} elseif ( 'inline_footer' === $method ) {
 			$footer_script =
 				'<style>img.lazy{min-height:1px}</style>' .
 				'<script>' .
@@ -181,49 +253,85 @@ private function embed_script( $buffer ) {
 				'window.w3tc_lazyload=new LazyLoad(' . $config . ');' .
 				$on_initialized_javascript .
 				'</script>';
-			$buffer = preg_replace( '~</body(\s+[^>]*)*>~Ui',
-				$footer_script . '\\0', $buffer, 1 );
-		} else {   // 'sync_head'
+
+			$buffer = preg_replace(
+				'~</body(\s+[^>]*)*>~Ui',
+				$footer_script . '\\0',
+				$buffer,
+				1
+			);
+		} else { // 'sync_head'
 			$head_script =
 				'<style>img.lazy{min-height:1px}</style>' .
 				'<script src="' . esc_url( $js_url ) . '"></script>';
-			$buffer = preg_replace( '~<head(\s+[^>]*)*>~Ui',
-				'\\0' . $head_script, $buffer, 1 );
+
+			$buffer = preg_replace(
+				'~<head(\s+[^>]*)*>~Ui',
+				'\\0' . $head_script,
+				$buffer,
+				1
+			);
 
 			$footer_script =
 				'<script>' .
 					'window.w3tc_lazyload=new LazyLoad(' . $config . ');' .
 					$on_initialized_javascript .
 				'</script>';
-			$buffer = preg_replace( '~</body(\s+[^>]*)*>~Ui',
-				$footer_script . '\\0', $buffer, 1 );
+
+			$buffer = preg_replace(
+				'~</body(\s+[^>]*)*>~Ui',
+				$footer_script . '\\0',
+				$buffer,
+				1
+			);
 		}
 
 		return $buffer;
 	}
 
-
-
+	/**
+	 * Maps attachment URLs to their corresponding post IDs.
+	 *
+	 * Updates the internal posts-by-URL mapping for tracking purposes.
+	 *
+	 * @param string $url     The attachment URL.
+	 * @param int    $post_id The post ID.
+	 *
+	 * @return string The unmodified attachment URL.
+	 */
 	public function wp_get_attachment_url( $url, $post_id ) {
-		$this->posts_by_url[$url] = $post_id;
+		$this->posts_by_url[ $url ] = $post_id;
 		return $url;
 	}
 
-
-
+	/**
+	 * Adds hooks specific to MetaSlider plugin compatibility.
+	 *
+	 * Modifies MetaSlider content to work seamlessly with lazy loading.
+	 *
+	 * @return void
+	 */
 	private function metaslider_hooks() {
-		add_filter( 'metaslider_nivo_slider_get_html',
-			array( $this, 'metaslider_nivo_slider_get_html' ) );
+		add_filter( 'metaslider_nivo_slider_get_html', array( $this, 'metaslider_nivo_slider_get_html' ) );
 	}
 
-
-
+	/**
+	 * Filters MetaSlider HTML output for compatibility.
+	 *
+	 * Prevents lazy loading from interfering with MetaSlider's image loading
+	 * by adding a `no-lazy` class to images.
+	 *
+	 * @param string $content The MetaSlider HTML content.
+	 *
+	 * @return string Modified HTML content.
+	 */
 	public function metaslider_nivo_slider_get_html( $content ) {
 		// nivo slider use "src" attr of <img> tags to populate
-		// own image via JS, i.e. cant be replaced by lazyloading
+		// own image via JS, i.e. cant be replaced by lazyloading.
 		$content = preg_replace(
 			'~(\s+)(class=)([\"\'])(.*?)([\"\'])~',
-			'$1$2$3$4 no-lazy$5', $content
+			'$1$2$3$4 no-lazy$5',
+			$content
 		);
 
 		return $content;
diff --git a/UserExperience_OEmbed_Extension.php b/UserExperience_OEmbed_Extension.php
index 93d55dcba..e7ef30c28 100644
--- a/UserExperience_OEmbed_Extension.php
+++ b/UserExperience_OEmbed_Extension.php
@@ -1,19 +1,39 @@
 <?php
+/**
+ * File: UserExperience_OEmbed_Extension.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_OEmbed_Extension
+ */
 class UserExperience_OEmbed_Extension {
+	/**
+	 * Runs the initialization process for the extension.
+	 *
+	 * Adds the necessary WordPress hooks to modify the oEmbed behavior.
+	 *
+	 * @return void
+	 */
 	public function run() {
 		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
 	}
 
-
-
+	/**
+	 * Modifies the footer of the WordPress page.
+	 *
+	 * Deregisters the 'wp-embed' script to prevent WordPress from enqueueing
+	 * its default embed script, reducing unnecessary resources being loaded.
+	 *
+	 * @return void
+	 */
 	public function wp_footer() {
 		wp_deregister_script( 'wp-embed' );
 	}
 }
 
-
-
 $o = new UserExperience_OEmbed_Extension();
 $o->run();
diff --git a/UserExperience_Page.php b/UserExperience_Page.php
index 128f9035f..4197e114a 100644
--- a/UserExperience_Page.php
+++ b/UserExperience_Page.php
@@ -1,9 +1,26 @@
 <?php
+/**
+ * File: UserExperience_Page.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
+/**
+ * Class UserExperience_Page
+ */
 class UserExperience_Page {
+	/**
+	 * Renders the content of the User Experience page.
+	 *
+	 * This method retrieves configuration data using the Dispatcher class and includes
+	 * the corresponding view file for rendering the User Experience page content.
+	 *
+	 * @return void
+	 */
 	public function render_content() {
 		$c = Dispatcher::config();
-		include  W3TC_DIR . '/UserExperience_Page_View.php';
+		include W3TC_DIR . '/UserExperience_Page_View.php';
 	}
 }
diff --git a/UserExperience_Page_View.php b/UserExperience_Page_View.php
index 794034e4b..7414705af 100644
--- a/UserExperience_Page_View.php
+++ b/UserExperience_Page_View.php
@@ -1,15 +1,22 @@
 <?php
+/**
+ * File: UserExperience_Page_View.php
+ *
+ * @package W3TC
+ */
+
 namespace W3TC;
 
-if ( !defined( 'W3TC' ) )
+if ( ! defined( 'W3TC' ) ) {
 	die();
+}
 
 ?>
 <p>
 	Lazy loading is currently
-	<?php if ( $c->get_boolean( 'lazyload.enabled' ) ): ?>
+	<?php if ( $c->get_boolean( 'lazyload.enabled' ) ) : ?>
 		<span class="w3tc-enabled">enabled</span>.
-	<?php else: ?>
+	<?php else : ?>
 		<span class="w3tc-disabled">disabled</span>.
 	<?php endif ?>
 <p>
@@ -18,7 +25,7 @@
 	<?php Util_UI::print_control_bar( 'pagecache_form_control' ); ?>
 	<div class="metabox-holder">
 		<?php /* decouple it when too much */ ?>
-		<?php include  W3TC_DIR . '/UserExperience_LazyLoad_Page_View.php' ?>
-		<?php do_action( 'w3tc_userexperience_page' ) ?>
+		<?php require W3TC_DIR . '/UserExperience_LazyLoad_Page_View.php'; ?>
+		<?php do_action( 'w3tc_userexperience_page' ); ?>
 	</div>
 </form>
diff --git a/UserExperience_Plugin_Admin.php b/UserExperience_Plugin_Admin.php
index 5bbc1e858..5c2a13cc4 100644
--- a/UserExperience_Plugin_Admin.php
+++ b/UserExperience_Plugin_Admin.php
@@ -8,11 +8,14 @@
 namespace W3TC;
 
 /**
- * UserExperience Plugin Admin.
+ * Class UserExperience_Plugin_Admin
  */
 class UserExperience_Plugin_Admin {
 	/**
-	 * Runs the user experience feature.
+	 * Initializes the admin hooks for the User Experience plugin.
+	 *
+	 * This method registers WordPress filters and actions necessary for the
+	 * integration of the User Experience plugin into the W3 Total Cache admin area.
 	 *
 	 * @return void
 	 */
@@ -24,11 +27,13 @@ public function run() {
 	}
 
 	/**
-	 * Set user experience admin menu item.
+	 * Adds a custom menu entry for the User Experience plugin.
+	 *
+	 * This method adds a "User Experience" menu item to the W3 Total Cache admin menu.
 	 *
-	 * @param array $menu Menu array.
+	 * @param array $menu The existing admin menu items.
 	 *
-	 * @return array
+	 * @return array The modified admin menu items, including the User Experience menu.
 	 */
 	public function w3tc_admin_menu( $menu ) {
 		$menu['w3tc_userexperience'] = array(
@@ -42,12 +47,15 @@ public function w3tc_admin_menu( $menu ) {
 	}
 
 	/**
-	 * Configures extensions for user experience.
+	 * Registers User Experience-related extensions for W3 Total Cache.
 	 *
-	 * @param array  $extensions Extensions array.
-	 * @param object $config     Config object.
+	 * This method adds several custom extensions to W3 Total Cache that handle specific
+	 * User Experience features like deferring scripts, preloading requests, and more.
 	 *
-	 * @return array
+	 * @param array  $extensions The existing W3TC extensions.
+	 * @param object $config     The W3TC configuration object.
+	 *
+	 * @return array The modified W3TC extensions array with added User Experience extensions.
 	 */
 	public static function w3tc_extensions( $extensions, $config ) {
 		$extensions['user-experience-defer-scripts']    = array(
@@ -80,7 +88,10 @@ public static function w3tc_extensions( $extensions, $config ) {
 	}
 
 	/**
-	 * Render user experience advanced settings page.
+	 * Renders the settings page for the User Experience plugin.
+	 *
+	 * This method initializes and displays the settings page content for the
+	 * User Experience plugin in the W3 Total Cache admin area.
 	 *
 	 * @return void
 	 */
diff --git a/UserExperience_Plugin_Jquery.php b/UserExperience_Plugin_Jquery.php
index 67891c3e7..99ffd646f 100644
--- a/UserExperience_Plugin_Jquery.php
+++ b/UserExperience_Plugin_Jquery.php
@@ -12,6 +12,8 @@
 /**
  * Class: UserExperience_Plugin_Jquery
  *
+ * phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
+ *
  * @since 0.14.4
  */
 class UserExperience_Plugin_Jquery {
diff --git a/UserExperience_Preload_Requests_Extension.php b/UserExperience_Preload_Requests_Extension.php
index d2a891f3a..94aba9d5e 100644
--- a/UserExperience_Preload_Requests_Extension.php
+++ b/UserExperience_Preload_Requests_Extension.php
@@ -85,8 +85,8 @@ public function w3tc_userexperience_page() {
 	 */
 	public function w3tc_config_key_descriptor( $descriptor, $key ) {
 		if (
-			is_array( $key )
-			&& in_array(
+			is_array( $key ) &&
+			in_array(
 				implode( '.', $key ),
 				array(
 					'user-experience-preload-requests.dns-prefetch',
@@ -98,7 +98,8 @@ public function w3tc_config_key_descriptor( $descriptor, $key ) {
 					'user-experience-preload-requests.preload-videos',
 					'user-experience-preload-requests.preload-audio',
 					'user-experience-preload-requests.preload-documents',
-				)
+				),
+				true
 			)
 		) {
 			$descriptor = array( 'type' => 'array' );
diff --git a/Util_Debug.php b/Util_Debug.php
index cfa1ac3de..a99357957 100644
--- a/Util_Debug.php
+++ b/Util_Debug.php
@@ -190,7 +190,7 @@ private static function encode_params( $args ) {
 			$args_strings[] = $s;
 		} else {
 			foreach ( $args as $arg ) {
-				$s = json_encode( $arg, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
+				$s = wp_json_encode( $arg, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
 				if ( strlen( $s ) > 100 ) {
 					$s = substr( $s, 0, 98 ) . '..';
 				}
diff --git a/composer.lock b/composer.lock
index 9b44bf22a..82f023efa 100644
--- a/composer.lock
+++ b/composer.lock
@@ -2919,5 +2919,5 @@
     "prefer-lowest": false,
     "platform": [],
     "platform-dev": [],
-    "plugin-api-version": "2.6.0"
+    "plugin-api-version": "2.3.0"
 }
diff --git a/wp-content/db.php b/wp-content/db.php
index eb927b9b3..d9f84b22f 100644
--- a/wp-content/db.php
+++ b/wp-content/db.php
@@ -1,6 +1,13 @@
 <?php
 /**
- * W3 Total Cache Database module
+ * File: db.php
+ *
+ * W3 Total Cache Database module.
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
+ * phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
+ *
+ * @package W3TC
  */
 
 if ( ! defined( 'ABSPATH' ) ) {