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

Fix various linting errors. #1087

Merged
merged 15 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion classes/ActionScheduler_ActionClaim.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@
* Class ActionScheduler_ActionClaim
*/
class ActionScheduler_ActionClaim {
/** @var string */
private $id = '';
/** @var int[] */
private $action_ids = array();

/**
* Construct.
*
* @param string $id Claim ID.
* @param int[] $action_ids Action IDs.
*/
public function __construct( $id, array $action_ids ) {
$this->id = $id;
$this->action_ids = $action_ids;
}

/**
* Get claim ID.
*/
public function get_id() {
return $this->id;
}

/**
* Get IDs of claimed actions.
*/
public function get_actions() {
return $this->action_ids;
}
}

37 changes: 22 additions & 15 deletions classes/ActionScheduler_AdminView.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/
class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {

/** @var null|self */
private static $admin_view = NULL;

/** @var string */
private static $screen_id = 'tools_page_action-scheduler';

/** @var ActionScheduler_ListTable */
Expand All @@ -28,6 +30,8 @@ public static function instance() {
}

/**
* Initialize.
*
* @codeCoverageIgnore
*/
public function init() {
Expand All @@ -45,6 +49,9 @@ public function init() {
}
}

/**
* Print system status report.
*/
public function system_status_report() {
$table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
$table->render();
Expand Down Expand Up @@ -119,20 +126,20 @@ protected function get_list_table() {
*/
public function maybe_check_pastdue_actions() {

# Filter to prevent checking actions (ex: inappropriate user).
// Filter to prevent checking actions (ex: inappropriate user).
if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
return;
}

# Get last check transient.
// Get last check transient.
$last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );

# If transient exists, we're within interval, so bail.
// If transient exists, we're within interval, so bail.
if ( ! empty( $last_check ) ) {
return;
}

# Perform the check.
// Perform the check.
$this->check_pastdue_actions();
}

Expand All @@ -143,9 +150,9 @@ public function maybe_check_pastdue_actions() {
*/
protected function check_pastdue_actions() {

# Set thresholds.
$threshold_seconds = ( int ) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
$threshold_min = ( int ) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
// Set thresholds.
$threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
$threshold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );

// Set fallback value for past-due actions count.
$num_pastdue_actions = 0;
Expand All @@ -158,24 +165,24 @@ protected function check_pastdue_actions() {
return;
}

# Scheduled actions query arguments.
// Scheduled actions query arguments.
$query_args = array(
'date' => as_get_datetime_object( time() - $threshold_seconds ),
'status' => ActionScheduler_Store::STATUS_PENDING,
'per_page' => $threshold_min,
);

# If no third-party preempted, run default check.
// If no third-party preempted, run default check.
if ( is_null( $check ) ) {
$store = ActionScheduler_Store::instance();
$num_pastdue_actions = ( int ) $store->query_actions( $query_args, 'count' );
$num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );

# Check if past-due actions count is greater than or equal to threshold.
// Check if past-due actions count is greater than or equal to threshold.
$check = ( $num_pastdue_actions >= $threshold_min );
$check = ( bool ) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
$check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
}

# If check failed, set transient and abort.
// If check failed, set transient and abort.
if ( ! boolval( $check ) ) {
$interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );
Expand All @@ -189,7 +196,7 @@ protected function check_pastdue_actions() {
'order' => 'asc',
), admin_url( 'tools.php' ) );

# Print notice.
// Print notice.
echo '<div class="notice notice-warning"><p>';
printf(
// translators: 1) is the number of affected actions, 2) is a link to an admin screen.
Expand All @@ -204,7 +211,7 @@ protected function check_pastdue_actions() {
);
echo '</p></div>';

# Facilitate third-parties to evaluate and print notices.
// Facilitate third-parties to evaluate and print notices.
do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
}

Expand Down
9 changes: 4 additions & 5 deletions classes/ActionScheduler_AsyncRequest_QueueRunner.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php
/**
* ActionScheduler_AsyncRequest_QueueRunner
*/

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -35,7 +32,9 @@ class ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request {
protected $action = 'async_request_queue_runner';

/**
* Initiate new async request
* Initiate new async request.
*
* @param ActionScheduler_Store $store Store object.
*/
public function __construct( ActionScheduler_Store $store ) {
parent::__construct();
Expand All @@ -49,7 +48,7 @@ public function __construct( ActionScheduler_Store $store ) {
* if there are still pending actions after completing a queue in this request.
*/
protected function handle() {
do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context
do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context.

$sleep_seconds = $this->get_sleep_seconds();

Expand Down
2 changes: 1 addition & 1 deletion classes/ActionScheduler_DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function free_memory() {
$wp_object_cache->cache = array();

if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important
call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important!
}
}

Expand Down
4 changes: 2 additions & 2 deletions classes/ActionScheduler_DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getTimestamp() {
*
* This represents a fixed offset instead of a timezone setting.
*
* @param $offset
* @param string|int $offset UTC offset value.
*/
public function setUtcOffset( $offset ) {
$this->utcOffset = intval( $offset );
Expand All @@ -54,7 +54,7 @@ public function getOffset() {
/**
* Set the TimeZone associated with the DateTime
*
* @param DateTimeZone $timezone
* @param DateTimeZone $timezone Timezone object.
*
* @return static
* @link http://php.net/manual/en/datetime.settimezone.php
Expand Down
29 changes: 28 additions & 1 deletion classes/ActionScheduler_FatalErrorMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ class ActionScheduler_FatalErrorMonitor {
private $claim = NULL;
/** @var ActionScheduler_Store */
private $store = NULL;
/** @var int */
private $action_id = 0;

/**
* Construct.
*
* @param ActionScheduler_Store $store Action store.
*/
public function __construct( ActionScheduler_Store $store ) {
$this->store = $store;
}

/**
* Start monitoring.
*
* @param ActionScheduler_ActionClaim $claim Claimed actions.
*/
public function attach( ActionScheduler_ActionClaim $claim ) {
$this->claim = $claim;
add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
Expand All @@ -23,6 +34,9 @@ public function attach( ActionScheduler_ActionClaim $claim ) {
add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
}

/**
* Stop monitoring.
*/
public function detach() {
$this->claim = NULL;
$this->untrack_action();
Expand All @@ -33,16 +47,29 @@ public function detach() {
remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
}

/**
* Track specified action.
*
* @param int $action_id Action ID to track.
*/
public function track_current_action( $action_id ) {
$this->action_id = $action_id;
}

/**
* Un-track action.
*/
public function untrack_action() {
$this->action_id = 0;
}

/**
* Handle unexpected shutdown.
*/
public function handle_unexpected_shutdown() {
if ( $error = error_get_last() ) {
$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) ) {
$this->store->mark_failure( $this->action_id );
Expand Down
2 changes: 2 additions & 0 deletions classes/ActionScheduler_InvalidActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ActionScheduler_InvalidActionException extends \InvalidArgumentException i
* Create a new exception when the action's schedule cannot be fetched.
*
* @param string $action_id The action ID with bad args.
* @param mixed $schedule Passed schedule.
* @return static
*/
public static function from_schedule( $action_id, $schedule ) {
Expand All @@ -32,6 +33,7 @@ public static function from_schedule( $action_id, $schedule ) {
* @author Jeremy Pry
*
* @param string $action_id The action ID with bad args.
* @param mixed $args Passed arguments.
* @return static
*/
public static function from_decoding_args( $action_id, $args = array() ) {
Expand Down
Loading
Loading