Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS fixes: WordPress and WooCommerce #1081

Open
wants to merge 26 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
39e6497
eliminate WordPress.WhiteSpace.PrecisionAlignment smells
crstauf Aug 2, 2024
fb3a59f
eliminate WordPress.WhiteSpace.OperatorSpacing smells
crstauf Aug 2, 2024
e3be4bb
eliminate WordPress.WhiteSpace.ControlStructureSpacing smells
crstauf Aug 2, 2024
af4f5a5
eliminate WordPress.Security.EscapeOutput smells
crstauf Aug 2, 2024
2352610
eliminate WordPress.WP.CronInterval smells
crstauf Aug 2, 2024
1c3d753
eliminate WordPress.PHP.YodaConditions smells
crstauf Aug 2, 2024
b7a1002
eliminate WordPress.PHP.StrictInArray smells
crstauf Aug 3, 2024
1a3d5ce
eliminate WordPress.PHP.StrictComparisons smells
crstauf Aug 3, 2024
d5451c7
eliminate some WordPress.PHP.DevelopmentFunctions smells
crstauf Aug 3, 2024
cfafb3b
eliminate WordPress.NamingConventions.ValidVariableName smells
crstauf Aug 3, 2024
0d0ec58
eliminate WordPress.CodeAnalysis.AssignmentInCondition smells
crstauf Aug 3, 2024
b9abf80
eliminate WordPress.Classes.ClassInstantiation smells
crstauf Aug 3, 2024
deb901e
eliminate WordPress.Arrays.MultipleStatementAlignment smells
crstauf Aug 3, 2024
4c4a219
eliminate WordPress.Arrays.CommaAfterArrayItem smells
crstauf Aug 3, 2024
8ca4c4c
eliminate WordPress.Arrays.ArrayKeySpacingRestrictions smells
crstauf Aug 3, 2024
4f22362
eliminate WordPress.Arrays.ArrayIndentation smells
crstauf Aug 3, 2024
bd99172
eliminate WordPress.Arrays.ArrayDeclarationSpacing smells
crstauf Aug 3, 2024
1ad9418
eliminate WooCommerce.Commenting.CommentTags smells
crstauf Aug 3, 2024
756162d
eliminate WordPress.PHP.StrictComparisons smells properly
crstauf Aug 8, 2024
36eeb8e
Merge branch 'trunk' into phpcs/wordpress
crstauf Aug 12, 2024
0bcb67b
Merge branch 'master' into phpcs/wordpress
crstauf Aug 15, 2024
93e65d0
Merge branch 'trunk' into phpcs/wordpress
crstauf Aug 21, 2024
070ecfb
Merge branch 'trunk' into phpcs/wordpress
crstauf Aug 26, 2024
3101096
Merge branch 'trunk' into phpcs/wordpress
crstauf Sep 5, 2024
0307cba
Merge branch 'trunk' into phpcs/wordpress
crstauf Sep 14, 2024
74314ad
Merge branch 'trunk' into phpcs/wordpress
crstauf Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions classes/ActionScheduler_AdminView.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function instance() {
* @codeCoverageIgnore
*/
public function init() {
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false === DOING_AJAX ) ) {

if ( class_exists( 'WooCommerce' ) ) {
add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
Expand Down Expand Up @@ -200,13 +200,19 @@ protected function check_pastdue_actions() {
echo '<div class="notice notice-warning"><p>';
printf(
// translators: 1) is the number of affected actions, 2) is a link to an admin screen.
_n(
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
$num_pastdue_actions,
'action-scheduler'
wp_kses(
_n(
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
$num_pastdue_actions,
'action-scheduler'
),
array(
'strong' => array(),
'a' => array( 'href', 'target' ),
)
),
$num_pastdue_actions,
absint( $num_pastdue_actions ),
esc_attr( esc_url( $actions_url ) )
);
echo '</p></div>';
Expand All @@ -221,7 +227,7 @@ protected function check_pastdue_actions() {
public function add_help_tabs() {
$screen = get_current_screen();

if ( ! $screen || self::$screen_id != $screen->id ) {
if ( ! $screen || self::$screen_id !== $screen->id ) {
return;
}

Expand Down
3 changes: 0 additions & 3 deletions classes/ActionScheduler_AsyncRequest_QueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ class ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request {
* Data store for querying actions
*
* @var ActionScheduler_Store
* @access protected
*/
protected $store;

/**
* Prefix for ajax hooks
*
* @var string
* @access protected
*/
protected $prefix = 'as';

/**
* Action for ajax hooks
*
* @var string
* @access protected
*/
protected $action = 'async_request_queue_runner';

Expand Down
8 changes: 4 additions & 4 deletions classes/ActionScheduler_DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ActionScheduler_DateTime extends DateTime {
*
* @var int
*/
protected $utcOffset = 0;
protected $utc_offset = 0;

/**
* Get the unix timestamp of the current object.
Expand All @@ -37,7 +37,7 @@ public function getTimestamp() {
* @param string|int $offset UTC offset value.
*/
public function setUtcOffset( $offset ) {
$this->utcOffset = intval( $offset );
$this->utc_offset = intval( $offset );
}

/**
Expand All @@ -48,7 +48,7 @@ public function setUtcOffset( $offset ) {
*/
#[\ReturnTypeWillChange]
public function getOffset() {
return $this->utcOffset ? $this->utcOffset : parent::getOffset();
return $this->utc_offset ? $this->utc_offset : parent::getOffset();
}

/**
Expand All @@ -61,7 +61,7 @@ public function getOffset() {
*/
#[\ReturnTypeWillChange]
public function setTimezone( $timezone ) {
$this->utcOffset = 0;
$this->utc_offset = 0;
parent::setTimezone( $timezone );

return $this;
Expand Down
4 changes: 2 additions & 2 deletions classes/ActionScheduler_FatalErrorMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function handle_unexpected_shutdown() {
$error = error_get_last();

if ( $error ) {
if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) {
if ( !empty($this->action_id) ) {
if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
if ( ! empty($this->action_id) ) {
$this->store->mark_failure( $this->action_id );
do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error );
}
Expand Down
6 changes: 2 additions & 4 deletions classes/ActionScheduler_InvalidActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function from_schedule( $action_id, $schedule ) {
/* translators: 1: action ID 2: schedule */
__( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ),
$action_id,
var_export( $schedule, true )
var_export( $schedule, true ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions
);

return new static( $message );
Expand All @@ -30,8 +30,6 @@ public static function from_schedule( $action_id, $schedule ) {
/**
* Create a new exception when the action's args cannot be decoded to an array.
*
* @author Jeremy Pry
*
* @param string $action_id The action ID with bad args.
* @param mixed $args Passed arguments.
* @return static
Expand All @@ -41,7 +39,7 @@ public static function from_decoding_args( $action_id, $args = array() ) {
/* translators: 1: action ID 2: arguments */
__( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ),
$action_id,
var_export( $args, true )
var_export( $args, true ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions
);

return new static( $message );
Expand Down
14 changes: 7 additions & 7 deletions classes/ActionScheduler_ListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ public function __construct( ActionScheduler_Store $store, ActionScheduler_Logge

if ( empty( $request_status ) ) {
$this->sort_by[] = 'status';
} elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) {
} elseif ( in_array( $request_status, array( 'in-progress', 'failed' ), true ) ) {
$this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) );
$this->sort_by[] = 'claim_id';
}

$this->row_actions = array(
'hook' => array(
'run' => array(
'name' => __( 'Run', 'action-scheduler' ),
'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
'run' => array(
'name' => __( 'Run', 'action-scheduler' ),
'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
),
'cancel' => array(
'name' => __( 'Cancel', 'action-scheduler' ),
Expand Down Expand Up @@ -331,7 +331,7 @@ protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, Date
* @return string
*/
protected function maybe_render_actions( $row, $column_name ) {
if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) {
if ( 'pending' === strtolower( $row['status_name'] ) ) {
return parent::maybe_render_actions( $row, $column_name );
}

Expand Down Expand Up @@ -359,7 +359,7 @@ public function display_admin_notices() {

$found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
foreach ( $table_list as $table_name ) {
if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) {
if ( ! in_array( $wpdb->prefix . $table_name, $found_tables, true ) ) {
$this->admin_notices[] = array(
'class' => 'error',
'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ),
Expand Down Expand Up @@ -414,7 +414,7 @@ public function display_admin_notices() {

$action = $this->store->fetch_action( $notification['action_id'] );
$action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>';
if ( 1 == $notification['success'] ) {
if ( 1 === absint( $notification['success'] ) ) {
$class = 'updated';
switch ( $notification['row_action_type'] ) {
case 'run' :
Expand Down
6 changes: 3 additions & 3 deletions classes/ActionScheduler_LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class ActionScheduler_LogEntry {
/**
* @var int $action_id
*/
protected $action_id = '';
protected $action_id = '';

/**
* @var string $message
*/
protected $message = '';
protected $message = '';

/**
* @var Datetime $date
Expand Down Expand Up @@ -43,7 +43,7 @@ public function __construct( $action_id, $message, $date = null ) {

$this->action_id = $action_id;
$this->message = $message;
$this->date = $date ? $date : new Datetime;
$this->date = $date ? $date : new Datetime();
}

/**
Expand Down
8 changes: 3 additions & 5 deletions classes/ActionScheduler_QueueCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public function delete_old_actions() {
* @return array Actions deleted.
*/
public function clean_actions( array $statuses_to_purge, DateTime $cutoff_date, $batch_size = null, $context = 'old' ) {
$batch_size = $batch_size !== null ? $batch_size : $this->batch_size;
$cutoff = $cutoff_date !== null ? $cutoff_date : as_get_datetime_object( $this->month_in_seconds . ' seconds ago' );
$batch_size = ! is_null( $batch_size ) ? $batch_size : $this->batch_size;
$cutoff = ! is_null( $cutoff_date ) ? $cutoff_date : as_get_datetime_object( $this->month_in_seconds . ' seconds ago' );
$lifespan = time() - $cutoff->getTimestamp();
if ( empty( $statuses_to_purge ) ) {
$statuses_to_purge = $this->default_statuses_to_purge;
Expand Down Expand Up @@ -119,7 +119,7 @@ public function clean_actions( array $statuses_to_purge, DateTime $cutoff_date,
*/
private function delete_actions( array $actions_to_delete, $lifespan = null, $context = 'old' ) {
$deleted_actions = [];
if ( $lifespan === null ) {
if ( is_null( $lifespan ) ) {
$lifespan = $this->month_in_seconds;
}

Expand Down Expand Up @@ -209,7 +209,6 @@ public function mark_failures( $time_limit = 300 ) {
* Do all of the cleaning actions.
*
* @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes).
* @author Jeremy Pry
*/
public function clean( $time_limit = 300 ) {
$this->delete_old_actions();
Expand All @@ -220,7 +219,6 @@ public function clean( $time_limit = 300 ) {
/**
* Get the batch size for cleaning the queue.
*
* @author Jeremy Pry
* @return int
*/
protected function get_batch_size() {
Expand Down
5 changes: 3 additions & 2 deletions classes/ActionScheduler_QueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct( ActionScheduler_Store $store = null, ActionSchedule
*/
public function init() {

// phpcs:ignore WordPress.WP.CronInterval.CronSchedulesInterval
add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) );

// Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param.
Expand Down Expand Up @@ -163,8 +164,8 @@ protected function do_batch( $size = 100, $context = '' ) {
$processed_actions = 0;

foreach ( $claim->get_actions() as $action_id ) {
// bail if we lost the claim.
if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) {
// bail if we lost the claim
if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ), true ) ) {
break;
}
$this->process_action( $action_id, $context );
Expand Down
8 changes: 4 additions & 4 deletions classes/ActionScheduler_Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ActionScheduler_Versions {
* @param callable $initialization_callback Callback to initialize the version.
*/
public function register( $version_string, $initialization_callback ) {
if ( isset($this->versions[$version_string]) ) {
if ( isset($this->versions[ $version_string ]) ) {
return FALSE;
}
$this->versions[$version_string] = $initialization_callback;
$this->versions[ $version_string ] = $initialization_callback;
return TRUE;
}

Expand Down Expand Up @@ -50,10 +50,10 @@ public function latest_version() {
*/
public function latest_version_callback() {
$latest = $this->latest_version();
if ( empty($latest) || !isset($this->versions[$latest]) ) {
if ( empty($latest) || ! isset($this->versions[ $latest ]) ) {
return '__return_null';
}
return $this->versions[$latest];
return $this->versions[ $latest ];
}

/**
Expand Down
11 changes: 9 additions & 2 deletions classes/ActionScheduler_WPCommentCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public static function has_logs() {
* Attached to the migration complete hook 'action_scheduler/migration_complete'.
*/
public static function maybe_schedule_cleanup() {
if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) {
if ( (bool) get_comments( array(
'type' => ActionScheduler_wpCommentLogger::TYPE,
'number' => 1,
'fields' => 'ids',
) ) ) {
update_option( self::$has_logs_option_key, 'yes' );

if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
Expand All @@ -80,7 +84,10 @@ public static function maybe_schedule_cleanup() {
*/
public static function delete_all_action_comments() {
global $wpdb;
$wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) );
$wpdb->delete( $wpdb->comments, array(
'comment_type' => ActionScheduler_wpCommentLogger::TYPE,
'comment_agent' => ActionScheduler_wpCommentLogger::AGENT,
) );
delete_option( self::$has_logs_option_key );
}

Expand Down
2 changes: 1 addition & 1 deletion classes/WP_CLI/ActionScheduler_WPCLI_Clean_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function clean( $args, $assoc_args ) {

$batches_completed = 0;
$actions_deleted = 0;
$unlimited = $batches === 0;
$unlimited = 0 === $batches;
try {
$lifespan = as_get_datetime_object( $before );
} catch ( Exception $e ) {
Expand Down
Loading
Loading