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: PHPCompatibility, Generic #1095

Closed
wants to merge 15 commits into from
Closed
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
16 changes: 13 additions & 3 deletions classes/ActionScheduler_ActionClaim.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
* Class ActionScheduler_ActionClaim
*/
class ActionScheduler_ActionClaim {
/** @var string */

/**
* Claim ID.
*
* @var string
*/
private $id = '';
/** @var int[] */

/**
* Action IDs that have been claimed.
*
* @var int[]
*/
private $action_ids = array();

/**
Expand All @@ -16,7 +26,7 @@ class ActionScheduler_ActionClaim {
* @param int[] $action_ids Action IDs.
*/
public function __construct( $id, array $action_ids ) {
$this->id = $id;
$this->id = $id;
$this->action_ids = $action_ids;
}

Expand Down
30 changes: 22 additions & 8 deletions classes/ActionScheduler_AdminView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,42 @@

/**
* Class ActionScheduler_AdminView
*
* @codeCoverageIgnore
*/
class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {

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

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

/** @var ActionScheduler_ListTable */
/**
* ListTable instance.
*
* @var ActionScheduler_ListTable
*/
protected $list_table;

/**
* Instance.
*
* @return ActionScheduler_AdminView
* @codeCoverageIgnore
*/
public static function instance() {

if ( empty( self::$admin_view ) ) {
$class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
$class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
self::$admin_view = new $class();
}

Expand Down Expand Up @@ -85,7 +100,7 @@ public function register_menu() {
'action-scheduler',
array( $this, 'render_admin_ui' )
);
add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) );
}

