diff --git a/inc/Addon/Cloudflare/Subscriber.php b/inc/Addon/Cloudflare/Subscriber.php index 099d90c306..5ea9de2fc2 100644 --- a/inc/Addon/Cloudflare/Subscriber.php +++ b/inc/Addon/Cloudflare/Subscriber.php @@ -415,7 +415,7 @@ private function save_cloudflare_auto_settings( $auto_settings, $old_settings ) $result = []; // Set Cache Level to Aggressive. - $cf_cache_level = isset( $cf_old_settings[0] ) && 0 === $auto_settings ? $cf_old_settings[0] : 'aggressive'; + $cf_cache_level = 0 === $auto_settings ? $cf_old_settings[0] : 'aggressive'; $result[] = $this->save_cache_level( $cf_cache_level ); // Deactivate Rocket Loader to prevent conflicts. diff --git a/inc/Addon/WebP/Subscriber.php b/inc/Addon/WebP/Subscriber.php index 6fed28f9e4..8951d6fa7c 100644 --- a/inc/Addon/WebP/Subscriber.php +++ b/inc/Addon/WebP/Subscriber.php @@ -38,7 +38,7 @@ class Subscriber extends AbstractWebp implements Subscriber_Interface { /** * \WP_Filesystem_Direct instance. * - * @var \WP_Filesystem_Direct + * @var null|\WP_Filesystem_Direct */ private $filesystem; @@ -58,11 +58,11 @@ public function __construct( Options_Data $options_data, Options $options_api, C $this->options_data = $options_data; $this->options_api = $options_api; - if ( ! isset( $server ) && ! empty( $_SERVER ) && is_array( $_SERVER ) ) { + if ( ! isset( $server ) && ! empty( $_SERVER ) ) { $server = $_SERVER; } - $this->server = $server && is_array( $server ) ? $server : []; + $this->server = $server ?: []; } /** @@ -202,8 +202,8 @@ public function sync_webp_cache_with_third_party_plugins() { * @param array $requests Requests to make. * @return array */ - public function add_accept_header( $requests ) { - if ( ! is_array( $requests ) || ! $this->options_data->get( 'cache_webp', 0 ) ) { + public function add_accept_header( array $requests ) { + if ( ! $this->options_data->get( 'cache_webp', 0 ) ) { return $requests; } @@ -214,7 +214,7 @@ function ( $request ) { return $request; }, $requests - ); + ); } /** diff --git a/inc/Dependencies/Database/Base.php b/inc/Dependencies/Database/Base.php index 20fcdb52d9..1e28f2323c 100644 --- a/inc/Dependencies/Database/Base.php +++ b/inc/Dependencies/Database/Base.php @@ -281,7 +281,7 @@ protected function set_vars( $args = array() ) { * * @since 1.0.0 * - * @return \wpdb Database interface, or False if not set + * @return \wpdb|false Database interface, or False if not set */ protected function get_db() { diff --git a/inc/Engine/Admin/Beacon/Beacon.php b/inc/Engine/Admin/Beacon/Beacon.php index 7873a4cfdc..bef646541b 100644 --- a/inc/Engine/Admin/Beacon/Beacon.php +++ b/inc/Engine/Admin/Beacon/Beacon.php @@ -111,7 +111,7 @@ public function insert_script() { * @return string */ private function get_user_locale() { - if ( ! isset( $this->locale ) ) { + if ( empty( $this->locale ) ) { $this->locale = current( array_slice( explode( '_', get_user_locale() ), 0, 1 ) ); } @@ -122,7 +122,7 @@ private function get_user_locale() { * * @param string $locale The locale ID. */ - return apply_filters( 'rocket_beacon_locale', $this->locale ); + return wpm_apply_filters_typed( 'string', 'rocket_beacon_locale', $this->locale ); } /** diff --git a/inc/Engine/Admin/Database/Optimization.php b/inc/Engine/Admin/Database/Optimization.php index 367ad7c7e6..f3bc436a51 100644 --- a/inc/Engine/Admin/Database/Optimization.php +++ b/inc/Engine/Admin/Database/Optimization.php @@ -56,7 +56,7 @@ public function get_options() { * @param array $options WP Rocket Database options. */ public function process_handler( $options ) { - if ( method_exists( $this->process, 'cancel_process' ) ) { + if ( method_exists( $this->process, 'cancel_process' ) ) { // @phpstan-ignore-line $this->process->cancel_process(); } diff --git a/inc/Engine/Admin/Metaboxes/PostEditOptionsSubscriber.php b/inc/Engine/Admin/Metaboxes/PostEditOptionsSubscriber.php index ab096d8ba7..1924c171d2 100644 --- a/inc/Engine/Admin/Metaboxes/PostEditOptionsSubscriber.php +++ b/inc/Engine/Admin/Metaboxes/PostEditOptionsSubscriber.php @@ -104,11 +104,7 @@ public function display_metabox() { * * @param string[] $original_fields Metaboxes fields. */ - $fields = apply_filters( 'rocket_meta_boxes_fields', $original_fields ); - - if ( ! is_array( $fields ) ) { - $fields = $original_fields; - } + $fields = wpm_apply_filters_typed( 'array', 'rocket_meta_boxes_fields', $original_fields ); $fields_attributes = []; @@ -179,11 +175,7 @@ public function save_metabox_options() { * * @param string[] $original_fields Metaboxes fields. */ - $fields = apply_filters( 'rocket_meta_boxes_fields', $original_fields ); - - if ( ! is_array( $fields ) ) { - $fields = $original_fields; - } + $fields = wpm_apply_filters_typed( 'array', 'rocket_meta_boxes_fields', $original_fields ); $fields = array_keys( $fields ); diff --git a/inc/Engine/Admin/Settings/Page.php b/inc/Engine/Admin/Settings/Page.php index e9a3643f51..ac5eb3f473 100644 --- a/inc/Engine/Admin/Settings/Page.php +++ b/inc/Engine/Admin/Settings/Page.php @@ -1172,7 +1172,7 @@ private function advanced_cache_section() { $ecommerce_plugin = _x( 'iThemes Exchange', 'plugin name', 'rocket' ); } elseif ( defined( 'JIGOSHOP_VERSION' ) && function_exists( 'jigoshop_get_page_id' ) ) { $ecommerce_plugin = _x( 'Jigoshop', 'plugin name', 'rocket' ); - } elseif ( defined( 'WPSHOP_VERSION' ) && class_exists( 'wpshop_tools' ) && method_exists( 'wpshop_tools', 'get_page_id' ) ) { + } elseif ( defined( 'WPSHOP_VERSION' ) && class_exists( 'wpshop_tools' ) && method_exists( 'wpshop_tools', 'get_page_id' ) ) { // @phpstan-ignore-line $ecommerce_plugin = _x( 'WP-Shop', 'plugin name', 'rocket' ); } @@ -1519,11 +1519,7 @@ private function cdn_section() { * * @param array $addons Array of addons. */ - $addons = apply_filters( 'rocket_cdn_helper_addons', [] ); - - if ( ! is_array( $addons ) ) { - $addons = []; - } + $addons = wpm_apply_filters_typed( 'array', 'rocket_cdn_helper_addons', [] ); $addons = array_unique( $addons ); @@ -2107,8 +2103,8 @@ private function hidden_fields() { * @param string $tag_name Name of the HTML tag that will wrap each element of the list. * @return array */ - private function sanitize_and_format_list( $list, $tag_name = 'strong' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.listFound - if ( ! is_array( $list ) || empty( $list ) ) { + private function sanitize_and_format_list( array $list, $tag_name = 'strong' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.listFound + if ( empty( $list ) ) { return []; } @@ -2180,7 +2176,7 @@ public function enable_mobile_cache(): void { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error(); - return; + return; // @phpstan-ignore-line } $this->options->set( 'cache_mobile', 1 ); diff --git a/inc/Engine/Admin/Settings/Render.php b/inc/Engine/Admin/Settings/Render.php index 79c33a3eeb..7650b99ac0 100644 --- a/inc/Engine/Admin/Settings/Render.php +++ b/inc/Engine/Admin/Settings/Render.php @@ -106,10 +106,6 @@ function ( array $item ) use ( $default ) { * @since 3.0 */ public function render_form_sections() { - if ( ! isset( $this->settings ) ) { - return; - } - foreach ( $this->settings as $id => $args ) { $default = [ 'title' => '', diff --git a/inc/Engine/Admin/Settings/Settings.php b/inc/Engine/Admin/Settings/Settings.php index 225411bd97..012a2eb641 100644 --- a/inc/Engine/Admin/Settings/Settings.php +++ b/inc/Engine/Admin/Settings/Settings.php @@ -333,7 +333,9 @@ public function sanitize_callback( $input ) { $input['automatic_cleanup_frequency'] = isset( $input['automatic_cleanup_frequency'], $cleanup_frequencies[ $input['automatic_cleanup_frequency'] ] ) ? $input['automatic_cleanup_frequency'] : $this->options->get( 'automatic_cleanup_frequency' ); - if ( 1 !== $input['schedule_automatic_cleanup'] && ( 'daily' !== $input['automatic_cleanup_frequency'] || 'weekly' !== $input['automatic_cleanup_frequency'] || 'monthly' !== $input['automatic_cleanup_frequency'] ) ) { + $allowed_frequencies = [ 'daily', 'weekly', 'monthly' ]; + + if ( 1 !== $input['schedule_automatic_cleanup'] && ! in_array( $input['automatic_cleanup_frequency'], $allowed_frequencies, true ) ) { $input['automatic_cleanup_frequency'] = $this->options->get( 'automatic_cleanup_frequency' ); } @@ -554,11 +556,7 @@ private function sanitize_fonts( $files ) { * @param string $file URL or path to a font file. * @return string|bool */ - private function sanitize_font( $file ) { - if ( ! is_string( $file ) ) { - return false; - } - + private function sanitize_font( string $file ) { $file = trim( $file ); if ( empty( $file ) ) { @@ -604,10 +602,6 @@ private function sanitize_font( $file ) { * @return array */ private function get_hosts() { - if ( isset( $this->hosts ) ) { - return $this->hosts; - } - $urls = (array) $this->options->get( 'cdn_cnames', [] ); $urls[] = home_url(); $urls = array_map( 'rocket_add_url_protocol', $urls ); diff --git a/inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php b/inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php index df0239178a..610cf77883 100644 --- a/inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php +++ b/inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php @@ -63,30 +63,22 @@ public function update_user_token() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error( 'unauthorized_user' ); - - return; } if ( empty( $_POST['value'] ) ) { delete_option( 'rocketcdn_user_token' ); wp_send_json_success( 'user_token_deleted' ); - - return; } if ( ! is_string( $_POST['value'] ) ) { wp_send_json_error( 'invalid_token' ); - - return; } $token = sanitize_key( $_POST['value'] ); if ( 40 !== strlen( $token ) ) { wp_send_json_error( 'invalid_token_length' ); - - return; } update_option( 'rocketcdn_user_token', $token ); @@ -112,16 +104,12 @@ public function enable() { $data['message'] = 'unauthorized_user'; wp_send_json_error( $data ); - - return; } if ( empty( $_POST['cdn_url'] ) ) { $data['message'] = 'cdn_url_empty'; wp_send_json_error( $data ); - - return; } $cdn_url = filter_var( wp_unslash( $_POST['cdn_url'] ), FILTER_VALIDATE_URL ); @@ -130,8 +118,6 @@ public function enable() { $data['message'] = 'cdn_url_invalid_format'; wp_send_json_error( $data ); - - return; } $this->cdn_options->enable( esc_url_raw( $cdn_url ) ); @@ -164,8 +150,6 @@ public function disable() { $data['message'] = 'unauthorized_user'; wp_send_json_error( $data ); - - return; } $this->cdn_options->disable(); @@ -234,14 +218,10 @@ public function get_process_status() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error(); - - return; } if ( get_option( 'rocketcdn_process' ) ) { wp_send_json_success(); - - return; } wp_send_json_error(); @@ -285,13 +265,11 @@ public function validate_token_cname() { if ( ! current_user_can( 'rocket_manage_options' ) ) { $data['message'] = 'unauthorized_user'; wp_send_json_error( $data ); - return; } if ( empty( $_POST['cdn_url'] ) || empty( $_POST['cdn_token'] ) ) { $data['message'] = 'cdn_values_empty'; wp_send_json_error( $data ); - return; } $token = sanitize_key( $_POST['cdn_token'] ); @@ -300,13 +278,11 @@ public function validate_token_cname() { if ( ! $cdn_url ) { $data['message'] = 'cdn_url_invalid_format'; wp_send_json_error( $data ); - return; } if ( 40 !== strlen( $token ) ) { $data['message'] = 'invalid_token_length'; wp_send_json_error( $data ); - return; } $current_token = get_option( 'rocketcdn_user_token' ); @@ -315,7 +291,6 @@ public function validate_token_cname() { if ( ! empty( $current_token ) ) { $data['message'] = 'token_already_set'; wp_send_json_error( $data ); - return; } update_option( 'rocketcdn_user_token', $token ); diff --git a/inc/Engine/CDN/RocketCDN/NoticesSubscriber.php b/inc/Engine/CDN/RocketCDN/NoticesSubscriber.php index 6dd6231853..a09a968a59 100644 --- a/inc/Engine/CDN/RocketCDN/NoticesSubscriber.php +++ b/inc/Engine/CDN/RocketCDN/NoticesSubscriber.php @@ -167,8 +167,6 @@ public function dismiss_notice() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error( 'no permissions' ); - - return; } update_user_meta( get_current_user_id(), 'rocketcdn_dismiss_notice', true ); @@ -284,14 +282,10 @@ public function toggle_cta() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error( 'no permissions' ); - - return; } if ( ! isset( $_POST['status'] ) ) { wp_send_json_error( 'missing status' ); - - return; } if ( 'big' === $_POST['status'] ) { diff --git a/inc/Engine/Cache/Purge.php b/inc/Engine/Cache/Purge.php index 3ca1d89c2b..cdd91dbee6 100644 --- a/inc/Engine/Cache/Purge.php +++ b/inc/Engine/Cache/Purge.php @@ -57,11 +57,7 @@ public function purge_dates_archives( $post ) { * @param boolean $pagination Purge also pagination. * @return void */ - public function purge_url( $url, $pagination = false ) { - if ( ! is_string( $url ) ) { - return; - } - + public function purge_url( string $url, $pagination = false ) { global $wp_rewrite; $parsed_url = $this->parse_url( $url ); diff --git a/inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php b/inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php index 620b8494d8..e4bb1cc8b8 100644 --- a/inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php +++ b/inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php @@ -23,7 +23,7 @@ class PurgeExpiredCache { * * @since 3.4 * - * @var \WP_Filesystem_Direct + * @var null|\WP_Filesystem_Direct */ private $filesystem; @@ -60,7 +60,7 @@ public function purge_expired_files( $lifespan ) { * @param array $urls URLs that will be searched for old cache files. * @param int $file_age_limit Timestamp of the maximum age files must have. */ - $urls = apply_filters( 'rocket_automatic_cache_purge_urls', $urls, $file_age_limit ); + $urls = wpm_apply_filters_typed( 'array', 'rocket_automatic_cache_purge_urls', $urls, $file_age_limit ); if ( ! is_array( $urls ) ) { // I saw what you did ಠ_ಠ. @@ -380,8 +380,8 @@ private function is_dir_empty( $dir_path ) { * * @since 3.8 * - * @param int $old_lifespan Old value in minutes. - * @param int $old_lifespan_unit Old value of unit. + * @param int $old_lifespan Old value in minutes. + * @param string $old_lifespan_unit Old value of unit. * * @return void */ diff --git a/inc/Engine/Common/Database/Queries/AbstractQuery.php b/inc/Engine/Common/Database/Queries/AbstractQuery.php index ec652ea0da..c7dfa3a273 100644 --- a/inc/Engine/Common/Database/Queries/AbstractQuery.php +++ b/inc/Engine/Common/Database/Queries/AbstractQuery.php @@ -45,7 +45,7 @@ public function get_row( string $url, bool $is_mobile = false ) { * * @param int $row_id DB Row ID. * - * @return array|false + * @return object|array|false false if no row found, array or object if row found. */ public function get_row_by_id( int $row_id ) { if ( ! self::$table_exists && ! $this->table_exists() ) { diff --git a/inc/Engine/Common/JobManager/APIHandler/AbstractSafeAPIClient.php b/inc/Engine/Common/JobManager/APIHandler/AbstractSafeAPIClient.php index 38ea96f087..71b9c0271d 100644 --- a/inc/Engine/Common/JobManager/APIHandler/AbstractSafeAPIClient.php +++ b/inc/Engine/Common/JobManager/APIHandler/AbstractSafeAPIClient.php @@ -80,7 +80,7 @@ private function send_request( $method, $params = [], $safe = false ) { } $body = wp_remote_retrieve_body( $response ); - if ( empty( $body ) || ( is_array( $response ) && ! empty( $response['response']['code'] ) && 200 !== $response['response']['code'] ) ) { + if ( empty( $body ) || ( ! empty( $response['response']['code'] ) && 200 !== $response['response']['code'] ) ) { $this->set_timeout_transients( $previous_expiration ); return new WP_Error( 500, __( 'Not valid response.', 'rocket' ) ); } diff --git a/inc/Engine/Common/JobManager/JobProcessor.php b/inc/Engine/Common/JobManager/JobProcessor.php index a6e4a8fa7f..87fc294103 100644 --- a/inc/Engine/Common/JobManager/JobProcessor.php +++ b/inc/Engine/Common/JobManager/JobProcessor.php @@ -524,7 +524,7 @@ private function get_common_jobs( array $rows ): array { list($occurrences, $duplicates) = [ [], [] ]; foreach ( $rows as $row ) { - $key = $row->url . '|' . ( (bool) $row->is_mobile ?? 'null' ); + $key = $row->url . '|' . ( isset( $row->is_mobile ) ? (bool) $row->is_mobile : 'null' ); if ( ! isset( $occurrences[ $key ] ) ) { $occurrences[ $key ] = 1; diff --git a/inc/Engine/Common/Queue/Cleaner.php b/inc/Engine/Common/Queue/Cleaner.php index dde6dcc586..124257c9ca 100644 --- a/inc/Engine/Common/Queue/Cleaner.php +++ b/inc/Engine/Common/Queue/Cleaner.php @@ -113,7 +113,7 @@ public function delete_old_actions() { */ public function clean_actions( array $statuses_to_purge, \DateTime $cutoff_date, $batch_size = null, $context = 'old' ) { $batch_size = null !== $batch_size ? $batch_size : $this->batch_size; - $cutoff = null !== $cutoff_date ? $cutoff_date : as_get_datetime_object( $this->hour_in_seconds . ' seconds ago' ); + $cutoff = $cutoff_date; $lifespan = time() - $cutoff->getTimestamp(); if ( empty( $statuses_to_purge ) ) { diff --git a/inc/Engine/Common/Queue/RUCSSQueueRunner.php b/inc/Engine/Common/Queue/RUCSSQueueRunner.php index 1a23764c33..b1aad54c51 100644 --- a/inc/Engine/Common/Queue/RUCSSQueueRunner.php +++ b/inc/Engine/Common/Queue/RUCSSQueueRunner.php @@ -46,7 +46,7 @@ class RUCSSQueueRunner extends ActionScheduler_Abstract_QueueRunner { * @return RUCSSQueueRunner Instance. */ public static function instance() { - if ( empty( self::$runner ) ) { + if ( null === self::$runner ) { self::$runner = new RUCSSQueueRunner(); } return self::$runner; diff --git a/inc/Engine/CriticalPath/APIClient.php b/inc/Engine/CriticalPath/APIClient.php index 29d781e019..055f17e7d0 100644 --- a/inc/Engine/CriticalPath/APIClient.php +++ b/inc/Engine/CriticalPath/APIClient.php @@ -104,13 +104,11 @@ private function prepare_response( $response, $url, $is_mobile = false, $item_ty * * @return bool success or failed. */ - private function get_response_success( $response_code, $response_data ) { + private function get_response_success( int $response_code, $response_data ) { return ( 200 === $response_code && ( - $response_data instanceof stdClass - && ! empty( (array) $response_data ) ) && diff --git a/inc/Engine/CriticalPath/Admin/Admin.php b/inc/Engine/CriticalPath/Admin/Admin.php index 214a13458d..1b0aa711d9 100644 --- a/inc/Engine/CriticalPath/Admin/Admin.php +++ b/inc/Engine/CriticalPath/Admin/Admin.php @@ -51,8 +51,6 @@ public function cpcss_heartbeat() { ! current_user_can( 'rocket_regenerate_critical_css' ) ) { wp_send_json_error(); - - return; } $cpcss_pending = get_transient( 'rocket_cpcss_generation_pending' ); @@ -68,8 +66,6 @@ public function cpcss_heartbeat() { if ( empty( $cpcss_pending ) ) { $this->generation_complete(); wp_send_json_success( [ 'status' => 'cpcss_complete' ] ); - - return; } set_transient( 'rocket_cpcss_generation_pending', $cpcss_pending, HOUR_IN_SECONDS ); diff --git a/inc/Engine/CriticalPath/Admin/Settings.php b/inc/Engine/CriticalPath/Admin/Settings.php index 2e33b9db81..6209f6c8d1 100644 --- a/inc/Engine/CriticalPath/Admin/Settings.php +++ b/inc/Engine/CriticalPath/Admin/Settings.php @@ -92,7 +92,6 @@ public function enable_mobile_cpcss() { if ( ! current_user_can( 'rocket_manage_options' ) || ! current_user_can( 'rocket_regenerate_critical_css' ) ) { wp_send_json_error(); - return; } $this->options->set( 'async_css_mobile', 1 ); diff --git a/inc/Engine/CriticalPath/CriticalCSS.php b/inc/Engine/CriticalPath/CriticalCSS.php index 17c4fb2737..0175998ee2 100644 --- a/inc/Engine/CriticalPath/CriticalCSS.php +++ b/inc/Engine/CriticalPath/CriticalCSS.php @@ -133,6 +133,7 @@ public function process_handler( $version = 'default', $clean_version = '' ) { * @since 3.3 */ public function stop_generation() { + // @phpstan-ignore-next-line if ( method_exists( $this->process, 'cancel_process' ) ) { $this->process->cancel_process(); } diff --git a/inc/Engine/CriticalPath/CriticalCSSSubscriber.php b/inc/Engine/CriticalPath/CriticalCSSSubscriber.php index a7b0b48d27..ffba529501 100644 --- a/inc/Engine/CriticalPath/CriticalCSSSubscriber.php +++ b/inc/Engine/CriticalPath/CriticalCSSSubscriber.php @@ -819,7 +819,8 @@ public function switch_to_rucss_notice() { * * @param array $should_disable will return array with disable status and text. */ - $rucss_status = apply_filters( + $rucss_status = wpm_apply_filters_typed( + 'array', 'rocket_disable_rucss_setting', [ 'disable' => false, @@ -827,7 +828,7 @@ public function switch_to_rucss_notice() { ] ); - if ( is_array( $rucss_status ) && key_exists( 'disable', $rucss_status ) && $rucss_status['disable'] ) { + if ( key_exists( 'disable', $rucss_status ) && $rucss_status['disable'] ) { return; } @@ -859,6 +860,7 @@ public function switch_to_rucss() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_safe_redirect( wp_get_referer() ); rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ? wp_die() : exit; + // @phpstan-ignore-next-line return; // phpcs:ignore Squiz.PHP.NonExecutableCode.Unreachable } diff --git a/inc/Engine/CriticalPath/ProcessorService.php b/inc/Engine/CriticalPath/ProcessorService.php index 71fcea37b2..d29cdaf65d 100644 --- a/inc/Engine/CriticalPath/ProcessorService.php +++ b/inc/Engine/CriticalPath/ProcessorService.php @@ -99,27 +99,6 @@ private function send_generation_request( $item_url, $item_path, $is_mobile = fa return $this->check_cpcss_job_status( $generated_job->data->id, $item_path, $item_url, $is_mobile, $item_type ); } - /** - * Get job details by job_id. - * - * @since 3.6 - * - * @param string $job_id ID for the job to get details. - * @param string $item_url URL for item to be used in error messages. - * @param string $item_type Optional. Type for this item if it's custom or specific type. Default: custom. - * - * @return array|mixed|WP_Error - */ - private function get_cpcss_job_details( $job_id, $item_url, $item_type = 'custom' ) { - $job_details = $this->api_client->get_job_details( $job_id, $item_url, $item_type ); - - if ( is_wp_error( $job_details ) ) { - return $job_details; - } - - return $job_details; - } - /** * Check status and process the output for a job. * @@ -156,11 +135,7 @@ private function check_cpcss_job_status( $job_id, $item_path, $item_url, $is_mob } // For successful job status. - if ( - isset( $job_state, $job_details->data->critical_path ) - && - 'complete' === $job_state - ) { + if ( isset( $job_state, $job_details->data->critical_path ) ) { return $this->on_job_success( $item_path, $item_url, $job_details->data->critical_path, $is_mobile, $item_type ); } diff --git a/inc/Engine/License/API/User.php b/inc/Engine/License/API/User.php index 21ef304fbe..14b5094100 100644 --- a/inc/Engine/License/API/User.php +++ b/inc/Engine/License/API/User.php @@ -13,7 +13,7 @@ class User { /** * Instantiate the class * - * @param object $user The user object. + * @param object|false $user The user object. */ public function __construct( $user ) { $this->user = is_object( $user ) ? $user : new \stdClass(); diff --git a/inc/Engine/License/Renewal.php b/inc/Engine/License/Renewal.php index 5b203bb3a5..02fdb8207a 100644 --- a/inc/Engine/License/Renewal.php +++ b/inc/Engine/License/Renewal.php @@ -271,11 +271,7 @@ public function dismiss_renewal_expired_banner() { * @param array $data Localize script data. * @return array */ - public function add_localize_script_data( $data ) { - if ( ! is_array( $data ) ) { - $data = (array) $data; - } - + public function add_localize_script_data( array $data ) { if ( $this->user->is_license_expired() ) { return $data; } @@ -318,7 +314,7 @@ private function get_discount_percent() { $renewals = $this->get_user_renewal_status(); - if ( false === $renewals || ! isset( $prices->prices, $prices->prices->renewal ) ) { + if ( ! isset( $prices->prices, $prices->prices->renewal ) ) { return 0; } @@ -339,10 +335,6 @@ private function get_discount_percent() { private function is_grandfather(): bool { $renewals = $this->get_user_renewal_status(); - if ( ! is_array( $renewals ) ) { - return false; - } - return key_exists( 'is_grandfather', $renewals ) && $renewals['is_grandfather']; } /** @@ -353,10 +345,6 @@ private function is_grandfather(): bool { private function has_grandmother(): bool { $renewals = $this->get_user_renewal_status(); - if ( ! is_array( $renewals ) ) { - return false; - } - return key_exists( 'is_grandmother', $renewals ) && $renewals['is_grandmother']; } @@ -370,10 +358,6 @@ private function has_grandmother(): bool { private function get_price() { $renewals = $this->get_user_renewal_status(); - if ( false === $renewals ) { - return 0; - } - $license = $this->get_license_pricing_data(); if ( @@ -399,7 +383,7 @@ private function get_price() { * * @return array */ - private function get_user_renewal_status() { + private function get_user_renewal_status(): array { $renewals = $this->pricing->get_renewals_data(); if ( ! isset( $renewals->extra_days, $renewals->grandfather_date, $renewals->discount_percent, $renewals->grandmother_date ) ) { diff --git a/inc/Engine/License/Upgrade.php b/inc/Engine/License/Upgrade.php index 4d811f5c54..b90db308ac 100644 --- a/inc/Engine/License/Upgrade.php +++ b/inc/Engine/License/Upgrade.php @@ -166,11 +166,7 @@ public function dismiss_promo_banner() { * @param array $data Localize script data. * @return array */ - public function add_localize_script_data( $data ) { - if ( ! is_array( $data ) ) { - $data = (array) $data; - } - + public function add_localize_script_data( array $data ) { if ( ! $this->can_use_promo() ) { return $data; } diff --git a/inc/Engine/Media/AboveTheFold/AJAX/Controller.php b/inc/Engine/Media/AboveTheFold/AJAX/Controller.php index f401058346..113491b369 100644 --- a/inc/Engine/Media/AboveTheFold/AJAX/Controller.php +++ b/inc/Engine/Media/AboveTheFold/AJAX/Controller.php @@ -126,7 +126,7 @@ public function add_data(): array { 'is_mobile' => $is_mobile, 'status' => $status_code, 'error_message' => $status_message, - 'lcp' => ( is_array( $lcp ) || is_object( $lcp ) ) ? wp_json_encode( $lcp ) : $lcp, + 'lcp' => is_object( $lcp ) ? wp_json_encode( $lcp ) : $lcp, 'viewport' => wp_json_encode( $viewport ), 'last_accessed' => current_time( 'mysql', true ), ]; @@ -313,11 +313,7 @@ private function validate_image_src( string $image_src ): bool { * * @param array $invalid_schemes Array of invalid schemes. */ - $invalid_schemes = apply_filters( 'rocket_atf_invalid_schemes', $this->invalid_schemes ); - - if ( ! is_array( $invalid_schemes ) ) { - $invalid_schemes = $this->invalid_schemes; - } + $invalid_schemes = wpm_apply_filters_typed( 'array', 'rocket_atf_invalid_schemes', $this->invalid_schemes ); $invalid_schemes = implode( '|', $invalid_schemes ); diff --git a/inc/Engine/Media/AboveTheFold/Context/Context.php b/inc/Engine/Media/AboveTheFold/Context/Context.php index edb3a385d4..0090b7ccfe 100644 --- a/inc/Engine/Media/AboveTheFold/Context/Context.php +++ b/inc/Engine/Media/AboveTheFold/Context/Context.php @@ -23,12 +23,6 @@ public function is_allowed( array $data = [] ): bool { * * @param bool $allow True to allow, false otherwise. */ - $is_atf_enabled = apply_filters( 'rocket_above_the_fold_optimization', true ); - - if ( ! is_bool( $is_atf_enabled ) ) { - return true; - } - - return $is_atf_enabled; + return wpm_apply_filters_typed( 'boolean', 'rocket_above_the_fold_optimization', true ); } } diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php index 14e58f811c..e34481d969 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php @@ -237,16 +237,12 @@ function ( $exclusion ) { * @param object $lcp LCP Object. * @return array */ - private function generate_lcp_link_tag_with_sources( $lcp ): array { + private function generate_lcp_link_tag_with_sources( object $lcp ): array { $pairs = [ 'tags' => '', 'sources' => [], ]; - if ( ! $lcp && ! is_object( $lcp ) ) { - return $pairs; - } - $tag = ''; $start_tag = 'can_disable_emoji() ) { return $plugins; } - if ( is_array( $plugins ) ) { - return array_diff( $plugins, [ 'wpemoji' ] ); - } - - return []; + return array_diff( $plugins, [ 'wpemoji' ] ); } /** diff --git a/inc/Engine/Media/Lazyload/CSS/Front/Extractor.php b/inc/Engine/Media/Lazyload/CSS/Front/Extractor.php index 15c1ae8d8b..9a0300e251 100644 --- a/inc/Engine/Media/Lazyload/CSS/Front/Extractor.php +++ b/inc/Engine/Media/Lazyload/CSS/Front/Extractor.php @@ -132,8 +132,10 @@ function ( $matches ) { $block = trim( $block_matches[ $default_index ][ $block_index ] ); } - foreach ( $this->comments_mapping as $id => $comment ) { - $block = str_replace( $id, $comment, $block ); + if ( ! empty( $this->comments_mapping ) ) { + foreach ( $this->comments_mapping as $id => $comment ) { + $block = str_replace( $id, $comment, $block ); + } } foreach ( $urls as $url ) { diff --git a/inc/Engine/Media/Lazyload/CSS/Front/MappingFormatter.php b/inc/Engine/Media/Lazyload/CSS/Front/MappingFormatter.php index 127eb8a32d..61f73d9c55 100644 --- a/inc/Engine/Media/Lazyload/CSS/Front/MappingFormatter.php +++ b/inc/Engine/Media/Lazyload/CSS/Front/MappingFormatter.php @@ -58,11 +58,7 @@ private function get_pseudo_elements_to_remove() { * * @param string[] $original_pseudo_elements Pseudo elements to remove. */ - $pseudo_elements_to_remove = apply_filters( 'rocket_lazyload_css_ignored_pseudo_elements', $original_pseudo_elements ); - - if ( ! is_array( $original_pseudo_elements ) ) { - $pseudo_elements_to_remove = $original_pseudo_elements; - } + $pseudo_elements_to_remove = wpm_apply_filters_typed( 'array', 'rocket_lazyload_css_ignored_pseudo_elements', $original_pseudo_elements ); usort( $pseudo_elements_to_remove, @@ -117,10 +113,6 @@ protected function remove_pseudo_classes( string $selector ): string { $selector = implode( ',', $selectors ); - if ( ! $selector ) { - return 'body'; - } - return (string) $selector; } } diff --git a/inc/Engine/Media/Lazyload/CSS/Subscriber.php b/inc/Engine/Media/Lazyload/CSS/Subscriber.php index 0075f0d941..0a33ec5350 100644 --- a/inc/Engine/Media/Lazyload/CSS/Subscriber.php +++ b/inc/Engine/Media/Lazyload/CSS/Subscriber.php @@ -176,14 +176,15 @@ public function maybe_replace_css_images( string $html ): string { * * @param array $data Data passed to generate the lazyload CSS. */ - $output = apply_filters( + $output = wpm_apply_filters_typed( + 'array', 'rocket_generate_lazyloaded_css', [ 'html' => $html, ] - ); + ); - if ( ! is_array( $output ) || ! key_exists( 'html', $output ) ) { + if ( ! key_exists( 'html', $output ) ) { $this->logger::debug( 'Lazyload bailed out', $this->generate_log_context( @@ -537,11 +538,7 @@ protected function is_excluded( string $string ) { // phpcs:ignore Universal.Nam * * @param array $excluded_src An array of excluded src. */ - $excluded_values = apply_filters( 'rocket_lazyload_excluded_src', [] ); - - if ( ! is_array( $excluded_values ) ) { - $excluded_values = (array) $excluded_values; - } + $excluded_values = wpm_apply_filters_typed( 'array', 'rocket_lazyload_excluded_src', [] ); $excluded_values = array_filter( $excluded_values ); @@ -583,11 +580,7 @@ public function exclude_rocket_lazyload_excluded_src( $excluded, $urls ) { * * @param array $excluded_src An array of excluded src. */ - $excluded_values = apply_filters( 'rocket_lazyload_excluded_src', [] ); - - if ( ! is_array( $excluded_values ) ) { - $excluded_values = (array) $excluded_values; - } + $excluded_values = wpm_apply_filters_typed( 'array', 'rocket_lazyload_excluded_src', [] ); $excluded_values = array_filter( $excluded_values ); diff --git a/inc/Engine/Media/Lazyload/Subscriber.php b/inc/Engine/Media/Lazyload/Subscriber.php index 50ddd59197..2b35cfe5bc 100644 --- a/inc/Engine/Media/Lazyload/Subscriber.php +++ b/inc/Engine/Media/Lazyload/Subscriber.php @@ -245,9 +245,9 @@ public function insert_youtube_thumbnail_script() { * @param string $extension extension from the thumbnail from Youtube video. * @returns string */ - $extension = apply_filters( 'rocket_lazyload_youtube_thumbnail_extension', 'jpg' ); + $extension = wpm_apply_filters_typed( 'string', 'rocket_lazyload_youtube_thumbnail_extension', 'jpg' ); - if ( ! is_string( $extension ) || ! in_array( $extension, [ 'jpg', 'webp' ], true ) ) { + if ( ! in_array( $extension, [ 'jpg', 'webp' ], true ) ) { $extension = 'jpg'; } @@ -456,11 +456,7 @@ public function maybe_disable_core_lazyload( $value, $tag_name ) { * @param array $exclusions Array of excluded patterns. * @return array */ - public function add_exclusions( $exclusions ): array { - if ( ! is_array( $exclusions ) ) { - $exclusions = []; - } - + public function add_exclusions( array $exclusions = [] ): array { $exclude_lazyload = $this->options->get( 'exclude_lazyload', [] ); if ( empty( $exclude_lazyload ) ) { diff --git a/inc/Engine/Optimization/AssetsLocalCache.php b/inc/Engine/Optimization/AssetsLocalCache.php index 7cc1701319..f41531345d 100644 --- a/inc/Engine/Optimization/AssetsLocalCache.php +++ b/inc/Engine/Optimization/AssetsLocalCache.php @@ -149,10 +149,6 @@ private function has_integrity( $asset ) { return false; } - if ( ! isset( $integrity_matches['integrityhashmethod'], $integrity_matches['integrityhash'] ) ) { - return false; - } - return $integrity_matches; } diff --git a/inc/Engine/Optimization/DeferJS/DeferJS.php b/inc/Engine/Optimization/DeferJS/DeferJS.php index d9cd542a08..70f27fe0cc 100644 --- a/inc/Engine/Optimization/DeferJS/DeferJS.php +++ b/inc/Engine/Optimization/DeferJS/DeferJS.php @@ -277,6 +277,7 @@ private function get_inline_exclusions_list_pattern() { $inline_exclusions = ''; // Check if filter return is string so convert it to array for backward compatibility. + // @phpstan-ignore-next-line - Ignoring the safeguard as the result could be mixed. if ( is_string( $additional_inline_exclusions_list ) ) { $additional_inline_exclusions_list = explode( '|', $additional_inline_exclusions_list ); } diff --git a/inc/Engine/Optimization/DelayJS/ServiceProvider.php b/inc/Engine/Optimization/DelayJS/ServiceProvider.php index ee9576f73c..fb39c7a2c7 100644 --- a/inc/Engine/Optimization/DelayJS/ServiceProvider.php +++ b/inc/Engine/Optimization/DelayJS/ServiceProvider.php @@ -58,7 +58,6 @@ public function register(): void { ->addArgument( new Logger() ); $this->getContainer()->addShared( 'delay_js_subscriber', Subscriber::class ) ->addArgument( $this->getContainer()->get( 'delay_js_html' ) ) - ->addArgument( rocket_direct_filesystem() ) - ->addArgument( $this->getContainer()->get( 'options' ) ); + ->addArgument( rocket_direct_filesystem() ); } } diff --git a/inc/Engine/Optimization/DelayJS/Subscriber.php b/inc/Engine/Optimization/DelayJS/Subscriber.php index d48f80bd5b..2f6d68a52d 100644 --- a/inc/Engine/Optimization/DelayJS/Subscriber.php +++ b/inc/Engine/Optimization/DelayJS/Subscriber.php @@ -26,33 +26,15 @@ class Subscriber implements Subscriber_Interface { */ private $filesystem; - /** - * Options Data instance - * - * @var Options_Data - */ - private $options; - - /** - * Script enqueued status. - * - * @since 3.7 - * - * @var bool - */ - private $is_enqueued = false; - /** * Subscriber constructor. * * @param HTML $html HTML Instance. * @param \WP_Filesystem_Direct $filesystem The Filesystem object. - * @param Options_Data $options Options data instance. */ - public function __construct( HTML $html, $filesystem, Options_Data $options ) { + public function __construct( HTML $html, $filesystem ) { $this->html = $html; $this->filesystem = $filesystem; - $this->options = $options; } /** diff --git a/inc/Engine/Optimization/DynamicLists/Subscriber.php b/inc/Engine/Optimization/DynamicLists/Subscriber.php index afb9425a1e..33f088d98f 100644 --- a/inc/Engine/Optimization/DynamicLists/Subscriber.php +++ b/inc/Engine/Optimization/DynamicLists/Subscriber.php @@ -109,11 +109,7 @@ public function display_update_lists_section() { * * @return array */ - public function add_cache_ignored_parameters( $params = [] ): array { - if ( ! is_array( $params ) ) { - $params = (array) $params; - } - + public function add_cache_ignored_parameters( array $params = [] ): array { return array_merge( $params, $this->dynamic_lists->get_cache_ignored_parameters() ); } @@ -124,11 +120,7 @@ public function add_cache_ignored_parameters( $params = [] ): array { * * @return array */ - public function add_minify_excluded_external_js( $excluded = [] ): array { - if ( ! is_array( $excluded ) ) { - $excluded = (array) $excluded; - } - + public function add_minify_excluded_external_js( array $excluded = [] ): array { return array_merge( $excluded, $this->dynamic_lists->get_js_minify_excluded_external() ); } @@ -139,11 +131,7 @@ public function add_minify_excluded_external_js( $excluded = [] ): array { * * @return array */ - public function add_move_after_combine_js( $excluded = [] ): array { - if ( ! is_array( $excluded ) ) { - $excluded = (array) $excluded; - } - + public function add_move_after_combine_js( array $excluded = [] ): array { return array_merge( $excluded, $this->dynamic_lists->get_js_move_after_combine() ); } @@ -154,10 +142,7 @@ public function add_move_after_combine_js( $excluded = [] ): array { * * @return array */ - public function add_combine_js_excluded_inline( $excluded = [] ): array { - if ( ! is_array( $excluded ) ) { - $excluded = (array) $excluded; - } + public function add_combine_js_excluded_inline( array $excluded = [] ): array { return array_merge( $excluded, $this->dynamic_lists->get_combine_js_excluded_inline() ); } @@ -169,11 +154,7 @@ public function add_combine_js_excluded_inline( $excluded = [] ): array { * * @return array */ - public function add_preload_exclusions( $excluded = [] ): array { - if ( ! is_array( $excluded ) ) { - $excluded = (array) $excluded; - } - + public function add_preload_exclusions( array $excluded = [] ): array { return array_merge( $excluded, $this->dynamic_lists->get_preload_exclusions() ); } @@ -184,11 +165,7 @@ public function add_preload_exclusions( $excluded = [] ): array { * * @return array */ - public function add_js_exclude_files( $js_files = [] ): array { - if ( ! is_array( $js_files ) ) { - $js_files = (array) $js_files; - } - + public function add_js_exclude_files( array $js_files = [] ): array { return array_merge( $js_files, $this->dynamic_lists->get_js_exclude_files() ); } diff --git a/inc/Engine/Optimization/GoogleFonts/AbstractGFOptimization.php b/inc/Engine/Optimization/GoogleFonts/AbstractGFOptimization.php index 519355ff45..e3b112402b 100644 --- a/inc/Engine/Optimization/GoogleFonts/AbstractGFOptimization.php +++ b/inc/Engine/Optimization/GoogleFonts/AbstractGFOptimization.php @@ -96,11 +96,7 @@ protected function get_font_display_value(): string { * * @param string $display Display value. Can be either auto, block, swap, fallback or optional. */ - $display = apply_filters( 'rocket_combined_google_fonts_display', 'swap' ); - - if ( ! is_string( $display ) ) { - return 'swap'; - } + $display = wpm_apply_filters_typed( 'string', 'rocket_combined_google_fonts_display', 'swap' ); return isset( $this->display_values[ $display ] ) ? $display : 'swap'; } diff --git a/inc/Engine/Optimization/GoogleFonts/Admin/Settings.php b/inc/Engine/Optimization/GoogleFonts/Admin/Settings.php index 2d765a8f0c..0414c864ba 100644 --- a/inc/Engine/Optimization/GoogleFonts/Admin/Settings.php +++ b/inc/Engine/Optimization/GoogleFonts/Admin/Settings.php @@ -74,7 +74,6 @@ public function enable_google_fonts() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error(); - return; } $this->options->set( 'minify_google_fonts', 1 ); diff --git a/inc/Engine/Optimization/IEConditionalSubscriber.php b/inc/Engine/Optimization/IEConditionalSubscriber.php index 55f2bf7b96..d7a0b0ee6c 100644 --- a/inc/Engine/Optimization/IEConditionalSubscriber.php +++ b/inc/Engine/Optimization/IEConditionalSubscriber.php @@ -67,7 +67,7 @@ public static function get_subscribed_events() { public function extract_ie_conditionals( $html ) { preg_match_all( self::IE_PATTERN, $html, $conditionals_match ); - if ( ! $conditionals_match ) { + if ( count( $conditionals_match[0] ) === 0 ) { return $html; } diff --git a/inc/Engine/Optimization/LazyRenderContent/AJAX/Controller.php b/inc/Engine/Optimization/LazyRenderContent/AJAX/Controller.php index 5039086d9c..fad069ea23 100644 --- a/inc/Engine/Optimization/LazyRenderContent/AJAX/Controller.php +++ b/inc/Engine/Optimization/LazyRenderContent/AJAX/Controller.php @@ -91,7 +91,7 @@ public function add_data(): array { 'is_mobile' => $is_mobile, 'status' => $status_code, 'error_message' => $status_message, - 'below_the_fold' => ( is_array( $below_the_fold ) || is_object( $below_the_fold ) ) ? wp_json_encode( $below_the_fold ) : $below_the_fold, + 'below_the_fold' => wp_json_encode( $below_the_fold ), 'last_accessed' => current_time( 'mysql', true ), 'created_at' => current_time( 'mysql', true ), ]; diff --git a/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php b/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php index 8cfdb64be3..d4e29e6485 100755 --- a/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php +++ b/inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php @@ -34,11 +34,7 @@ public static function get_subscribed_events() { * * @return void */ - public function clean_minify( $old, $new ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound - if ( ! is_array( $old ) || ! is_array( $new ) ) { - return; - } - + public function clean_minify( array $old, array $new ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound if ( ! $this->maybe_minify_regenerate( $new, $old ) ) { return; } @@ -52,15 +48,12 @@ public function clean_minify( $old, $new ) { // phpcs:ignore Universal.NamingCon * @since 3.5.4 * * @param array $new An array of submitted settings. - * @param array $old An array of previous settings. + * @param mixed $old An array of previous settings or false. * * @return array Updates 'minify_css_key' setting when regenerated; else, original submitted settings. */ - public function regenerate_minify_css_key( $new, $old ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound - if ( ! is_array( $old ) || ! is_array( $new ) ) { - return $new; - } - + public function regenerate_minify_css_key( array $new, $old ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound + $old = is_array( $old ) ? $old : []; if ( ! $this->maybe_minify_regenerate( $new, $old ) ) { return $new; } diff --git a/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php b/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php index f610af3876..08814e970a 100644 --- a/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php +++ b/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php @@ -441,7 +441,6 @@ public function spawn_cron() { if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error(); - return; } spawn_cron(); diff --git a/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php b/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php index 9fbf26d9e0..8cbb154ffd 100644 --- a/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php +++ b/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php @@ -475,10 +475,7 @@ private function add_used_fonts_preload( string $html, string $used_css ): strin * * @param array $excluded_fonts_preload List of fonts to exclude from preload */ - $exclude_fonts_preload = apply_filters( 'rocket_exclude_rucss_fonts_preload', [] ); - if ( ! is_array( $exclude_fonts_preload ) ) { - $exclude_fonts_preload = []; - } + $exclude_fonts_preload = wpm_apply_filters_typed( 'array', 'rocket_exclude_rucss_fonts_preload', [] ); $urls = []; diff --git a/inc/Engine/Optimization/RUCSS/Jobs/Manager.php b/inc/Engine/Optimization/RUCSS/Jobs/Manager.php index f17d9e8823..f0c9cd382e 100644 --- a/inc/Engine/Optimization/RUCSS/Jobs/Manager.php +++ b/inc/Engine/Optimization/RUCSS/Jobs/Manager.php @@ -120,10 +120,7 @@ public function validate_and_fail( array $job_details, $row_details, string $opt * * @param int $min_rucss_size min size. */ - $min_rucss_size = apply_filters( 'rocket_min_rucss_size', 150 ); - if ( ! is_numeric( $min_rucss_size ) ) { - $min_rucss_size = 150; - } + $min_rucss_size = wpm_apply_filters_typed( 'integer', 'rocket_min_rucss_size', 150 ); if ( isset( $job_details['contents']['shakedCSS_size'] ) && intval( $job_details['contents']['shakedCSS_size'] ) < $min_rucss_size ) { $message = 'RUCSS: shakedCSS size is less than ' . $min_rucss_size; @@ -194,8 +191,7 @@ public function set_request_param(): array { * * @param array $skipped_attr Array of safelist values. */ - $skipped_attr = apply_filters( 'rocket_rucss_skip_styles_with_attr', [] ); - $skipped_attr = ( is_array( $skipped_attr ) ) ? $skipped_attr : []; + $skipped_attr = wpm_apply_filters_typed( 'array', 'rocket_rucss_skip_styles_with_attr', [] ); return [ 'rucss_safelist' => $safelist, diff --git a/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php b/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php index 461a80e70b..7b32d418ef 100644 --- a/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php +++ b/inc/Engine/Plugin/UpdaterApiCommonSubscriber.php @@ -81,11 +81,7 @@ public static function get_subscribed_events() { * @param string $url Requested URL. * @return array An array of requested arguments */ - public function maybe_set_rocket_user_agent( $request, $url ) { - if ( ! is_string( $url ) ) { - return $request; - } - + public function maybe_set_rocket_user_agent( $request, string $url ) { if ( strpos( $url, self::API_HOST ) !== false ) { $request['user-agent'] = sprintf( '%s;%s', $request['user-agent'], $this->get_rocket_user_agent() ); } @@ -116,16 +112,12 @@ protected function get_current_option( $field_name ) { if ( current_user_can( 'rocket_manage_options' ) && wp_verify_nonce( filter_input( INPUT_POST, '_wpnonce' ), $this->settings_nonce_key . '-options' ) ) { $posted = filter_input( INPUT_POST, $this->settings_slug, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); - if ( ! empty( $posted[ $field_name ] ) && is_string( $posted[ $field_name ] ) ) { + if ( ! empty( $posted[ $field_name ] ) ) { // The value has been posted through the settings page. return sanitize_text_field( $posted[ $field_name ] ); } } - if ( ! $this->plugin_options ) { - return ''; - } - $option_value = $this->plugin_options->get( $field_name ); if ( $option_value && is_string( $option_value ) ) { diff --git a/inc/Engine/Plugin/UpdaterSubscriber.php b/inc/Engine/Plugin/UpdaterSubscriber.php index 2cb844ec03..5e9c39da51 100644 --- a/inc/Engine/Plugin/UpdaterSubscriber.php +++ b/inc/Engine/Plugin/UpdaterSubscriber.php @@ -132,11 +132,7 @@ public static function get_subscribed_events() { * @param string $url The request URL. * @return array Updated array of HTTP request arguments. */ - public function exclude_rocket_from_wp_updates( $request, $url ) { - if ( ! is_string( $url ) ) { - return $request; - } - + public function exclude_rocket_from_wp_updates( $request, string $url ) { if ( ! preg_match( '@^https?://api.wordpress.org/plugins/update-check(/|\?|$)@', $url ) || empty( $request['body']['plugins'] ) ) { // Not a plugin update request. Stop immediately. return $request; @@ -204,7 +200,7 @@ public function exclude_rocket_from_wp_updates( $request, $url ) { /** * Add WPR update data to the "WP update" transient. * - * @param \stdClass $transient_value New value of site transient. + * @param \stdClass|array $transient_value New value of site transient. * @return \stdClass */ public function maybe_add_rocket_update_data( $transient_value ) { diff --git a/inc/Engine/Preload/Controller/CheckExcludedTrait.php b/inc/Engine/Preload/Controller/CheckExcludedTrait.php index 6cffb45d85..59f4b6161d 100644 --- a/inc/Engine/Preload/Controller/CheckExcludedTrait.php +++ b/inc/Engine/Preload/Controller/CheckExcludedTrait.php @@ -67,7 +67,7 @@ protected function is_excluded_by_filter( string $url ): bool { $regexes = array_unique( $regexes ); foreach ( $regexes as $regex ) { - if ( ! is_string( $regex ) ) { + if ( ! is_string( $regex ) ) { // @phpstan-ignore-line continue; } diff --git a/inc/Engine/Preload/Controller/LoadInitialSitemap.php b/inc/Engine/Preload/Controller/LoadInitialSitemap.php index 9d116c13c7..f244f68e3f 100755 --- a/inc/Engine/Preload/Controller/LoadInitialSitemap.php +++ b/inc/Engine/Preload/Controller/LoadInitialSitemap.php @@ -150,10 +150,6 @@ protected function load_wordpress_sitemap() { $sitemaps = wp_sitemaps_get_server(); - if ( ! $sitemaps ) { - return false; - } - return $sitemaps->index->get_index_url(); } diff --git a/inc/Engine/Preload/Controller/PreloadUrl.php b/inc/Engine/Preload/Controller/PreloadUrl.php index 909bc00131..4a8905e103 100755 --- a/inc/Engine/Preload/Controller/PreloadUrl.php +++ b/inc/Engine/Preload/Controller/PreloadUrl.php @@ -101,11 +101,7 @@ public function preload_url( string $url ) { * * @param array $requests Requests that will be done. */ - $requests = apply_filters( 'rocket_preload_before_preload_url', $requests ); - - if ( ! is_array( $requests ) ) { - return; - } + $requests = wpm_apply_filters_typed( 'array', 'rocket_preload_before_preload_url', $requests ); $requests = array_filter( $requests ); @@ -135,15 +131,12 @@ public function preload_url( string $url ) { * * @param array $headers Request arguments. */ - $headers = apply_filters( + $headers = wpm_apply_filters_typed( + 'array', 'rocket_preload_url_request_args', $headers ); - if ( ! is_array( $headers ) ) { - return; - } - if ( $check_duration ) { $start = microtime( true ); } @@ -203,9 +196,9 @@ protected function get_mobile_user_agent_prefix() { * * @param string $prefix The prefix. */ - $new_prefix = apply_filters( 'rocket_mobile_preload_user_agent_prefix', $prefix ); + $new_prefix = wpm_apply_filters_typed( 'string', 'rocket_mobile_preload_user_agent_prefix', $prefix ); - if ( empty( $new_prefix ) || ! is_string( $new_prefix ) ) { + if ( empty( $new_prefix ) ) { return $prefix; } diff --git a/inc/Engine/Preload/Fonts.php b/inc/Engine/Preload/Fonts.php index 9a20f12275..891d9a958e 100644 --- a/inc/Engine/Preload/Fonts.php +++ b/inc/Engine/Preload/Fonts.php @@ -125,11 +125,7 @@ public function preload_fonts( $html ): string { * @param string $file Filepath to sanitize. * @return string|bool Sanitized filepath. False if not a font file. */ - private function sanitize_font( $file ) { - if ( ! is_string( $file ) ) { - return false; - } - + private function sanitize_font( string $file ) { $file = trim( $file ); if ( empty( $file ) ) { diff --git a/inc/Engine/Preload/Links/Subscriber.php b/inc/Engine/Preload/Links/Subscriber.php index 63e3bd1462..c93001f624 100644 --- a/inc/Engine/Preload/Links/Subscriber.php +++ b/inc/Engine/Preload/Links/Subscriber.php @@ -154,11 +154,7 @@ private function get_preload_links_config() { * * @param array $config Preload Links script configuration parameters. */ - $filtered_config = apply_filters( 'rocket_preload_links_config', $config ); - - if ( ! is_array( $filtered_config ) ) { - return $config; - } + $filtered_config = wpm_apply_filters_typed( 'array', 'rocket_preload_links_config', $config ); return array_merge( $config, $filtered_config ); } @@ -194,11 +190,7 @@ private function get_uris_to_exclude( $use_trailing_slash ) { * @param string[] $excluded Array of excluded patterns. * @param string[] $default Array of default excluded patterns. */ - $excluded = apply_filters( 'rocket_preload_links_exclusions', $excluded, $default ); - - if ( ! is_array( $excluded ) ) { - $excluded = (array) $excluded; - } + $excluded = wpm_apply_filters_typed( 'array', 'rocket_preload_links_exclusions', $excluded, $default ); $excluded = array_filter( $excluded ); diff --git a/inc/Engine/Preload/Subscriber.php b/inc/Engine/Preload/Subscriber.php index 59cfd02404..2c70cecac4 100644 --- a/inc/Engine/Preload/Subscriber.php +++ b/inc/Engine/Preload/Subscriber.php @@ -502,49 +502,6 @@ public function remove_private_post( string $new_status, string $old_status, $po $this->delete_post_preload_cache( $post->ID ); } - /** - * Get all private urls for public post types. - * - * @return array - */ - private function get_all_private_urls() { - static $private_urls; - - if ( rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ) { - $private_urls = null; - } - - if ( isset( $private_urls ) ) { - return $private_urls; - } - - $private_urls = []; - - $public_post_types = get_post_types( [ 'public' => true ] ); - unset( $public_post_types['attachment'] ); - - $arg = [ - 'post_type' => $public_post_types, - 'post_status' => 'private', - 'posts_per_page' => -1, - ]; - $query = new \WP_Query( $arg ); - - if ( ! $query->have_posts() ) { - return []; - } - - foreach ( $query->posts as $post ) { - // Temporarily cast publish status to get pretty url. - $post->post_status = 'publish'; - $private_post_url = get_permalink( $post ); - - $private_urls[ md5( $private_post_url ) ] = $private_post_url; - } - - return $private_urls; - } - /** * Exclude private urls. * diff --git a/inc/Engine/Saas/Admin/Notices.php b/inc/Engine/Saas/Admin/Notices.php index bb2dd9f925..a8c454f1f9 100644 --- a/inc/Engine/Saas/Admin/Notices.php +++ b/inc/Engine/Saas/Admin/Notices.php @@ -189,11 +189,7 @@ public function display_success_notice() { * * @return array */ - public function add_localize_script_data( $data ): array { - if ( ! is_array( $data ) ) { - $data = (array) $data; - } - + public function add_localize_script_data( array $data ): array { if ( ! $this->options->get( 'remove_unused_css', 0 ) ) { return $data; } diff --git a/inc/ThirdParty/Hostings/Cloudways.php b/inc/ThirdParty/Hostings/Cloudways.php index 6831531210..e896c2fea0 100644 --- a/inc/ThirdParty/Hostings/Cloudways.php +++ b/inc/ThirdParty/Hostings/Cloudways.php @@ -99,13 +99,14 @@ public function varnish_addon_title( array $settings ) { * * @since 3.5.5 * - * @param array $varnish_ip Varnish IP. + * @param mixed $varnish_ip Varnish IP. * @return array */ public function varnish_ip( $varnish_ip ) { if ( ! self::is_varnish_running() ) { return $varnish_ip; } + if ( ! is_array( $varnish_ip ) ) { $varnish_ip = (array) $varnish_ip; } diff --git a/inc/ThirdParty/Hostings/Godaddy.php b/inc/ThirdParty/Hostings/Godaddy.php index e4601b57b3..dc5cb932b3 100644 --- a/inc/ThirdParty/Hostings/Godaddy.php +++ b/inc/ThirdParty/Hostings/Godaddy.php @@ -22,7 +22,7 @@ class Godaddy implements Subscriber_Interface { * @param string $vip_url Godaddy vip url. */ public function __construct( $vip_url = '' ) { - $this->vip_url = method_exists( '\WPaas\Plugin', 'vip' ) ? \WPaas\Plugin::vip() : $vip_url; + $this->vip_url = method_exists( '\WPaas\Plugin', 'vip' ) ? \WPaas\Plugin::vip() : $vip_url; // @phpstan-ignore-line } /** diff --git a/inc/ThirdParty/Hostings/Pressidium.php b/inc/ThirdParty/Hostings/Pressidium.php index b7587050ba..c5b0e8a738 100644 --- a/inc/ThirdParty/Hostings/Pressidium.php +++ b/inc/ThirdParty/Hostings/Pressidium.php @@ -82,7 +82,7 @@ public function clean_pressidium() { * Returns the path of URLs. * * @param array|string $urls Urls we want to get paths. - * @return array|void the path. + * @return array the path. */ private function get_paths( $urls ) { if ( ! is_array( $urls ) ) { diff --git a/inc/ThirdParty/Hostings/WPEngine.php b/inc/ThirdParty/Hostings/WPEngine.php index fd195f46f5..f5e156206d 100644 --- a/inc/ThirdParty/Hostings/WPEngine.php +++ b/inc/ThirdParty/Hostings/WPEngine.php @@ -56,11 +56,11 @@ public function varnish_addon_title( $settings ) { * @since 3.6.1 */ public function clean_wpengine() { - if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) { + if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) { // @phpstan-ignore-line WpeCommon::purge_memcached(); } - if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) { + if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) { // @phpstan-ignore-line WpeCommon::purge_varnish_cache(); } } diff --git a/inc/ThirdParty/Hostings/WPXCloud.php b/inc/ThirdParty/Hostings/WPXCloud.php index 0b6b431b8d..e963cfd69d 100644 --- a/inc/ThirdParty/Hostings/WPXCloud.php +++ b/inc/ThirdParty/Hostings/WPXCloud.php @@ -13,7 +13,7 @@ class WPXCloud extends AbstractNoCacheHost { * * @return array */ - public static function get_subscribed_events() { + public static function get_subscribed_events(): array { return [ 'rocket_varnish_ip' => 'varnish_ip', 'rocket_display_input_varnish_auto_purge' => 'return_false', @@ -26,10 +26,10 @@ public static function get_subscribed_events() { /** * Adds WPX Cloud Varnish IP to varnish IPs array * - * @param array $varnish_ip Varnish IP. + * @param mixed $varnish_ip Varnish IP. * @return array */ - public function varnish_ip( $varnish_ip ) { + public function varnish_ip( $varnish_ip ): array { if ( ! is_array( $varnish_ip ) ) { $varnish_ip = (array) $varnish_ip; } @@ -45,7 +45,7 @@ public function varnish_ip( $varnish_ip ) { * @param array $settings Array of settings for Varnish. * @return array */ - public function varnish_addon_title( array $settings ) { + public function varnish_addon_title( array $settings ): array { $settings['varnish_auto_purge']['title'] = sprintf( // Translators: %s = Hosting name. __( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ), @@ -73,7 +73,7 @@ public function append_cache_control_header(): string { * * @return void */ - public function activate() { + public function activate(): void { parent::activate(); add_action( 'rocket_activation', [ $this, 'append_cache_control_header_on_activation' ] ); @@ -84,7 +84,7 @@ public function activate() { * * @return void */ - public function append_cache_control_header_on_activation() { + public function append_cache_control_header_on_activation(): void { add_filter( 'after_rocket_htaccess_rules', [ $this, 'append_cache_control_header' ] ); } } diff --git a/inc/ThirdParty/Plugins/CDN/CloudflareFacade.php b/inc/ThirdParty/Plugins/CDN/CloudflareFacade.php index 517fb634c1..150ab511f7 100644 --- a/inc/ThirdParty/Plugins/CDN/CloudflareFacade.php +++ b/inc/ThirdParty/Plugins/CDN/CloudflareFacade.php @@ -9,9 +9,9 @@ class CloudflareFacade { /** * Hooks class instance * - * @var Hooks + * @var null|Hooks */ - private $hooks; + private $hooks = null; /** * Instantiate the hooks class diff --git a/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php b/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php index ec7a6d3b5f..b94f294928 100644 --- a/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php +++ b/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php @@ -388,7 +388,7 @@ public function cache_empty_cart() { * @since 3.1 * @author Remy Perona * - * @return string + * @return mixed */ private function get_cache_empty_cart() { $lang = rocket_get_current_language(); @@ -549,13 +549,9 @@ public function show_empty_product_gallery_with_delayJS() { * * @return array */ - public function show_notempty_product_gallery_with_delayJS( $exclusions = [] ): array { + public function show_notempty_product_gallery_with_delayJS( array $exclusions = [] ): array { global $wp_version; - if ( ! is_array( $exclusions ) ) { - $exclusions = (array) $exclusions; - } - if ( ! $this->delayjs_html->is_allowed() ) { return $exclusions; } diff --git a/inc/ThirdParty/Plugins/I18n/TranslatePress.php b/inc/ThirdParty/Plugins/I18n/TranslatePress.php index e55cc3b52a..ff56aa7412 100644 --- a/inc/ThirdParty/Plugins/I18n/TranslatePress.php +++ b/inc/ThirdParty/Plugins/I18n/TranslatePress.php @@ -121,11 +121,7 @@ public function set_current_language( $current_language ) { * * @return array */ - public function get_active_languages_uri( $urls ) { - if ( ! is_array( $urls ) ) { - $urls = (array) $urls; - } - + public function get_active_languages_uri( array $urls ): array { $home_url = home_url(); $translatepress = TRP_Translate_Press::get_trp_instance(); @@ -148,12 +144,12 @@ public function get_active_languages_uri( $urls ) { /** * Gets the active languages slugs * - * @param Array $codes Array of languages codes. + * @param array $codes Array of languages codes. * * @return array */ public function get_active_languages_codes( $codes ) { - if ( ! is_array( $codes ) ) { + if ( ! is_array( $codes ) ) { // @phpstan-ignore-line $codes = (array) $codes; } @@ -220,7 +216,7 @@ public function get_home_url_for_lang( $home_url, $lang ) { * @return array */ public function get_translated_post_urls( $urls, $url, $post_type, $regex ) { - if ( ! is_array( $urls ) ) { + if ( ! is_array( $urls ) ) { // @phpstan-ignore-line $urls = (array) $urls; } diff --git a/inc/ThirdParty/Plugins/I18n/WPML.php b/inc/ThirdParty/Plugins/I18n/WPML.php index e54150a457..7a82910e92 100644 --- a/inc/ThirdParty/Plugins/I18n/WPML.php +++ b/inc/ThirdParty/Plugins/I18n/WPML.php @@ -87,7 +87,7 @@ public function is_secondary_home( string $home_url, string $url ): string { * @param string $condition condition used to clean URLS in the database. * @return string */ - public function clean_only_right_domain( $condition ) { + public function clean_only_right_domain( $condition ): string { global $sitepress; $lang = isset( $_GET['lang'] ) && 'all' !== $_GET['lang'] ? sanitize_key( $_GET['lang'] ) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended @@ -106,7 +106,7 @@ public function clean_only_right_domain( $condition ) { * @param array $sitemaps list of sitemaps to be fetched. * @return array */ - public function add_languages_sitemaps( $sitemaps ) { + public function add_languages_sitemaps( $sitemaps ): array { global $sitepress; $new_sitemaps = []; @@ -130,13 +130,13 @@ public function add_languages_sitemaps( $sitemaps ) { * * @return void */ - public function remove_root_cached_files() { + public function remove_root_cached_files(): void { $site_url = home_url(); $host_name = wp_parse_url( $site_url, PHP_URL_HOST ); $cache_folder_path = _rocket_get_wp_rocket_cache_path() . $host_name . '/'; $cache_folder_directory = $this->filesystem->dirlist( $cache_folder_path ); - if ( ! is_array( $cache_folder_directory ) || ! is_array( array_keys( $cache_folder_directory ) ) ) { + if ( ! is_array( $cache_folder_directory ) ) { return; } @@ -156,11 +156,7 @@ public function remove_root_cached_files() { * * @return array */ - public function on_change_directory_for_default_language_clean_cache( $new, $old ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound - if ( ! is_array( $old ) || ! is_array( $new ) ) { - return $new; - } - + public function on_change_directory_for_default_language_clean_cache( array $new, array $old ): array { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound if ( ! key_exists( 'urls', $old ) || ! key_exists( 'directory_for_default_language', $old['urls'] ) || ! key_exists( 'urls', $new ) || ! key_exists( 'directory_for_default_language', $new['urls'] ) || $new['urls']['directory_for_default_language'] === $old['urls']['directory_for_default_language'] ) { return $new; } @@ -179,7 +175,7 @@ public function on_change_directory_for_default_language_clean_cache( $new, $old * * @return void */ - public function maybe_clear_on_disable() { + public function maybe_clear_on_disable(): void { $option = get_option( 'icl_sitepress_settings' ); if ( ! $option || ! is_array( $option ) || ! key_exists( 'urls', $option ) || ! key_exists( 'directory_for_default_language', $option['urls'] ) || false === $option['urls']['directory_for_default_language'] ) { return; diff --git a/inc/ThirdParty/Plugins/Optimization/AMP.php b/inc/ThirdParty/Plugins/Optimization/AMP.php index 2a27e9ae3f..c64ffb32cc 100644 --- a/inc/ThirdParty/Plugins/Optimization/AMP.php +++ b/inc/ThirdParty/Plugins/Optimization/AMP.php @@ -21,21 +21,12 @@ class AMP implements Subscriber_Interface { */ private $cdn_subscriber; - /** - * WP Rocket Options instance - * - * @var Options_Data - */ - private $options; - /** * Constructor * - * @param Options_Data $options WP Rocket Options instance. * @param Subscriber_Interface $cdn_subscriber WP Rocket CDN Subscriber. */ - public function __construct( Options_Data $options, Subscriber_Interface $cdn_subscriber ) { - $this->options = $options; + public function __construct( Subscriber_Interface $cdn_subscriber ) { $this->cdn_subscriber = $cdn_subscriber; } diff --git a/inc/ThirdParty/Plugins/Optimization/Hummingbird.php b/inc/ThirdParty/Plugins/Optimization/Hummingbird.php index a412b5d9e9..92bdfc284a 100644 --- a/inc/ThirdParty/Plugins/Optimization/Hummingbird.php +++ b/inc/ThirdParty/Plugins/Optimization/Hummingbird.php @@ -106,7 +106,7 @@ private function is_utils_available() { return false; } - if ( ! method_exists( 'WP_Hummingbird_Utils', 'get_module' ) ) { + if ( ! method_exists( 'WP_Hummingbird_Utils', 'get_module' ) ) { // @phpstan-ignore-line return false; } @@ -126,7 +126,7 @@ private function is_settings_available() { return false; } - if ( ! method_exists( 'WP_Hummingbird_Settings', 'get_setting' ) ) { + if ( ! method_exists( 'WP_Hummingbird_Settings', 'get_setting' ) ) { // @phpstan-ignore-line return false; } @@ -179,11 +179,11 @@ private function check_gzip() { return false; } - if ( ! method_exists( $gzip, 'is_htaccess_written' ) ) { + if ( ! method_exists( $gzip, 'is_htaccess_written' ) ) { // @phpstan-ignore-line return false; } - if ( ! method_exists( $gzip, 'get_server_type' ) ) { + if ( ! method_exists( $gzip, 'get_server_type' ) ) { // @phpstan-ignore-line return false; } @@ -215,11 +215,11 @@ private function check_browser_caching() { return false; } - if ( ! method_exists( $caching, 'is_htaccess_written' ) ) { + if ( ! method_exists( $caching, 'is_htaccess_written' ) ) { // @phpstan-ignore-line return false; } - if ( ! method_exists( $caching, 'get_server_type' ) ) { + if ( ! method_exists( $caching, 'get_server_type' ) ) { // @phpstan-ignore-line return false; } @@ -251,7 +251,7 @@ private function check_cache() { return false; } - if ( ! method_exists( $cache, 'is_active' ) ) { + if ( ! method_exists( $cache, 'is_active' ) ) { // @phpstan-ignore-line return false; } @@ -285,7 +285,7 @@ private function check_assets() { return false; } - if ( ! method_exists( $minify, 'is_active' ) ) { + if ( ! method_exists( $minify, 'is_active' ) ) { // @phpstan-ignore-line return false; } diff --git a/inc/ThirdParty/Plugins/RevolutionSlider.php b/inc/ThirdParty/Plugins/RevolutionSlider.php index 9a2117f45c..c95015df62 100644 --- a/inc/ThirdParty/Plugins/RevolutionSlider.php +++ b/inc/ThirdParty/Plugins/RevolutionSlider.php @@ -22,7 +22,7 @@ class RevolutionSlider implements Subscriber_Interface { * @inheritDoc */ public static function get_subscribed_events() { - if ( ! defined( 'RS_REVISION' ) || version_compare( RS_REVISION, '6.5.5', '<' ) ) { + if ( ! defined( 'RS_REVISION' ) || version_compare( RS_REVISION, '6.5.5', '<' ) ) { // @phpstan-ignore-line return []; } diff --git a/inc/ThirdParty/Plugins/SEO/Yoast.php b/inc/ThirdParty/Plugins/SEO/Yoast.php index 71dc65949b..b401a488d4 100644 --- a/inc/ThirdParty/Plugins/SEO/Yoast.php +++ b/inc/ThirdParty/Plugins/SEO/Yoast.php @@ -7,21 +7,6 @@ use WP_Rocket\Event_Management\Subscriber_Interface; class Yoast implements Subscriber_Interface { - /** - * Options Data instance - * - * @var Options_Data - */ - private $options; - - /** - * Constructor - * - * @param Options_Data $options Options_Data instance. - */ - public function __construct( Options_Data $options ) { - $this->options = $options; - } /** * Array of events this subscriber listens to @@ -43,11 +28,7 @@ public static function get_subscribed_events() { * * @return array */ - public function add_sitemap( $sitemaps ): array { - if ( ! is_array( $sitemaps ) ) { - $sitemaps = (array) $sitemaps; - } - + public function add_sitemap( array $sitemaps ): array { if ( ! $this->is_sitemap_enabled() ) { return $sitemaps; } diff --git a/inc/ThirdParty/Plugins/Smush.php b/inc/ThirdParty/Plugins/Smush.php index 1652d4c662..d3c3e77a47 100644 --- a/inc/ThirdParty/Plugins/Smush.php +++ b/inc/ThirdParty/Plugins/Smush.php @@ -149,7 +149,7 @@ private function is_smush_lazyload_enabled() { return $enabled; } - if ( ! method_exists( '\Smush\Core\Settings', 'get_instance' ) ) { + if ( ! method_exists( '\Smush\Core\Settings', 'get_instance' ) ) { // @phpstan-ignore-line return $enabled; } diff --git a/inc/ThirdParty/Plugins/ThirstyAffiliates.php b/inc/ThirdParty/Plugins/ThirstyAffiliates.php index 032b1e9cd4..89d5b7d3c8 100644 --- a/inc/ThirdParty/Plugins/ThirstyAffiliates.php +++ b/inc/ThirdParty/Plugins/ThirstyAffiliates.php @@ -28,7 +28,7 @@ public static function get_subscribed_events() { * @return array */ public function exclude_link_prefix( $excluded, $default ): array { - if ( ! is_array( $excluded ) ) { + if ( ! is_array( $excluded ) ) { // @phpstan-ignore-line $excluded = (array) $excluded; } diff --git a/inc/ThirdParty/ServiceProvider.php b/inc/ThirdParty/ServiceProvider.php index c2f617eb3b..25cdc783e6 100644 --- a/inc/ThirdParty/ServiceProvider.php +++ b/inc/ThirdParty/ServiceProvider.php @@ -156,7 +156,7 @@ public function register(): void { ->addShared( 'beaverbuilder_subscriber', BeaverBuilder::class ); $this->getContainer() ->addShared( 'amp_subscriber', AMP::class ) - ->addArgument( $options )->addArgument( $this->getContainer()->get( 'cdn_subscriber' ) ); + ->addArgument( $this->getContainer()->get( 'cdn_subscriber' ) ); $this->getContainer() ->addShared( 'simple_custom_css', SimpleCustomCss::class ) ->addArgument( WP_ROCKET_CACHE_BUSTING_PATH )->addArgument( WP_ROCKET_CACHE_BUSTING_URL ); @@ -182,8 +182,7 @@ public function register(): void { $this->getContainer() ->addShared( 'pwa', PWA::class ); $this->getContainer() - ->addShared( 'yoast_seo', Yoast::class ) - ->addArgument( $options ); + ->addShared( 'yoast_seo', Yoast::class ); $this->getContainer() ->addShared( 'convertplug', ConvertPlug::class ); $this->getContainer() diff --git a/inc/ThirdParty/Themes/Avada.php b/inc/ThirdParty/Themes/Avada.php index 20cf2c45c7..a140e1c246 100644 --- a/inc/ThirdParty/Themes/Avada.php +++ b/inc/ThirdParty/Themes/Avada.php @@ -100,7 +100,7 @@ public function maybe_disable_lazyload( $disable_images_lazyload ) { return $disable_images_lazyload; } - if ( ! empty( $avada_options['lazy_load'] && 'avada' !== $avada_options['lazy_load'] ) ) { + if ( 'avada' !== $avada_options['lazy_load'] ) { return $disable_images_lazyload; } diff --git a/inc/ThirdParty/Themes/ThemeResolver.php b/inc/ThirdParty/Themes/ThemeResolver.php index 2ae28b867e..296dd76409 100644 --- a/inc/ThirdParty/Themes/ThemeResolver.php +++ b/inc/ThirdParty/Themes/ThemeResolver.php @@ -4,13 +4,6 @@ namespace WP_Rocket\ThirdParty\Themes; class ThemeResolver { - /** - * Name of the current theme. - * - * @var string - */ - private static $theme_name = ''; - /** * Array of themes names with compatibility classes * @@ -37,7 +30,7 @@ class ThemeResolver { */ public static function get_current_theme(): string { $theme = wp_get_theme(); - $template = $theme->get_template() ?? ''; + $template = $theme->get_template(); if ( empty( $template ) ) { return ''; @@ -49,8 +42,6 @@ public static function get_current_theme(): string { return ''; } - self::$theme_name = $template; - return $template; } } diff --git a/inc/classes/subscriber/third-party/plugins/Images/Webp/class-imagify-subscriber.php b/inc/classes/subscriber/third-party/plugins/Images/Webp/class-imagify-subscriber.php index f79d590284..b232de0a83 100644 --- a/inc/classes/subscriber/third-party/plugins/Images/Webp/class-imagify-subscriber.php +++ b/inc/classes/subscriber/third-party/plugins/Images/Webp/class-imagify-subscriber.php @@ -373,9 +373,9 @@ public function is_serving_webp_compatible_with_cdn() { * @access public * @author Grégory Viguier * - * @return bool + * @return string */ - public function get_basename() { + public function get_basename(): string { if ( empty( $this->plugin_basename ) ) { $this->plugin_basename = rocket_has_constant( 'IMAGIFY_FILE' ) ? plugin_basename( rocket_get_constant( 'IMAGIFY_FILE' ) ) diff --git a/inc/functions/admin.php b/inc/functions/admin.php index 975e8f7ee8..2971129ffd 100755 --- a/inc/functions/admin.php +++ b/inc/functions/admin.php @@ -270,7 +270,7 @@ function rocket_after_update_array_options( $old_value, $value ) { * @since 2.10 * @author Remy Perona * - * @return true if a mobile plugin in the list is active, false otherwise. + * @return bool true if a mobile plugin in the list is active, false otherwise. **/ function rocket_is_mobile_plugin_active() { return \WP_Rocket\Subscriber\Third_Party\Plugins\Mobile_Subscriber::is_mobile_plugin_active(); diff --git a/inc/functions/posts.php b/inc/functions/posts.php index e3c7a6f4e2..f3c4ed164c 100755 --- a/inc/functions/posts.php +++ b/inc/functions/posts.php @@ -12,7 +12,8 @@ * @param int $id The post ID. * @param string $title The post title. * @param string $name The post name. - * @return string The permalink + * + * @return array */ function get_rocket_sample_permalink( $id, $title = null, $name = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals $post = get_post( $id ); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 612faecfcd..02e47b7399 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,7 @@ includes: - phar://phpstan.phar/conf/bleedingEdge.neon parameters: - level: 3 + level: 4 inferPrivatePropertyTypeFromConstructor: true paths: # Test only the new architecture for now. diff --git a/tests/Fixtures/inc/Engine/CriticalPath/CriticalCSSSubscriber/switchToRucssNotice.php b/tests/Fixtures/inc/Engine/CriticalPath/CriticalCSSSubscriber/switchToRucssNotice.php index 48cc5ee884..1a70c65743 100644 --- a/tests/Fixtures/inc/Engine/CriticalPath/CriticalCSSSubscriber/switchToRucssNotice.php +++ b/tests/Fixtures/inc/Engine/CriticalPath/CriticalCSSSubscriber/switchToRucssNotice.php @@ -29,7 +29,7 @@ 'licence_expiration' => strtotime( 'next year' ), 'date_created' => strtotime( 'last year' ), ] ) ), - 'rucss_status' => false, + 'rucss_status' => [], ], 'expected' => [ 'contains' => true, @@ -67,7 +67,7 @@ 'expected' => [ 'contains' => false, 'content' => $notice, - 'rucss_status' => false, + 'rucss_status' => [], 'user_id' => 42, 'notice' => [ 'status' => 'wpr-warning', @@ -101,7 +101,7 @@ 'expected' => [ 'contains' => false, 'content' => $notice, - 'rucss_status' => false, + 'rucss_status' => [], 'user_id' => 42, 'notice' => [ 'status' => 'wpr-warning', @@ -131,7 +131,7 @@ 'licence_expiration' => strtotime( 'last year' ), 'date_created' => strtotime( 'last year' ), ] ) ), - 'rucss_status' => false, + 'rucss_status' => [], ], 'expected' => [ 'contains' => false, @@ -169,7 +169,7 @@ 'expected' => [ 'contains' => false, 'content' => $notice, - 'rucss_status' => false, + 'rucss_status' => [], 'user_id' => 42, 'notice' => [ 'status' => 'wpr-warning', diff --git a/tests/Fixtures/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php b/tests/Fixtures/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php index d2971b1f5c..42952b113a 100644 --- a/tests/Fixtures/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php +++ b/tests/Fixtures/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php @@ -32,4 +32,3 @@ ], ], ]; - diff --git a/tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/preserveAuthorizationToken.php b/tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/preserveAuthorizationToken.php index 198b228661..99c0454279 100644 --- a/tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/preserveAuthorizationToken.php +++ b/tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/preserveAuthorizationToken.php @@ -17,7 +17,6 @@ class Test_PreserveAuthorizationToken extends TestCase { use ApiTrait; - private $client; protected static $api_credentials_config_file = 'rocketcdn.php'; public static function set_up_before_class() { diff --git a/tests/Integration/inc/Engine/Cache/AdvancedCache/noticePermissions.php b/tests/Integration/inc/Engine/Cache/AdvancedCache/noticePermissions.php index df383042e7..b692865f70 100644 --- a/tests/Integration/inc/Engine/Cache/AdvancedCache/noticePermissions.php +++ b/tests/Integration/inc/Engine/Cache/AdvancedCache/noticePermissions.php @@ -71,9 +71,9 @@ public function testShouldEchoNotice( $config, $expected ) { if ( empty( $expected ) ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - $advanced_cache->notice_permissions(); - - return; +// $advanced_cache->notice_permissions(); +// +// return; } ob_start(); diff --git a/tests/Integration/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php b/tests/Integration/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php index 7a9f20fd31..35830ee254 100644 --- a/tests/Integration/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php +++ b/tests/Integration/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php @@ -44,14 +44,14 @@ public function testUpdateAdvancedCache( $set_filter, $expected ) { public function testShouldNotUpdateWhenMultisiteAndSitesNotZero() { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - $advanced_cache = new AdvancedCache( - $this->filesystem->getUrl( $this->config['vfs_dir'] ), - $this->filesystem - ); - - Functions\when( 'current_filter' )->justReturn( 'rocket_deactivation' ); - - $advanced_cache->update_advanced_cache( 1 ); +// $advanced_cache = new AdvancedCache( +// $this->filesystem->getUrl( $this->config['vfs_dir'] ), +// $this->filesystem +// ); +// +// Functions\when( 'current_filter' )->justReturn( 'rocket_deactivation' ); +// +// $advanced_cache->update_advanced_cache( 1 ); } /** diff --git a/tests/Integration/inc/Engine/Cache/WPCache/noticeWpConfigPermissions.php b/tests/Integration/inc/Engine/Cache/WPCache/noticeWpConfigPermissions.php index 0d44b98579..b550a43dd1 100644 --- a/tests/Integration/inc/Engine/Cache/WPCache/noticeWpConfigPermissions.php +++ b/tests/Integration/inc/Engine/Cache/WPCache/noticeWpConfigPermissions.php @@ -84,9 +84,9 @@ public function testShouldEchoNotice( $config, $expected ) { if ( empty( $expected ) ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - $wp_cache->notice_wp_config_permissions(); - - return; +// $wp_cache->notice_wp_config_permissions(); +// +// return; } ob_start(); diff --git a/tests/Integration/inc/Engine/Cache/WPCache/updateWPCache.php b/tests/Integration/inc/Engine/Cache/WPCache/updateWPCache.php index 2d3daf6148..66f83e62bc 100644 --- a/tests/Integration/inc/Engine/Cache/WPCache/updateWPCache.php +++ b/tests/Integration/inc/Engine/Cache/WPCache/updateWPCache.php @@ -38,10 +38,10 @@ public function testShouldCallSetCacheConstant() { public function testShouldNotUpdateWhenMultisiteAndSitesNotZero() { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - $wp_cache = new WPCache( null ); - - Functions\when( 'current_filter' )->justReturn( 'rocket_deactivation' ); - - $wp_cache->update_wp_cache( 1 ); +// $wp_cache = new WPCache( null ); +// +// Functions\when( 'current_filter' )->justReturn( 'rocket_deactivation' ); +// +// $wp_cache->update_wp_cache( 1 ); } } diff --git a/tests/Integration/inc/Engine/Common/PerformanceHints/Admin/Controller/truncateFromAdmin.php b/tests/Integration/inc/Engine/Common/PerformanceHints/Admin/Controller/truncateFromAdmin.php index fba055a4a9..4844d66e79 100644 --- a/tests/Integration/inc/Engine/Common/PerformanceHints/Admin/Controller/truncateFromAdmin.php +++ b/tests/Integration/inc/Engine/Common/PerformanceHints/Admin/Controller/truncateFromAdmin.php @@ -16,9 +16,6 @@ class Test_TruncateFromAdmin extends TestCase { protected $config; - private $factories; - private $queries; - public static function set_up_before_class() { parent::set_up_before_class(); diff --git a/tests/Integration/inc/Engine/CriticalPath/CriticalCSS/processHandler.php b/tests/Integration/inc/Engine/CriticalPath/CriticalCSS/processHandler.php index 29a47cf748..f597b81812 100644 --- a/tests/Integration/inc/Engine/CriticalPath/CriticalCSS/processHandler.php +++ b/tests/Integration/inc/Engine/CriticalPath/CriticalCSS/processHandler.php @@ -122,8 +122,6 @@ public function testShouldHandleProcess( $config, $expected ) { ); if ( $expected['generated'] ) { - $this->assertStopGeneration( $process ); - $this->prepareSetItems( $config ); } @@ -150,10 +148,6 @@ private function addFilters( $filters ) { } } - private function assertStopGeneration( $process ) { - //$process->shouldReceive( 'cancel_process' )->once()->andReturn( null ); - } - private function prepareSetItems( $config ) { $this->prepareFrontPage( $config ); diff --git a/tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/generateCriticalCssOnActivation.php b/tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/generateCriticalCssOnActivation.php index 4cff2996bb..565162070b 100644 --- a/tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/generateCriticalCssOnActivation.php +++ b/tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/generateCriticalCssOnActivation.php @@ -114,7 +114,7 @@ public function testShouldProcessMultisite( $values, $site_id, $should_generate if ( $should_generate ) { $this->assertEquals( 1, $this->did_filter['do_rocket_critical_css_generation'] ); $value = get_transient( 'rocket_critical_css_generation_process_running' ); - $this->assertSame( [ 'total', 'items' ], array_keys( $value ) ); + $this->assertSame( [ 'total', 'items' ], array_keys( $value ) ); // @phpstan-ignore-line } else { $this->assertEquals( 0, $this->did_filter['do_rocket_critical_css_generation'] ); $this->assertFalse( get_transient( 'rocket_critical_css_generation_process_running' ) ); diff --git a/tests/Integration/inc/Engine/CriticalPath/ProcessorService/processGenerate.php b/tests/Integration/inc/Engine/CriticalPath/ProcessorService/processGenerate.php index 862b0f61d1..c2353714b9 100644 --- a/tests/Integration/inc/Engine/CriticalPath/ProcessorService/processGenerate.php +++ b/tests/Integration/inc/Engine/CriticalPath/ProcessorService/processGenerate.php @@ -17,7 +17,7 @@ class Test_ProcessGenerate extends FilesystemTestCase { protected $path_to_test_data = '/inc/Engine/CriticalPath/ProcessorService/processGenerate.php'; private static $container; - private static $user_id; + private static $user_id; // @phpstan-ignore-line private $api_client; private $processor; diff --git a/tests/Integration/inc/Engine/CriticalPath/RESTWPPost/generate.php b/tests/Integration/inc/Engine/CriticalPath/RESTWPPost/generate.php index 1f568ad1cf..fa3d00bbf8 100644 --- a/tests/Integration/inc/Engine/CriticalPath/RESTWPPost/generate.php +++ b/tests/Integration/inc/Engine/CriticalPath/RESTWPPost/generate.php @@ -13,9 +13,14 @@ */ class Test_Generate extends RESTVfsTestCase { protected $path_to_test_data = '/inc/Engine/CriticalPath/RESTWPPost/generate.php'; + + // @phpstan-ignore-next-line private static $post_id; + // @phpstan-ignore-next-line private $async_css_mobile; + + // @phpstan-ignore-next-line private $do_caching_mobile_files; public static function wpSetUpBeforeClass( $factory ) { @@ -35,115 +40,115 @@ public function tear_down() { protected function doTest( $site_id, $config, $expected ) { $this->markTestSkipped(); - $orig_post_id = isset( $config['post_data']['ID'] ) - ? $config['post_data']['ID'] - : 0; - - if ( isset( $config['post_data'] ) ) { - $config['post_data']['ID'] = self::$post_id; - - $post_id = wp_update_post( $config['post_data'], true ); - } else { - $post_id = 0; - } - - $post_type = isset( $config['post_data']['post_type'] ) - ? $config['post_data']['post_type'] - : 'post'; - - $post_title = isset( $config['post_data']['post_title'] ) - ? $config['post_data']['post_title'] - : ''; - - $post_request_response_code = ! isset( $config['generate_post_request_data']['code'] ) - ? 200 - : $config['generate_post_request_data']['code']; - $post_request_response_body = ! isset( $config['generate_post_request_data']['body'] ) - ? '' - : $config['generate_post_request_data']['body']; - $get_request_response_body = ! isset( $config['generate_get_request_data']['body'] ) - ? '' - : $config['generate_get_request_data']['body']; - $request_timeout = isset( $config['request_timeout'] ) - ? $config['request_timeout'] - : false; - $is_mobile = isset( $config['mobile'] ) - ? $config['mobile'] - : false; - $no_fontface = isset( $config['no_fontface'] ) - ? $config['no_fontface'] - : false; - $async_css_mobile = isset( $config['async_css_mobile'] ) - ? $config['async_css_mobile'] - : 0; - $do_caching_mobile_files = isset( $config['do_caching_mobile_files'] ) - ? $config['do_caching_mobile_files'] - : 0; - - Functions\expect( 'wp_remote_post' ) - ->atMost() - ->times( 1 ) - ->with( - 'https://cpcss.wp-rocket.me/api/job/', - [ - 'body' => [ - 'url' => "http://example.org/?p={$post_id}", - 'mobile' => (int) $is_mobile, - 'nofontface' => $no_fontface, - ], - ] - ) - ->andReturn( 'postRequest' ); - - Functions\expect( 'wp_remote_get' ) - ->atMost() - ->times( 1 ) - ->andReturn( 'getRequest' ); - - Functions\expect( 'wp_remote_retrieve_response_code' ) - ->atMost() - ->times( 1 ) - ->andReturn( $post_request_response_code ); - - Functions\expect( 'wp_remote_retrieve_body' ) - ->ordered() - ->atMost() - ->times( 1 ) - ->with( 'postRequest' ) - ->andReturn( $post_request_response_body ) - ->andAlsoExpectIt() - ->atMost() - ->times( 1 ) - ->with( 'getRequest' ) - ->andReturn( $get_request_response_body ); - - $this->async_css_mobile = $async_css_mobile; - add_filter( 'pre_get_rocket_option_async_css_mobile', [ $this, 'setAsyncCssMobileOption' ] ); - - $this->do_caching_mobile_files = $do_caching_mobile_files; - add_filter( 'pre_get_rocket_option_do_caching_mobile_files', [ $this, 'setDoCachingMobileFilesOption' ] ); - - $file = $this->config['vfs_dir'] . "cache/critical-css/{$site_id}/posts/{$post_type}-{$post_id}" . ( $is_mobile ? '-mobile' : '' ). ".css"; - - $body_param = []; - $body_param['is_mobile'] = $is_mobile; - if ( $request_timeout ) { - $body_param['timeout'] = true; - } - - $expected['message'] = str_replace( $orig_post_id, $post_id, $expected['message'] ); - - $cache_file_path = $this->filesystem->getUrl( "{$this->config['vfs_dir']}cache/wp-rocket/example.org/{$post_title}/index.html" ); - if ( $expected['success'] ) { - $this->assertTrue( $this->filesystem->exists( $cache_file_path ) ); - } - - $this->assertSame( $expected, $this->doRestRequest( 'POST', "/wp-rocket/v1/cpcss/post/{$post_id}", $body_param ) ); - $this->assertSame( $config['cpcss_exists_after'], $this->filesystem->exists( $file ) ); - - if ( $expected['success'] ) { - $this->assertFalse( $this->filesystem->exists( $cache_file_path ) ); - } +// $orig_post_id = isset( $config['post_data']['ID'] ) +// ? $config['post_data']['ID'] +// : 0; +// +// if ( isset( $config['post_data'] ) ) { +// $config['post_data']['ID'] = self::$post_id; +// +// $post_id = wp_update_post( $config['post_data'], true ); +// } else { +// $post_id = 0; +// } +// +// $post_type = isset( $config['post_data']['post_type'] ) +// ? $config['post_data']['post_type'] +// : 'post'; +// +// $post_title = isset( $config['post_data']['post_title'] ) +// ? $config['post_data']['post_title'] +// : ''; +// +// $post_request_response_code = ! isset( $config['generate_post_request_data']['code'] ) +// ? 200 +// : $config['generate_post_request_data']['code']; +// $post_request_response_body = ! isset( $config['generate_post_request_data']['body'] ) +// ? '' +// : $config['generate_post_request_data']['body']; +// $get_request_response_body = ! isset( $config['generate_get_request_data']['body'] ) +// ? '' +// : $config['generate_get_request_data']['body']; +// $request_timeout = isset( $config['request_timeout'] ) +// ? $config['request_timeout'] +// : false; +// $is_mobile = isset( $config['mobile'] ) +// ? $config['mobile'] +// : false; +// $no_fontface = isset( $config['no_fontface'] ) +// ? $config['no_fontface'] +// : false; +// $async_css_mobile = isset( $config['async_css_mobile'] ) +// ? $config['async_css_mobile'] +// : 0; +// $do_caching_mobile_files = isset( $config['do_caching_mobile_files'] ) +// ? $config['do_caching_mobile_files'] +// : 0; +// +// Functions\expect( 'wp_remote_post' ) +// ->atMost() +// ->times( 1 ) +// ->with( +// 'https://cpcss.wp-rocket.me/api/job/', +// [ +// 'body' => [ +// 'url' => "http://example.org/?p={$post_id}", +// 'mobile' => (int) $is_mobile, +// 'nofontface' => $no_fontface, +// ], +// ] +// ) +// ->andReturn( 'postRequest' ); +// +// Functions\expect( 'wp_remote_get' ) +// ->atMost() +// ->times( 1 ) +// ->andReturn( 'getRequest' ); +// +// Functions\expect( 'wp_remote_retrieve_response_code' ) +// ->atMost() +// ->times( 1 ) +// ->andReturn( $post_request_response_code ); +// +// Functions\expect( 'wp_remote_retrieve_body' ) +// ->ordered() +// ->atMost() +// ->times( 1 ) +// ->with( 'postRequest' ) +// ->andReturn( $post_request_response_body ) +// ->andAlsoExpectIt() +// ->atMost() +// ->times( 1 ) +// ->with( 'getRequest' ) +// ->andReturn( $get_request_response_body ); +// +// $this->async_css_mobile = $async_css_mobile; +// add_filter( 'pre_get_rocket_option_async_css_mobile', [ $this, 'setAsyncCssMobileOption' ] ); +// +// $this->do_caching_mobile_files = $do_caching_mobile_files; +// add_filter( 'pre_get_rocket_option_do_caching_mobile_files', [ $this, 'setDoCachingMobileFilesOption' ] ); +// +// $file = $this->config['vfs_dir'] . "cache/critical-css/{$site_id}/posts/{$post_type}-{$post_id}" . ( $is_mobile ? '-mobile' : '' ). ".css"; +// +// $body_param = []; +// $body_param['is_mobile'] = $is_mobile; +// if ( $request_timeout ) { +// $body_param['timeout'] = true; +// } +// +// $expected['message'] = str_replace( $orig_post_id, $post_id, $expected['message'] ); +// +// $cache_file_path = $this->filesystem->getUrl( "{$this->config['vfs_dir']}cache/wp-rocket/example.org/{$post_title}/index.html" ); +// if ( $expected['success'] ) { +// $this->assertTrue( $this->filesystem->exists( $cache_file_path ) ); +// } +// +// $this->assertSame( $expected, $this->doRestRequest( 'POST', "/wp-rocket/v1/cpcss/post/{$post_id}", $body_param ) ); +// $this->assertSame( $config['cpcss_exists_after'], $this->filesystem->exists( $file ) ); +// +// if ( $expected['success'] ) { +// $this->assertFalse( $this->filesystem->exists( $cache_file_path ) ); +// } } /** diff --git a/tests/Integration/inc/Engine/Optimization/GoogleFonts/Admin/Subscriber/displayGoogleFontsEnabler.php b/tests/Integration/inc/Engine/Optimization/GoogleFonts/Admin/Subscriber/displayGoogleFontsEnabler.php index 9992d6c551..6ccea76c75 100644 --- a/tests/Integration/inc/Engine/Optimization/GoogleFonts/Admin/Subscriber/displayGoogleFontsEnabler.php +++ b/tests/Integration/inc/Engine/Optimization/GoogleFonts/Admin/Subscriber/displayGoogleFontsEnabler.php @@ -53,32 +53,6 @@ public function providerTestData() { return $this->getTestData( __DIR__, 'displayGoogleFontsEnabler' ); } - private function getExpectedHtml() { - $html = << -
-
-Enable Google Font Optimization
-
-Improves font performance and combines multiple font requests to reduce the number of HTTP requests.
-
-This is a one-time action and this button will be removed afterwards. -More info -
-
-Google Fonts Optimization is now enabled for your site. -More info -
-
-
- -
- -HTML; - - return $this->format_the_html( $html ); - } private function getActualHtml() { ob_start(); diff --git a/tests/Integration/inc/Engine/Support/Subscriber/registerSupportRoute.php b/tests/Integration/inc/Engine/Support/Subscriber/registerSupportRoute.php index aa8ce70f8b..bb65ed6782 100644 --- a/tests/Integration/inc/Engine/Support/Subscriber/registerSupportRoute.php +++ b/tests/Integration/inc/Engine/Support/Subscriber/registerSupportRoute.php @@ -17,8 +17,6 @@ class Test_RegisterSupportRoute extends WPMediaRESTfulTestCase { protected static $api_credentials_config_file = 'license.php'; protected $config; - private $consumer_key; - private $consumer_email; private $wp_version; public static function set_up_before_class() { diff --git a/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanDomain.php b/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanDomain.php index e97c9230ba..00ff018ce6 100644 --- a/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanDomain.php +++ b/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanDomain.php @@ -14,9 +14,9 @@ class Test_cleanDomain extends GodaddyTestCase { public function testShouldDoBanRequest( ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - Filters\expectApplied( 'pre_http_request' )->andReturn( 'response' ); - - do_action( 'before_rocket_clean_domain', '', '', home_url() ); +// Filters\expectApplied( 'pre_http_request' )->andReturn( 'response' ); +// +// do_action( 'before_rocket_clean_domain', '', '', home_url() ); } } diff --git a/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanFile.php b/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanFile.php index 8f0838870e..77859a4088 100644 --- a/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanFile.php +++ b/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanFile.php @@ -14,9 +14,9 @@ class Test_cleanFile extends GodaddyTestCase { public function testShouldPurgeFile( ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - Filters\expectApplied( 'pre_http_request' )->andReturn( 'response' ); - - do_action( 'before_rocket_clean_file', home_url() ); +// Filters\expectApplied( 'pre_http_request' )->andReturn( 'response' ); +// +// do_action( 'before_rocket_clean_file', home_url() ); } } diff --git a/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanHome.php b/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanHome.php index 66caace24d..92a48ef977 100644 --- a/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanHome.php +++ b/tests/Integration/inc/ThirdParty/Hostings/Godaddy/cleanHome.php @@ -14,9 +14,9 @@ class Test_cleanHome extends GodaddyTestCase { public function testShouldPurgeHome( ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - Filters\expectApplied( 'pre_http_request' )->andReturn( 'response' ); - - do_action( 'before_rocket_clean_home', 'wp-rocket/cache', '' ); +// Filters\expectApplied( 'pre_http_request' )->andReturn( 'response' ); +// +// do_action( 'before_rocket_clean_home', 'wp-rocket/cache', '' ); } } diff --git a/tests/Integration/inc/ThirdParty/Hostings/Pressidium/cleanPost.php b/tests/Integration/inc/ThirdParty/Hostings/Pressidium/cleanPost.php index 2f5fa4a61b..9bb501d569 100644 --- a/tests/Integration/inc/ThirdParty/Hostings/Pressidium/cleanPost.php +++ b/tests/Integration/inc/ThirdParty/Hostings/Pressidium/cleanPost.php @@ -29,12 +29,12 @@ public function tear_down() { */ public function testShouldReturnExpected( $config, $expected ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - - $post = $this->factory()->post->create_and_get( $config['post'] ); - - $this->ninukis_caching->shouldReceive( 'purge_url' ) - ->with( $config['url'] ); - - do_action( 'after_rocket_clean_post', $post, $config['url'], '' ); +// +// $post = $this->factory()->post->create_and_get( $config['post'] ); +// +// $this->ninukis_caching->shouldReceive( 'purge_url' ) +// ->with( $config['url'] ); +// +// do_action( 'after_rocket_clean_post', $post, $config['url'], '' ); } } diff --git a/tests/Integration/inc/ThirdParty/Hostings/Pressidium/purgeUrl.php b/tests/Integration/inc/ThirdParty/Hostings/Pressidium/purgeUrl.php index 020d7b18b9..7e525196b5 100644 --- a/tests/Integration/inc/ThirdParty/Hostings/Pressidium/purgeUrl.php +++ b/tests/Integration/inc/ThirdParty/Hostings/Pressidium/purgeUrl.php @@ -26,8 +26,8 @@ public function set_up() { public function testShouldReturnExpected( $config ) { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - $this->ninukis_caching->shouldReceive( 'purge_url' ); - - do_action( 'after_rocket_clean_file' ); +// $this->ninukis_caching->shouldReceive( 'purge_url' ); +// +// do_action( 'after_rocket_clean_file' ); } } diff --git a/tests/Integration/inc/ThirdParty/Themes/Avada/cleanDomain.php b/tests/Integration/inc/ThirdParty/Themes/Avada/cleanDomain.php index b4f56183a9..1c9cd0d6a2 100644 --- a/tests/Integration/inc/ThirdParty/Themes/Avada/cleanDomain.php +++ b/tests/Integration/inc/ThirdParty/Themes/Avada/cleanDomain.php @@ -20,11 +20,14 @@ public function testShouldCleanCacheWhenAvadaCacheIsCleaned() { $cache_exists = false; + // @phpstan-ignore-next-line $this->assertSame( ! $cache_exists, $this->filesystem->exists( 'wp-content/cache/wp-rocket/example.org/index.html' ) ); + // @phpstan-ignore-next-line $this->assertSame( ! $cache_exists, $this->filesystem->exists( 'wp-content/cache/wp-rocket/example.org/index.html_gzip' ) ); + // @phpstan-ignore-next-line $this->assertSame( ! $cache_exists, $this->filesystem->exists( 'wp-content/cache/wp-rocket/example.org-wpmedia-594d03f6ae698691165999/about/index.html' ) ); + // @phpstan-ignore-next-line $this->assertSame( ! $cache_exists, $this->filesystem->exists( 'wp-content/cache/wp-rocket/example.org-wpmedia-594d03f6ae698691165999/about/index.html_gzip' ) ); - apply_filters( 'avada_clear_dynamic_css_cache', [], [] ); $this->assertSame( $cache_exists, $this->filesystem->exists( 'wp-content/cache/wp-rocket/example.org/index.html' ) ); diff --git a/tests/Integration/inc/ThirdParty/Themes/Divi/handleSaveTemplate.php b/tests/Integration/inc/ThirdParty/Themes/Divi/handleSaveTemplate.php index 4d6e5c69ae..62cad7279d 100644 --- a/tests/Integration/inc/ThirdParty/Themes/Divi/handleSaveTemplate.php +++ b/tests/Integration/inc/ThirdParty/Themes/Divi/handleSaveTemplate.php @@ -19,7 +19,10 @@ class Test_handleSaveTemplate extends WPThemeTestcase { protected $path_to_test_data = '/inc/ThirdParty/Themes/Divi/handleSaveTemplate.php'; + // @phpstan-ignore-next-line private static $user_without_permission; + + // @phpstan-ignore-next-line private static $user_with_permission; public static function set_up_before_class() { diff --git a/tests/Integration/inc/admin/rocketAfterSaveOptions.php b/tests/Integration/inc/admin/rocketAfterSaveOptions.php index a937a50e3f..b437cefc31 100644 --- a/tests/Integration/inc/admin/rocketAfterSaveOptions.php +++ b/tests/Integration/inc/admin/rocketAfterSaveOptions.php @@ -31,7 +31,6 @@ class Test_RocketAfterSaveOptions extends FilesystemTestCase { ]; private $is_apache; - private $hooks = []; private $expected; private $rocketCleanDomainEntriesBefore; private $rocketCleanMinifyEntriesBefore; @@ -84,7 +83,7 @@ public function tear_down() { public function testShouldTriggerCleaningsWhenOptionsChange( $settings, $expected ) { // Skip the "not an array" test as it fails in other hooked callbacks that are not checking for array. if ( ! is_array( $settings ) ) { - $this->assertTrue( true ); + $this->assertTrue( true ); // @phpstan-ignore-line return; } diff --git a/tests/Unit/inc/Addon/Cloudflare/Subscriber/saveCloudflareOptions.php b/tests/Unit/inc/Addon/Cloudflare/Subscriber/saveCloudflareOptions.php index e1dd2e5fe0..0b762e24cc 100644 --- a/tests/Unit/inc/Addon/Cloudflare/Subscriber/saveCloudflareOptions.php +++ b/tests/Unit/inc/Addon/Cloudflare/Subscriber/saveCloudflareOptions.php @@ -64,7 +64,7 @@ public function testShouldReturnExpected( $config, $expected ) { $this->cloudflare->shouldReceive( 'set_cache_level' ) ->with( 'aggressive' ) ->atMost() - ->once() + ->twice() ->andReturn( 'aggressive' ); $this->cloudflare->shouldReceive( 'set_rocket_loader' ) diff --git a/tests/Unit/inc/Engine/Admin/DomainChange/Subscriber/maybeCleanCacheDomainChange.php b/tests/Unit/inc/Engine/Admin/DomainChange/Subscriber/maybeCleanCacheDomainChange.php index 36895152bf..9f49fa8a66 100644 --- a/tests/Unit/inc/Engine/Admin/DomainChange/Subscriber/maybeCleanCacheDomainChange.php +++ b/tests/Unit/inc/Engine/Admin/DomainChange/Subscriber/maybeCleanCacheDomainChange.php @@ -58,6 +58,6 @@ public function testShouldDoAsExpected( $config ) } $this->subscriber->maybe_clean_cache_domain_change(); - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line } } diff --git a/tests/Unit/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php b/tests/Unit/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php index 5f9c711021..10faa7c587 100644 --- a/tests/Unit/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php +++ b/tests/Unit/inc/Engine/Cache/AdvancedCache/updateAdvancedCache.php @@ -47,16 +47,16 @@ public function testUpdateAdvancedCache( $set_filter, $expected ) { public function testShouldNotUpdateWhenMultisiteAndSitesNotZero() { $this->markTestSkipped( 'Test doest not perform assertion, need to revisit' ); - $advanced_cache = new AdvancedCache( - $this->filesystem->getUrl( $this->config['vfs_dir'] ), - $this->filesystem - ); - - Functions\when( 'is_rocket_generate_caching_mobile_files' )->justReturn( false ); - Functions\when( 'current_filter' )->justReturn( 'rocket_deactivation' ); - Functions\when( 'is_multisite' )->justReturn( true ); - - $advanced_cache->update_advanced_cache( 1 ); +// $advanced_cache = new AdvancedCache( +// $this->filesystem->getUrl( $this->config['vfs_dir'] ), +// $this->filesystem +// ); +// +// Functions\when( 'is_rocket_generate_caching_mobile_files' )->justReturn( false ); +// Functions\when( 'current_filter' )->justReturn( 'rocket_deactivation' ); +// Functions\when( 'is_multisite' )->justReturn( true ); +// +// $advanced_cache->update_advanced_cache( 1 ); } /** diff --git a/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php b/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php index 55784aa6e1..492b575dbd 100644 --- a/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php +++ b/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php @@ -17,9 +17,6 @@ */ class Test_AddCleanPerformanceHintsItem extends TestCase { private $admin_bar; - private $atf_context; - private $lrc_context; - private $wp_admin_bar; private $factories; diff --git a/tests/Unit/inc/Engine/CriticalPath/Admin/Admin/cpcssHeartbeat.php b/tests/Unit/inc/Engine/CriticalPath/Admin/Admin/cpcssHeartbeat.php index f02dbc3737..66b88dd974 100644 --- a/tests/Unit/inc/Engine/CriticalPath/Admin/Admin/cpcssHeartbeat.php +++ b/tests/Unit/inc/Engine/CriticalPath/Admin/Admin/cpcssHeartbeat.php @@ -24,13 +24,13 @@ class Test_CpcssHeartbeat extends TestCase { private $processor; private $wp_error; - public static function setUpBeforeClass() : void { + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); require_once WP_ROCKET_TESTS_FIXTURES_DIR . '/WP_Error.php'; } - protected function setUp() : void { + protected function setUp(): void { parent::setUp(); Functions\stubTranslationFunctions(); @@ -68,6 +68,8 @@ public function testShouldRunCPCSSHeartbeat( $config, $expected ) { $this->expectBailoutConditions( $expected ); } + $this->expectException( \Exception::class ); + $this->admin->cpcss_heartbeat(); } @@ -97,7 +99,8 @@ private function expectBailoutConditions( $expected ) { ->with( 'rocket_cpcss_generation_pending' ) ->never(); Functions\expect( $expected['json'] ) - ->once(); + ->once() + ->andThrow( new \Exception( 'Bailout' ) ); } private function expectTransientPending( $config, $expected ) { @@ -153,14 +156,16 @@ private function expectGenerationComplete( $config, $expected ) { if ( isset( $expected['generation_complete'] ) && ! $expected['generation_complete'] ) { Functions\expect( $expected['json'] ) ->once() - ->with( $expected['data'] ); + ->with( $expected['data'] ) + ->andThrow( new \Exception( 'not complete' ) ); } } private function assertGenerationCompleteWhenNotSet( $config, $expected ) { Functions\expect( $expected['json'] ) ->once() - ->with( $expected['data'] ); + ->with( $expected['data'] ) + ->andThrow( new \Exception( 'complete' ) ); if ( ! $config['rocket_critical_css_generation_process_running'] ) { Functions\expect( 'get_transient' ) diff --git a/tests/Unit/inc/Engine/CriticalPath/Admin/Settings/enableMobileCpcss.php b/tests/Unit/inc/Engine/CriticalPath/Admin/Settings/enableMobileCpcss.php index a9f0dc3f5f..2c36571401 100644 --- a/tests/Unit/inc/Engine/CriticalPath/Admin/Settings/enableMobileCpcss.php +++ b/tests/Unit/inc/Engine/CriticalPath/Admin/Settings/enableMobileCpcss.php @@ -9,17 +9,18 @@ /** * Test class covering \WP_Rocket\Engine\CriticalPath\Admin\Settings::enable_mobile_cpcss - * @uses ::rocket_get_constant * - * @group CriticalPath - * @group CriticalPathSettings + * @uses ::rocket_get_constant + * + * @group CriticalPath + * @group CriticalPathSettings */ class Test_EnableMobileCpcss extends TestCase { use AdminTrait; private $settings; - public function setUp() : void { + public function setUp(): void { parent::setUp(); $this->setUpMocks(); @@ -38,24 +39,43 @@ public function setUp() : void { * @dataProvider configTestData */ public function testShouldEnableMobileCpcss( $config, $update ) { - Functions\expect( 'current_user_can' )->once()->with( 'rocket_manage_options' )->andReturn( $config['rocket_manage_options'] ); - if ( isset( $config['rocket_regenerate_critical_css']) ) { - Functions\expect( 'current_user_can' )->once()->with( 'rocket_regenerate_critical_css' )->andReturn( $config['rocket_regenerate_critical_css'] ); + Functions\expect( 'current_user_can' ) + ->once() + ->with( 'rocket_manage_options' ) + ->andReturn( $config['rocket_manage_options'] ); + + if ( isset( $config['rocket_regenerate_critical_css'] ) ) { + Functions\expect( 'current_user_can' ) + ->once() + ->with( 'rocket_regenerate_critical_css' ) + ->andReturn( $config['rocket_regenerate_critical_css'] ); } if ( ! $update ) { - Functions\expect( 'wp_send_json_error' )->once(); + Functions\expect( 'wp_send_json_error' ) + ->once() + ->andThrow( new \Exception( 'no update' ) ); + $this->options->shouldReceive( 'set' )->never(); } else { - $this->options->shouldReceive( 'get_options' )->andReturn( $this->options ); - $this->options->shouldReceive( 'set' )->with( 'async_css_mobile', 1 ); + $this->options->shouldReceive( 'get_options' ) + ->andReturn( $this->options ); + $this->options->shouldReceive( 'set' ) + ->with( 'async_css_mobile', 1 ); - $this->critical_css->shouldReceive( 'process_handler' )->with( 'mobile' ); + $this->critical_css->shouldReceive( 'process_handler' ) + ->with( 'mobile' ); - Functions\expect( 'update_option' )->with( 'wp_rocket_settings', $this->options )->once(); - Functions\expect( 'wp_send_json_success' )->once(); + Functions\expect( 'update_option' ) + ->with( 'wp_rocket_settings', $this->options ) + ->once(); + Functions\expect( 'wp_send_json_success' ) + ->once() + ->andThrow( new \Exception( 'update' ) ); } + $this->expectException( \Exception::class ); + $this->settings->enable_mobile_cpcss(); } } diff --git a/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/maybeGenerateCpcssMobile.php b/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/maybeGenerateCpcssMobile.php index c5bba524d2..41249023ac 100644 --- a/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/maybeGenerateCpcssMobile.php +++ b/tests/Unit/inc/Engine/CriticalPath/CriticalCSSSubscriber/maybeGenerateCpcssMobile.php @@ -23,7 +23,6 @@ class Test_MaybeGenerateCpcssMobile extends TestCase { private $subscriber; private $critical_css; - private $processor_service; protected $user; protected $options_api; diff --git a/tests/Unit/inc/Engine/CriticalPath/RESTWPPost/delete.php b/tests/Unit/inc/Engine/CriticalPath/RESTWPPost/delete.php index f92999ead1..efa8549f44 100644 --- a/tests/Unit/inc/Engine/CriticalPath/RESTWPPost/delete.php +++ b/tests/Unit/inc/Engine/CriticalPath/RESTWPPost/delete.php @@ -56,7 +56,7 @@ public function testShouldDoExpected( $config, $expected ) { switch ( $expected['code'] ) { case 'rest_forbidden': // Skip as it's not valid for the unit test. - $this->assertTrue( true ); + $this->assertTrue( true ); // @phpstan-ignore-line return; diff --git a/tests/Unit/inc/Engine/Media/AboveTheFold/Frontend/Controller/addExclusions.php b/tests/Unit/inc/Engine/Media/AboveTheFold/Frontend/Controller/addExclusions.php index b313b41179..5fb5a71692 100644 --- a/tests/Unit/inc/Engine/Media/AboveTheFold/Frontend/Controller/addExclusions.php +++ b/tests/Unit/inc/Engine/Media/AboveTheFold/Frontend/Controller/addExclusions.php @@ -8,7 +8,6 @@ use WP_Rocket\Engine\Media\AboveTheFold\Context\Context; use WP_Rocket\Engine\Media\AboveTheFold\Database\Queries\AboveTheFold; use WP_Rocket\Engine\Media\AboveTheFold\Frontend\Controller; -use WP_Filesystem_Direct; use WP_Rocket\Tests\Unit\TestCase; use WP_Rocket\Tests\Fixtures\inc\Engine\Common\JobManager\Manager; @@ -23,7 +22,6 @@ class Test_addExclusions extends TestCase { private $query; private $controller; private $context; - private $filesystem; protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/inc/Engine/Media/Lazyload/CSS/Admin/Subscriber/maybeAddErrorNotice.php b/tests/Unit/inc/Engine/Media/Lazyload/CSS/Admin/Subscriber/maybeAddErrorNotice.php index a99f2f5bbe..00b7e24432 100644 --- a/tests/Unit/inc/Engine/Media/Lazyload/CSS/Admin/Subscriber/maybeAddErrorNotice.php +++ b/tests/Unit/inc/Engine/Media/Lazyload/CSS/Admin/Subscriber/maybeAddErrorNotice.php @@ -36,7 +36,7 @@ public function testShouldDoAsExpected( $config, $expected ) { $this->subscriber->maybe_add_error_notice(); - $this->assertTrue( true ); + $this->assertTrue( true ); // @phpstan-ignore-line } protected function configureIsAccessible( $config, $expected ) { diff --git a/tests/Unit/inc/Engine/Optimization/GoogleFonts/Admin/Settings/enableGoogleFonts.php b/tests/Unit/inc/Engine/Optimization/GoogleFonts/Admin/Settings/enableGoogleFonts.php index bcd34cd330..e127169d10 100644 --- a/tests/Unit/inc/Engine/Optimization/GoogleFonts/Admin/Settings/enableGoogleFonts.php +++ b/tests/Unit/inc/Engine/Optimization/GoogleFonts/Admin/Settings/enableGoogleFonts.php @@ -1,28 +1,29 @@ beacon = Mockery::mock( Beacon::class ); - $this->options = Mockery::mock( Options_Data::class ); + $this->beacon = Mockery::mock( Beacon::class ); + $this->options = Mockery::mock( Options_Data::class ); $this->settings = new Settings( $this->options, $this->beacon, @@ -33,7 +34,7 @@ public function setUp() : void { } /** - * @dataProvider provideTestData + * @dataProvider configTestData */ public function testShouldEnableGoogleFonts( $user_auth ) { Functions\when( 'current_user_can' )->justReturn( $user_auth ); @@ -43,28 +44,28 @@ public function testShouldEnableGoogleFonts( $user_auth ) { } else { $this->shouldSetOption(); } - } - public function shouldBail() { - Functions\expect( 'wp_send_json_error' )->once(); + $this->expectException( \Exception::class ); $this->settings->enable_google_fonts(); } + public function shouldBail() { + Functions\expect( 'wp_send_json_error' ) + ->once() + ->andThrow( new \Exception( 'no update' ) ); + } + public function shouldSetOption() { $this->options->shouldReceive( 'set' ) - ->once() - ->with( 'minify_google_fonts', 1 ); + ->once() + ->with( 'minify_google_fonts', 1 ); $this->options->shouldReceive( 'get_options' ) - ->once(); + ->once(); Functions\expect( 'update_option' )->once(); - Functions\expect( 'wp_send_json_success' )->once(); - - $this->settings->enable_google_fonts(); - } - - public function provideTestData() { - return $this->getTestData( __DIR__, 'enableGoogleFonts' ); + Functions\expect( 'wp_send_json_success' ) + ->once() + ->andThrow( new \Exception( 'update' ) ); } } diff --git a/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Activation/ActivationFactory/getContext.php b/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Activation/ActivationFactory/getContext.php deleted file mode 100644 index 1870a95b22..0000000000 --- a/tests/Unit/inc/Engine/Optimization/LazyRenderContent/Activation/ActivationFactory/getContext.php +++ /dev/null @@ -1,24 +0,0 @@ -assertInstanceOf( - ContextInterface::class, - $activation_factory->get_context() - ); - } -} diff --git a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/deleteOldUsedCss.php b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/deleteOldUsedCss.php index aaf3d3794c..7486d1e658 100644 --- a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/deleteOldUsedCss.php +++ b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/deleteOldUsedCss.php @@ -34,7 +34,7 @@ public function setUp() : void { */ public function testShouldDoExpected( $input ){ if ( $this->isPHP8() ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return; } @@ -58,7 +58,7 @@ public function testShouldDoExpected( $input ){ public function isPHP8() { $version = explode('.', PHP_VERSION); if ( $version[0] >= 8 ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return true; } diff --git a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropResourcesTable.php b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropResourcesTable.php index 3e82c62031..05fbf1d36a 100644 --- a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropResourcesTable.php +++ b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropResourcesTable.php @@ -47,7 +47,7 @@ protected function tearDown(): void { public function testShouldDeleteTableAndOption() { if ( $this->isPHP8() ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return; } @@ -67,7 +67,7 @@ public function testShouldDeleteTableAndOption() { public function isPHP8() { $version = explode('.', PHP_VERSION); if ( $version[0] >= 8 ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return true; } diff --git a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropRucssDatabaseTables.php b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropRucssDatabaseTables.php index 6d70b8cc0c..7c47d4f893 100644 --- a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropRucssDatabaseTables.php +++ b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/dropRucssDatabaseTables.php @@ -34,7 +34,7 @@ public function setUp() : void { */ public function testShouldDoExpected( $input ){ if ( $this->isPHP8() ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return; } @@ -58,7 +58,7 @@ public function testShouldDoExpected( $input ){ public function isPHP8() { $version = explode('.', PHP_VERSION); if ( $version[0] >= 8 ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return true; } diff --git a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/truncateUsedCssTable.php b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/truncateUsedCssTable.php index d136bbeb06..5ee9108d69 100644 --- a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/truncateUsedCssTable.php +++ b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Database/truncateUsedCssTable.php @@ -34,7 +34,7 @@ public function setUp() : void { */ public function testShouldDoExpected( $input ){ if ( $this->isPHP8() ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return; } @@ -59,7 +59,7 @@ public function testShouldDoExpected( $input ){ public function isPHP8() { $version = explode('.', PHP_VERSION); if ( $version[0] >= 8 ) { - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line return true; } diff --git a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php index 3f99c359f9..01ca50e791 100644 --- a/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php +++ b/tests/Unit/inc/Engine/Optimization/RUCSS/Admin/Subscriber/spawnCron.php @@ -3,9 +3,9 @@ use Brain\Monkey\Functions; use Mockery; -use WP_Rocket\Engine\Optimization\RUCSS\Admin\{Database,Settings,Subscriber}; -use WP_Rocket\Engine\Optimization\RUCSS\Controller\UsedCSS; use WP_Rocket\Engine\Common\JobManager\Queue\Queue; +use WP_Rocket\Engine\Optimization\RUCSS\Admin\{Database, Settings, Subscriber}; +use WP_Rocket\Engine\Optimization\RUCSS\Controller\UsedCSS; use WP_Rocket\Tests\Unit\TestCase; /** @@ -14,10 +14,9 @@ * @group RUCSS */ class Test_SpawnCron extends TestCase { - private $subscriber; - public function setUp() : void { + public function setUp(): void { parent::setUp(); $this->subscriber = new Subscriber( Mockery::mock( Settings::class ), Mockery::mock( Database::class ), Mockery::mock( UsedCSS::class ), Mockery::mock( Queue::class ) ); @@ -26,15 +25,20 @@ public function setUp() : void { /** * @dataProvider configTestData */ - public function testShouldReturnAsExpected($config, $expected) - { - Functions\when('rocket_get_constant')->justReturn($config['rocket_get_constant']); - - Functions\when('current_user_can')->justReturn($config['current_user_can']); - Functions\expect('wp_send_json_error')->times($expected['wp_send_json_error']); - Functions\when('check_ajax_referer')->justReturn(true); - Functions\when('wp_send_json_success')->justReturn(true); - Functions\expect('spawn_cron')->times($expected['spawnCronCalled']); + public function testShouldReturnAsExpected( $config, $expected ) { + Functions\when( 'rocket_get_constant' )->justReturn( $config['rocket_get_constant'] ); + + Functions\when( 'current_user_can' )->justReturn( $config['current_user_can'] ); + Functions\expect( 'wp_send_json_error' ) + ->times( $expected['wp_send_json_error'] ) + ->andThrow( new \Exception( 'error' ) ); + Functions\when( 'check_ajax_referer' )->justReturn( true ); + Functions\when( 'wp_send_json_success' )->justReturn( true ); + Functions\expect( 'spawn_cron' )->times( $expected['spawnCronCalled'] ); + + if ( $expected['wp_send_json_error'] > 0 ) { + $this->expectException( \Exception::class ); + } $this->subscriber->spawn_cron(); } diff --git a/tests/Unit/inc/Engine/Preload/Controller/LoadInitialSitemap/loadInitialSitemap.php b/tests/Unit/inc/Engine/Preload/Controller/LoadInitialSitemap/loadInitialSitemap.php index 924a54084d..5b5a21feb0 100755 --- a/tests/Unit/inc/Engine/Preload/Controller/LoadInitialSitemap/loadInitialSitemap.php +++ b/tests/Unit/inc/Engine/Preload/Controller/LoadInitialSitemap/loadInitialSitemap.php @@ -56,9 +56,6 @@ public function testShouldDoAsExpected($config, $expected) { protected function configureWordPressSitemap($config) { if(count($config['filter_sitemaps']) > 0) { return ; - $this->query->expects(self::once())->method('create_or_nothing')->with([ - 'url' => $config['home_url'] - ]); } Functions\expect('get_option')->with('blog_public')->andReturn($config['is_sitemap_activated']); diff --git a/tests/Unit/inc/Engine/Saas/Admin/AdminBar/addCleanSaasMenuItem.php b/tests/Unit/inc/Engine/Saas/Admin/AdminBar/addCleanSaasMenuItem.php index 3ff5650444..402347e1ed 100644 --- a/tests/Unit/inc/Engine/Saas/Admin/AdminBar/addCleanSaasMenuItem.php +++ b/tests/Unit/inc/Engine/Saas/Admin/AdminBar/addCleanSaasMenuItem.php @@ -17,7 +17,6 @@ class Test_AddCleanSaasMenuItem extends TestCase { private $admin_bar; private $options; - private $atf_context; private $rucss_url_context; private $wp_admin_bar; diff --git a/tests/Unit/inc/ThirdParty/Plugins/CDN/Cloudflare/updateAddonField.php b/tests/Unit/inc/ThirdParty/Plugins/CDN/Cloudflare/updateAddonField.php index aff7a0e44e..18664bcabe 100644 --- a/tests/Unit/inc/ThirdParty/Plugins/CDN/Cloudflare/updateAddonField.php +++ b/tests/Unit/inc/ThirdParty/Plugins/CDN/Cloudflare/updateAddonField.php @@ -69,10 +69,6 @@ public function testShouldReturnAsExpected( $config, $expected ) return $config['cloudflare_cached_domain_name']; } - if('cloudflare_cached_domain_name' === $name) { - return $config['cloudflare_cached_domain_name']; - } - return null; }); $this->assertSame($expected, $this->cloudflare->update_addon_field($config['settings'])); diff --git a/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/disableOptionsOnAmp.php b/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/disableOptionsOnAmp.php index 411690687a..56ae8ae6b0 100644 --- a/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/disableOptionsOnAmp.php +++ b/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/disableOptionsOnAmp.php @@ -17,15 +17,13 @@ */ class Test_DisableOptionsOnAmp extends TestCase { private $amp; - private $options; private $cdn_subscriber; public function setUp() : void { parent::setUp(); - $this->options = Mockery::mock( Options_Data::class ); $this->cdn_subscriber = Mockery::mock( Subscriber::class ); - $this->amp = new AMP( $this->options, $this->cdn_subscriber ); + $this->amp = new AMP( $this->cdn_subscriber ); } /** @@ -48,7 +46,6 @@ public function testShouldDoExpected( $config, $expected ) { if ( $expected[ 'bailout' ] ) { Functions\expect( 'remove_filter' )->never(); - $this->options->shouldReceive( 'get' )->never(); } else { global $wp_filter; add_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 ); @@ -102,7 +99,7 @@ public function testShouldDoExpected( $config, $expected ) { 10, has_filter( 'do_rocket_protocol_rewrite', '__return_false' ) ); - $this->assertEmpty( $wp_filter ); + $this->assertEmpty( $wp_filter ); // @phpstan-ignore-line if ( in_array( $config[ 'amp_options' ][ 'theme_support' ], [ 'transitional', 'reader' ], true ) ) { $this->assertSame( diff --git a/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/excludeScriptFromDelayJs.php b/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/excludeScriptFromDelayJs.php index cf4be63745..99688ed64a 100644 --- a/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/excludeScriptFromDelayJs.php +++ b/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/excludeScriptFromDelayJs.php @@ -17,15 +17,13 @@ class Test_ExcludeScriptFromDelayJs extends TestCase { private $amp; - private $options; private $cdn_subscriber; public function setUp() : void { parent::setUp(); - $this->options = Mockery::mock( Options_Data::class ); $this->cdn_subscriber = Mockery::mock( Subscriber::class ); - $this->amp = new AMP( $this->options, $this->cdn_subscriber ); + $this->amp = new AMP( $this->cdn_subscriber ); } /** diff --git a/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php b/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php index 3a81bc1bcb..aba193dff0 100644 --- a/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php +++ b/tests/Unit/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php @@ -16,15 +16,13 @@ */ class Test_IsAmpCompatibleCallback extends TestCase { private $amp; - private $options; private $cdn_subscriber; public function setUp() : void { parent::setUp(); - $this->options = Mockery::mock( Options_Data::class ); $this->cdn_subscriber = Mockery::mock( Subscriber::class ); - $this->amp = new AMP( $this->options, $this->cdn_subscriber ); + $this->amp = new AMP( $this->cdn_subscriber ); } /** diff --git a/tests/Unit/inc/ThirdParty/Themes/Themify/disablingConcatOnRucss.php b/tests/Unit/inc/ThirdParty/Themes/Themify/disablingConcatOnRucss.php index fa7c1c99e1..49165f2789 100644 --- a/tests/Unit/inc/ThirdParty/Themes/Themify/disablingConcatOnRucss.php +++ b/tests/Unit/inc/ThirdParty/Themes/Themify/disablingConcatOnRucss.php @@ -46,6 +46,6 @@ public function testShouldDoAsExpected( $config, $expected ) $this->themify->disabling_concat_on_rucss( $config['old_configurations'], $config['new_configurations'] ); - $this->assertTrue(true); + $this->assertTrue(true); // @phpstan-ignore-line } } diff --git a/tests/Unit/inc/classes/third-party/plugins/Images/Webp/EWWW_Subscriber/loadHooks.php b/tests/Unit/inc/classes/third-party/plugins/Images/Webp/EWWW_Subscriber/loadHooks.php index 23b8885778..b45fe3ec2d 100644 --- a/tests/Unit/inc/classes/third-party/plugins/Images/Webp/EWWW_Subscriber/loadHooks.php +++ b/tests/Unit/inc/classes/third-party/plugins/Images/Webp/EWWW_Subscriber/loadHooks.php @@ -50,7 +50,8 @@ public function testShouldRegisterHooksWhenPluginNotAvailable() { $subscriber->load_hooks(); - $this->assertTrue( true ); // Prevent "risky" warning. + // Prevent "risky" warning. + $this->assertTrue( true ); // @phpstan-ignore-line } public function testShouldCallCallbacksWhenDidAction() { diff --git a/tests/Unit/inc/common/rocketCleanPostCacheOnStatusChange.php b/tests/Unit/inc/common/rocketCleanPostCacheOnStatusChange.php index 831499d137..f3ab1cdc70 100644 --- a/tests/Unit/inc/common/rocketCleanPostCacheOnStatusChange.php +++ b/tests/Unit/inc/common/rocketCleanPostCacheOnStatusChange.php @@ -30,7 +30,7 @@ public function setUp() : void { * @dataProvider configTestData */ public function testShouldReturnAsExpected( $config, $expected ) { - $post = (object) $config['post_data'] ?? []; + $post = (object) $config['post_data']; $post_id = $config['post_data']['ID'] ?? 0; $post_type_public = isset( $config['post_type_public'] ) ? (object) $config['post_type_public'] : null; //post_type_public