Skip to content

Commit

Permalink
update WP CS to 3.0 (#6115)
Browse files Browse the repository at this point in the history
Co-authored-by: Ahmed Saeed <[email protected]>
Co-authored-by: engahmeds3ed <[email protected]>
Co-authored-by: Vasilis Manthos <[email protected]>
  • Loading branch information
4 people authored Sep 26, 2023
1 parent 539ecea commit 06381b8
Show file tree
Hide file tree
Showing 113 changed files with 201 additions and 302 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/lint_phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
name: WPRocket lint with PHPCS. PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -35,7 +35,5 @@ jobs:
run: composer install --prefer-dist --no-interaction --no-scripts

- name: Lint with phpcs
run: |
vendor/bin/phpcs --config-set installed_paths ../../phpcompatibility/phpcompatibility-paragonie,../../phpcompatibility/phpcompatibility-wp,../../wp-coding-standards/wpcs,../../phpcompatibility/php-compatibility
composer phpcs
run: composer phpcs

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"roave/security-advisories": "dev-master",
"szepeviktor/phpstan-wordpress": "^1.3",
"woocommerce/action-scheduler": "^3.4",
"wp-coding-standards/wpcs": "^2",
"wp-coding-standards/wpcs": "^3",
"wp-media/background-processing": "^1.3",
"wp-media/phpunit": "^3",
"wp-media/rocket-lazyload-common": "^3.0.11",
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/hosting/flywheel.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function rocket_flywheel_remove_partial_purge_hooks() {

// Remove rocket_clean_post() from core action hooks.
array_map(
function( $hook ) {
function ( $hook ) {
remove_action( $hook, 'rocket_clean_post' );
},
$clean_post_hooks
Expand Down
4 changes: 2 additions & 2 deletions inc/3rd-party/hosting/presslabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function rocket_pl_clean_post( $post = false, $permalink = false ) {
*
* @return void
*/
function rocket_pl_clean_home( $root = false, $lang = false ) {
function rocket_pl_clean_home( $root = false, $lang = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
if ( ! $post || ! $permalink ) {
return;
}
Expand All @@ -72,7 +72,7 @@ function rocket_pl_remove_partial_purge_hooks() {
];
// Remove rocket_clean_post() from core action hooks.
array_map(
function( $hook ) {
function ( $hook ) {
remove_action( $hook, 'rocket_clean_post' );
},
$clean_post_hooks
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/cookies/weepie-cookie-allow.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @param array $old_value Previous values for the plugin options.
* @param array $value New values for the plugin options.
*/
function rocket_after_update_wp_cookie_allow_options( $old_value, $value ) {
function rocket_after_update_wp_cookie_allow_options( $old_value, $value ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
// clear the cache because WeePie Cookie Allow plugin settings might have been changed.
rocket_clean_domain();
}
Expand Down
6 changes: 3 additions & 3 deletions inc/3rd-party/plugins/ecommerce/woocommerce-multilingual.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ function rocket_wcml_reset_settings( $option, $old_data, $data ) {
'default_currencies',
];

$check_key = function( $result, $key ) use ( $old_data, $data ) {
$has_value_changed = function( $key ) use ( $old_data, $data ) {
$get_value = function( $key, $data ) {
$check_key = function ( $result, $key ) use ( $old_data, $data ) {
$has_value_changed = function ( $key ) use ( $old_data, $data ) {
$get_value = function ( $key, $data ) {
return isset( $data[ $key ] ) ? $data[ $key ] : null;
};

Expand Down
2 changes: 0 additions & 2 deletions inc/3rd-party/plugins/envira-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ function rocket_deactivate_lazyload_on_envira_gallery_indexable_images( $images
return $images;
}
add_filter( 'envira_gallery_indexable_images', 'rocket_deactivate_lazyload_on_envira_gallery_indexable_images', PHP_INT_MAX );


2 changes: 1 addition & 1 deletion inc/Addon/Cloudflare/Auth/AuthFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface AuthFactoryInterface {
* @param array $data Data to inject into the client.
* @return AuthInterface
*/
public function create( array $data = []): AuthInterface;
public function create( array $data = [] ): AuthInterface;
}
2 changes: 1 addition & 1 deletion inc/Addon/Cloudflare/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function purge_cloudflare() {
*
* @return mixed true if the purge is successful, WP_Error otherwise
*/
public function purge_by_url( $post, $purge_urls, $lang ) {
public function purge_by_url( $post, $purge_urls, $lang ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$result = $this->endpoints->purge_files( $this->options->get( 'cloudflare_zone_id', '' ), $purge_urls );

if ( is_wp_error( $result ) ) {
Expand Down
7 changes: 3 additions & 4 deletions inc/Addon/WebP/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private function get_extensions() {
$extensions = apply_filters( 'rocket_file_extensions_for_webp', $extensions );
$extensions = array_filter(
(array) $extensions,
function( $extension ) {
function ( $extension ) {
return $extension && is_string( $extension );
}
);
Expand Down Expand Up @@ -334,7 +334,7 @@ private function get_attribute_names() {
$attributes = apply_filters( 'rocket_attributes_for_webp', $attributes );
$attributes = array_filter(
(array) $attributes,
function( $attributes ) {
function ( $attributes ) {
return $attributes && is_string( $attributes );
}
);
Expand Down Expand Up @@ -539,7 +539,7 @@ private function get_url_to_path_associations() {
$list = apply_filters( 'rocket_url_to_path_associations', $list );
$list = array_filter(
$list,
function( $path, $url ) {
function ( $path, $url ) {
return $path && $url && is_string( $path ) && is_string( $url );
},
ARRAY_FILTER_USE_BOTH
Expand Down Expand Up @@ -595,5 +595,4 @@ public function change_youtube_thumbnail( $extension ) {
}
return 'webp';
}

}
2 changes: 1 addition & 1 deletion inc/Engine/Admin/Beacon/Beacon.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function prefill_data() {
*
* @return array
*/
private function config_data() : array {
private function config_data(): array {
return [
'display' => [
'position' => is_rtl() ? 'left' : 'right',
Expand Down
1 change: 0 additions & 1 deletion inc/Engine/Admin/Database/OptimizationProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,4 @@ protected function complete() {

parent::complete();
}

}
6 changes: 2 additions & 4 deletions inc/Engine/Admin/Metaboxes/PostEditOptionsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ public function save_metabox_options() {
if ( ! isset( $rejected_uris[ $path ] ) ) {
array_push( $new_cache_reject_uri, $path );
}
} else {
if ( isset( $rejected_uris[ $path ] ) ) {
unset( $new_cache_reject_uri[ $rejected_uris[ $path ] ] );
}
} elseif ( isset( $rejected_uris[ $path ] ) ) {
unset( $new_cache_reject_uri[ $rejected_uris[ $path ] ] );
}

if ( $new_cache_reject_uri !== $cache_reject_uri ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ 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' ) {
private function sanitize_and_format_list( $list, $tag_name = 'strong' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.listFound
if ( ! is_array( $list ) || empty( $list ) ) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Admin/Settings/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function render_navigation() {
];

$navigation = array_map(
function( array $item ) use ( $default ) {
function ( array $item ) use ( $default ) {
$item = wp_parse_args( $item, $default );

if ( ! empty( $item['class'] ) ) {
Expand Down
8 changes: 4 additions & 4 deletions inc/Engine/Admin/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function sanitize_callback( $input ) {
$notices = array_merge( (array) $wp_settings_errors, (array) get_transient( 'settings_errors' ) );
$notices = array_filter(
$notices,
function( $error ) {
function ( $error ) {
if ( ! $error || ! is_array( $error ) ) {
return false;
}
Expand Down Expand Up @@ -472,7 +472,7 @@ function( $error ) {
* @param string $key Array key to check.
* @return int
*/
public function sanitize_checkbox( $array, $key ) {
public function sanitize_checkbox( $array, $key ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
return isset( $array[ $key ] ) && ! empty( $array[ $key ] ) ? 1 : 0;
}

Expand Down Expand Up @@ -520,7 +520,7 @@ private function sanitize_dns_prefetch( array $input ) {

return array_unique(
array_map(
function( $url ) {
function ( $url ) {
return '//' . wp_parse_url( $url, PHP_URL_HOST );
},
$urls
Expand Down Expand Up @@ -678,7 +678,7 @@ private function check_global_exclusion( $field ) {
*/
private function sanitize_cdn_cnames( array $cnames ) {
$cnames = array_map(
function( $cname ) {
function ( $cname ) {
$cname = trim( $cname );

if ( empty( $cname ) ) {
Expand Down
3 changes: 1 addition & 2 deletions inc/Engine/Cache/AdminSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AdminSubscriber implements Event_Manager_Aware_Subscriber_Interface {
public function __construct( AdvancedCache $advanced_cache, WPCache $wp_cache, $filesystem = null ) {
$this->advanced_cache = $advanced_cache;
$this->wp_cache = $wp_cache;
$this->filesystem = $filesystem ?: rocket_direct_filesystem();
$this->filesystem = ! empty( $filesystem ) ? $filesystem : rocket_direct_filesystem();
}

/**
Expand All @@ -77,7 +77,6 @@ public static function get_subscribed_events() {
[ 'delete_old_configs' ],
[ 'clear_cache', 10, 2 ],
],
'wp_rocket_upgrade' => [ 'on_update', 10, 2 ],
];
}

Expand Down
1 change: 0 additions & 1 deletion inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,4 @@ public function update_lifespan_value( $old_lifespan, $old_lifespan_unit ) {

update_option( 'wp_rocket_settings', $options );
}

}
2 changes: 1 addition & 1 deletion inc/Engine/Common/Context/ContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface ContextInterface {
* @param array $data Data to pass to the context.
* @return bool
*/
public function is_allowed( array $data = []): bool;
public function is_allowed( array $data = [] ): bool;
}
3 changes: 2 additions & 1 deletion inc/Engine/Common/ExtractCSS/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use WP_Rocket\Logger\LoggerAwareInterface;

class Subscriber implements Subscriber_Interface, LoggerAwareInterface {
use RegexTrait, LoggerAware;
use RegexTrait;
use LoggerAware;

/**
* Returns an array of events that this subscriber wants to listen to.
Expand Down
1 change: 0 additions & 1 deletion inc/Engine/Common/Queue/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ public function delete_old_actions() {
}
}
}

}
1 change: 0 additions & 1 deletion inc/Engine/Common/Queue/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,4 @@ public function get_next( $hook, $args = null );
* @return array
*/
public function search( $args = [], $return_format = OBJECT );

}
3 changes: 1 addition & 2 deletions inc/Engine/Common/Queue/RUCSSQueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function do_batch( $size = 100, $context = '' ) {
break;
}
$this->process_action( $action_id, $context );
$processed_actions++;
++$processed_actions;

if ( $this->batch_limits_exceeded( $processed_actions ) ) {
break;
Expand Down Expand Up @@ -276,5 +276,4 @@ public function add_wp_cron_schedule( $schedules ) {
public function get_allowed_concurrent_batches() {
return 2;
}

}
2 changes: 1 addition & 1 deletion inc/Engine/CriticalPath/APIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private function get_response_data( $response ) {
*
* @return string response code.
*/
private function get_response_code( $response ) {
private function get_response_code( $response ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
// Todo: we can return code based on the response status number, for example 404 not_found.
return 'cpcss_generation_failed';
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/CriticalPath/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function process_cpcss_pending_queue( array $cpcss_pending ) {
);

// Increment this item's threshold count.
$cpcss_pending[ $cpcss_item['path'] ]['check']++;
++$cpcss_pending[ $cpcss_item['path'] ]['check'];

$this->cpcss_heartbeat_notices( $cpcss_generation, $cpcss_item );

Expand Down
4 changes: 2 additions & 2 deletions inc/Engine/CriticalPath/CriticalCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ private function update_process_running_transient() {

foreach ( $this->items as $item ) {
if ( ! isset( $item['mobile'] ) ) {
$total ++;
++$total;
continue;
}

if ( 1 === $item['mobile'] ) {
continue;
}

$total ++;
++$total;
}

$transient = [
Expand Down
6 changes: 3 additions & 3 deletions inc/Engine/CriticalPath/CriticalCSSSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
class CriticalCSSSubscriber implements Subscriber_Interface {
use RegexTrait;

/**
* Instance of Critical CSS.
*
Expand Down Expand Up @@ -371,7 +372,7 @@ public function critical_css_generation_running_notice() {
if ( $status_nonmobile && $status_mobile ) {
$items_message .= '<li>' . $item['status']['nonmobile']['message'] . '</li>';
if ( $item['status']['nonmobile']['success'] ) {
$success_counter ++;
++$success_counter;
}
}
}
Expand Down Expand Up @@ -450,7 +451,7 @@ public function critical_css_generation_complete_notice() {
}
$items_message .= '<li>' . $item['status']['nonmobile']['message'] . '</li>';
if ( $item['status']['nonmobile']['success'] ) {
$success_counter ++;
++$success_counter;
}
}

Expand Down Expand Up @@ -845,7 +846,6 @@ public function switch_to_rucss_notice() {
'dismiss_button_message' => __( 'Stay with the old option', 'rocket' ),
]
);

}

/**
Expand Down
1 change: 0 additions & 1 deletion inc/Engine/CriticalPath/ProcessorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,4 @@ private function process_timeout( $item_url, $is_mobile = false, $item_type = 'c
]
);
}

}
1 change: 0 additions & 1 deletion inc/Engine/CriticalPath/RESTCSSSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ public function register_routes() {
$this->rest_manager->register_generate_route();
$this->rest_manager->register_delete_route();
}

}
2 changes: 0 additions & 2 deletions inc/Engine/CriticalPath/RESTWP.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ public function generate( WP_REST_Request $request ) {
return rest_ensure_response(
$this->return_success( $generated )
);

}

/**
Expand Down Expand Up @@ -318,5 +317,4 @@ protected function return_success( $data ) {
200
);
}

}
1 change: 0 additions & 1 deletion inc/Engine/CriticalPath/RESTWPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ public function generate( WP_REST_Request $request );
* @return WP_REST_Response
*/
public function delete( WP_REST_Request $request );

}
Loading

0 comments on commit 06381b8

Please sign in to comment.