/**
Expand Down Expand Up @@ -145,8 +160,6 @@ public function maybe_check_pastdue_actions() {

/**
* Check past-due actions, and print notice.
*
* @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511)
*/
protected function check_pastdue_actions() {

Expand Down Expand Up @@ -175,6 +188,7 @@ protected function check_pastdue_actions() {
// 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' );

// Check if past-due actions count is greater than or equal to threshold.
Expand Down
2 changes: 1 addition & 1 deletion classes/ActionScheduler_Compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function raise_memory_limit() {
* @param int $limit The time limit in seconds.
*/
public static function raise_time_limit( $limit = 0 ) {
$limit = (int) $limit;
$limit = (int) $limit;
$max_execution_time = (int) ini_get( 'max_execution_time' );

// If the max execution time is already set to zero (unlimited), there is no reason to make a further change.
Expand Down
24 changes: 19 additions & 5 deletions classes/ActionScheduler_DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,36 @@ class ActionScheduler_DataController {
const DATASTORE_CLASS = 'ActionScheduler_DBStore';

/** Logger data store class name. */
const LOGGER_CLASS = 'ActionScheduler_DBLogger';
const LOGGER_CLASS = 'ActionScheduler_DBLogger';

/** Migration status option name. */
const STATUS_FLAG = 'action_scheduler_migration_status';
const STATUS_FLAG = 'action_scheduler_migration_status';

/** Migration status option value. */
const STATUS_COMPLETE = 'complete';

/** Migration minimum required PHP version. */
const MIN_PHP_VERSION = '5.5';

/** @var ActionScheduler_DataController */
/**
* Instance.
*
* @var ActionScheduler_DataController
*/
private static $instance;

/** @var int */
/**
* Number of seconds to pause before resuming.
*
* @var int
*/
private static $sleep_time = 0;

/** @var int */
/**
* Number of ticks to free memory.
*
* @var int
*/
private static $free_ticks = 50;

/**
Expand Down Expand Up @@ -137,6 +149,8 @@ public static function free_memory() {
\WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) );

/**
* Globals.
*
* @var $wpdb \wpdb
* @var $wp_object_cache \WP_Object_Cache
*/
Expand Down
39 changes: 27 additions & 12 deletions classes/ActionScheduler_FatalErrorMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
* Class ActionScheduler_FatalErrorMonitor
*/
class ActionScheduler_FatalErrorMonitor {
/** @var ActionScheduler_ActionClaim */
private $claim = NULL;
/** @var ActionScheduler_Store */
private $store = NULL;
/** @var int */

/**
* Claim instance.
*
* @var ActionScheduler_ActionClaim
*/
private $claim = null;

/**
* Store instance.
*
* @var ActionScheduler_Store
*/
private $store = null;

/**
* Action's ID.
*
* @var int
*/
private $action_id = 0;

/**
Expand All @@ -29,22 +44,22 @@ public function attach( ActionScheduler_ActionClaim $claim ) {
$this->claim = $claim;
add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 );
add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
}

/**
* Stop monitoring.
*/
public function detach() {
$this->claim = NULL;
$this->claim = null;
$this->untrack_action();
remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 );
remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
}

/**
Expand Down
23 changes: 14 additions & 9 deletions classes/ActionScheduler_ListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/**
* Implements the admin view of the actions.
*
* @codeCoverageIgnore
*/
class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
Expand Down Expand Up @@ -49,9 +50,10 @@ class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
protected $runner;

/**
* Bulk actions. The key of the array is the method name of the implementation:
* Bulk actions.
*
* bulk_<key>(array $ids, string $sql_in).
* The key of the array is the method name of the implementation:
* bulk_<key>(array $ids, string $sql_in).
*
* See the comments in the parent class for further details
*
Expand Down Expand Up @@ -224,7 +226,7 @@ private static function human_interval( $interval, $periods_to_include = 2 ) {
return __( 'Now!', 'action-scheduler' );
}

$output = '';
$output = '';
$num_time_periods = count( self::$time_periods );

for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < $num_time_periods && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) {
Expand All @@ -235,8 +237,10 @@ private static function human_interval( $interval, $periods_to_include = 2 ) {
if ( ! empty( $output ) ) {
$output .= ' ';
}
$output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );

$output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
$seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds'];

$periods_included++;
}
}
Expand Down Expand Up @@ -362,7 +366,7 @@ public function display_admin_notices() {
if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) {
$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' ),
'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).', 'action-scheduler' ),
);
$this->recreate_tables();
parent::display_admin_notices();
Expand Down Expand Up @@ -393,7 +397,7 @@ public function display_admin_notices() {

// No lock set or lock expired.
if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) {
$in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
$in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
/* translators: %s: process URL */
$async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress &raquo;</a>', 'action-scheduler' ), esc_url( $in_progress_url ) );
} else {
Expand All @@ -412,8 +416,9 @@ public function display_admin_notices() {
if ( is_array( $notification ) ) {
delete_transient( 'action_scheduler_admin_notice' );

$action = $this->store->fetch_action( $notification['action_id'] );
$action = $this->store->fetch_action( $notification['action_id'] );
$action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>';

if ( 1 == $notification['success'] ) {
$class = 'updated';
switch ( $notification['row_action_type'] ) {
Expand Down Expand Up @@ -574,10 +579,10 @@ protected function process_row_action( $action_id, $row_action_type ) {
$this->store->cancel_action( $action_id );
break;
}
$success = 1;
$success = 1;
$error_message = '';
} catch ( Exception $e ) {
$success = 0;
$success = 0;
$error_message = $e->getMessage();
}

Expand Down
6 changes: 6 additions & 0 deletions classes/ActionScheduler_LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
class ActionScheduler_LogEntry {

/**
* Action's ID.
*
* @var int $action_id
*/
protected $action_id = '';

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

/**
* Log date and time.
*
* @var Datetime $date
*/
protected $date;
Expand Down
1 change: 1 addition & 0 deletions classes/ActionScheduler_OptionLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* for up-to a given duration.
*
* Class ActionScheduler_OptionLock
*
* @since 3.0.0
*/
class ActionScheduler_OptionLock extends ActionScheduler_Lock {
Expand Down
Loading
Loading