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

Make nullable parameters explicitly nullable #1205

Merged
merged 1 commit into from
Nov 1, 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
6 changes: 3 additions & 3 deletions classes/ActionScheduler_QueueCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class ActionScheduler_QueueCleaner {
/**
* ActionScheduler_QueueCleaner constructor.
*
* @param ActionScheduler_Store $store The store instance.
* @param int $batch_size The batch size.
* @param ActionScheduler_Store|null $store The store instance.
* @param int $batch_size The batch size.
*/
public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) {
public function __construct( ?ActionScheduler_Store $store = null, $batch_size = 20 ) {
$this->store = $store ? $store : ActionScheduler_Store::instance();
$this->batch_size = $batch_size;
}
Expand Down
10 changes: 5 additions & 5 deletions classes/ActionScheduler_QueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public static function instance() {
/**
* ActionScheduler_QueueRunner constructor.
*
* @param ActionScheduler_Store $store Store object.
* @param ActionScheduler_FatalErrorMonitor $monitor Monitor object.
* @param ActionScheduler_QueueCleaner $cleaner Cleaner object.
* @param ActionScheduler_AsyncRequest_QueueRunner $async_request Async request runner object.
* @param ActionScheduler_Store|null $store Store object.
* @param ActionScheduler_FatalErrorMonitor|null $monitor Monitor object.
* @param ActionScheduler_QueueCleaner|null $cleaner Cleaner object.
* @param ActionScheduler_AsyncRequest_QueueRunner|null $async_request Async request runner object.
*/
public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null, ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
public function __construct( ?ActionScheduler_Store $store = null, ?ActionScheduler_FatalErrorMonitor $monitor = null, ?ActionScheduler_QueueCleaner $cleaner = null, ?ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
parent::__construct( $store, $monitor, $cleaner );

if ( is_null( $async_request ) ) {
Expand Down
8 changes: 4 additions & 4 deletions classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class ActionScheduler_WPCLI_QueueRunner extends ActionScheduler_Abstract_QueueRu
/**
* ActionScheduler_WPCLI_QueueRunner constructor.
*
* @param ActionScheduler_Store $store Store object.
* @param ActionScheduler_FatalErrorMonitor $monitor Monitor object.
* @param ActionScheduler_QueueCleaner $cleaner Cleaner object.
* @param ActionScheduler_Store|null $store Store object.
* @param ActionScheduler_FatalErrorMonitor|null $monitor Monitor object.
* @param ActionScheduler_QueueCleaner|null $cleaner Cleaner object.
*
* @throws Exception When this is not run within WP CLI.
*/
public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) {
public function __construct( ?ActionScheduler_Store $store = null, ?ActionScheduler_FatalErrorMonitor $monitor = null, ?ActionScheduler_QueueCleaner $cleaner = null ) {
if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
/* translators: %s php class name */
throw new Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) );
Expand Down
8 changes: 4 additions & 4 deletions classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
/**
* ActionScheduler_Abstract_QueueRunner constructor.
*
* @param ActionScheduler_Store $store Store object.
* @param ActionScheduler_FatalErrorMonitor $monitor Monitor object.
* @param ActionScheduler_QueueCleaner $cleaner Cleaner object.
* @param ActionScheduler_Store|null $store Store object.
* @param ActionScheduler_FatalErrorMonitor|null $monitor Monitor object.
* @param ActionScheduler_QueueCleaner|null $cleaner Cleaner object.
*/
public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) {
public function __construct( ?ActionScheduler_Store $store = null, ?ActionScheduler_FatalErrorMonitor $monitor = null, ?ActionScheduler_QueueCleaner $cleaner = null ) {

$this->created_time = microtime( true );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ActionScheduler_Abstract_RecurringSchedule extends ActionSchedule
* @param mixed $recurrence The data used to determine the schedule's recurrence.
* @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
*/
public function __construct( DateTime $date, $recurrence, DateTime $first = null ) {
public function __construct( DateTime $date, $recurrence, ?DateTime $first = null ) {
parent::__construct( $date );
$this->first_date = empty( $first ) ? $date : $first;
$this->recurrence = $recurrence;
Expand Down
10 changes: 5 additions & 5 deletions classes/abstracts/ActionScheduler_Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public static function instance() {
/**
* Create log entry.
*
* @param string $action_id Action ID.
* @param string $message Log message.
* @param DateTime $date Log date.
* @param string $action_id Action ID.
* @param string $message Log message.
* @param DateTime|null $date Log date.
*
* @return string The log entry ID
*/
abstract public function log( $action_id, $message, DateTime $date = null );
abstract public function log( $action_id, $message, ?DateTime $date = null );

/**
* Get action's log entry.
Expand Down Expand Up @@ -215,7 +215,7 @@ public function log_ignored_action( $action_id, $context = '' ) {
* @param string $action_id Action ID.
* @param null|Exception $exception The exception which occurred when fetching the action. NULL by default for backward compatibility.
*/
public function log_failed_fetch_action( $action_id, Exception $exception = null ) {
public function log_failed_fetch_action( $action_id, ?Exception $exception = null ) {

if ( ! is_null( $exception ) ) {
/* translators: %s: exception message */
Expand Down
20 changes: 10 additions & 10 deletions classes/abstracts/ActionScheduler_Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
*
* @return int The action ID
*/
abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = null );
abstract public function save_action( ActionScheduler_Action $action, ?DateTime $scheduled_date = null );

/**
* Get action.
Expand Down Expand Up @@ -202,14 +202,14 @@ abstract public function get_date( $action_id );
/**
* Make a claim.
*
* @param int $max_actions Maximum number of actions to claim.
* @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now.
* @param array $hooks Claim only actions with a hook or hooks.
* @param string $group Claim only actions in the given group.
* @param int $max_actions Maximum number of actions to claim.
* @param DateTime|null $before_date Claim only actions schedule before the given date. Defaults to now.
* @param array $hooks Claim only actions with a hook or hooks.
* @param string $group Claim only actions in the given group.
*
* @return ActionScheduler_ActionClaim
*/
abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' );
abstract public function stake_claim( $max_actions = 10, ?DateTime $before_date = null, $hooks = array(), $group = '' );

/**
* Get claim count.
Expand Down Expand Up @@ -298,7 +298,7 @@ protected function validate_sql_comparator( $comparison_operator ) {
* @param null|DateTime $scheduled_date Action's schedule date (optional).
* @return string
*/
protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = null ) {
protected function get_scheduled_date_string( ActionScheduler_Action $action, ?DateTime $scheduled_date = null ) {
$next = is_null( $scheduled_date ) ? $action->get_schedule()->get_date() : $scheduled_date;

if ( ! $next ) {
Expand All @@ -313,11 +313,11 @@ protected function get_scheduled_date_string( ActionScheduler_Action $action, Da
/**
* Get the time MySQL formatted date/time string for an action's (next) scheduled date.
*
* @param ActionScheduler_Action $action Action.
* @param null|DateTime $scheduled_date Action's scheduled date (optional).
* @param ActionScheduler_Action|null $action Action.
barryhughes marked this conversation as resolved.
Show resolved Hide resolved
* @param null|DateTime $scheduled_date Action's scheduled date (optional).
* @return string
*/
protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = null ) {
protected function get_scheduled_date_string_local( ActionScheduler_Action $action, ?DateTime $scheduled_date = null ) {
$next = is_null( $scheduled_date ) ? $action->get_schedule()->get_date() : $scheduled_date;

if ( ! $next ) {
Expand Down
2 changes: 1 addition & 1 deletion classes/actions/ActionScheduler_Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ActionScheduler_Action {
* @param null|ActionScheduler_Schedule $schedule Action's schedule.
* @param string $group Action's group.
*/
public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
public function __construct( $hook, array $args = array(), ?ActionScheduler_Schedule $schedule = null, $group = '' ) {
$schedule = empty( $schedule ) ? new ActionScheduler_NullSchedule() : $schedule;
$this->set_hook( $hook );
$this->set_schedule( $schedule );
Expand Down
2 changes: 1 addition & 1 deletion classes/actions/ActionScheduler_CanceledAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ActionScheduler_CanceledAction extends ActionScheduler_FinishedAction {
* @param null|ActionScheduler_Schedule $schedule Action's schedule.
* @param string $group Action's group.
*/
public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
public function __construct( $hook, array $args = array(), ?ActionScheduler_Schedule $schedule = null, $group = '' ) {
parent::__construct( $hook, $args, $schedule, $group );
if ( is_null( $schedule ) ) {
$this->set_schedule( new ActionScheduler_NullSchedule() );
Expand Down
2 changes: 1 addition & 1 deletion classes/actions/ActionScheduler_NullAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ActionScheduler_NullAction extends ActionScheduler_Action {
* @param mixed[] $args Action arguments.
* @param null|ActionScheduler_Schedule $schedule Action schedule.
*/
public function __construct( $hook = '', array $args = array(), ActionScheduler_Schedule $schedule = null ) {
public function __construct( $hook = '', array $args = array(), ?ActionScheduler_Schedule $schedule = null ) {
$this->set_schedule( new ActionScheduler_NullSchedule() );
}

Expand Down
8 changes: 4 additions & 4 deletions classes/data-stores/ActionScheduler_DBLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class ActionScheduler_DBLogger extends ActionScheduler_Logger {
/**
* Add a record to an action log.
*
* @param int $action_id Action ID.
* @param string $message Message to be saved in the log entry.
* @param DateTime $date Timestamp of the log entry.
* @param int $action_id Action ID.
* @param string $message Message to be saved in the log entry.
* @param DateTime|null $date Timestamp of the log entry.
*
* @return int The log entry ID.
*/
public function log( $action_id, $message, DateTime $date = null ) {
public function log( $action_id, $message, ?DateTime $date = null ) {
if ( empty( $date ) ) {
$date = as_get_datetime_object();
} else {
Expand Down
32 changes: 16 additions & 16 deletions classes/data-stores/ActionScheduler_DBStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ public function init() {
* Save an action, checks if this is a unique action before actually saving.
*
* @param ActionScheduler_Action $action Action object.
* @param \DateTime $scheduled_date Optional schedule date. Default null.
* @param DateTime|null $scheduled_date Optional schedule date. Default null.
*
* @return int Action ID.
* @throws RuntimeException Throws exception when saving the action fails.
*/
public function save_unique_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null ) {
public function save_unique_action( ActionScheduler_Action $action, ?DateTime $scheduled_date = null ) {
return $this->save_action_to_db( $action, $scheduled_date, true );
}

/**
* Save an action. Can save duplicate action as well, prefer using `save_unique_action` instead.
*
* @param ActionScheduler_Action $action Action object.
* @param \DateTime $scheduled_date Optional schedule date. Default null.
* @param DateTime|null $scheduled_date Optional schedule date. Default null.
*
* @return int Action ID.
* @throws RuntimeException Throws exception when saving the action fails.
*/
public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null ) {
public function save_action( ActionScheduler_Action $action, ?DateTime $scheduled_date = null ) {
return $this->save_action_to_db( $action, $scheduled_date, false );
}

Expand All @@ -91,7 +91,7 @@ public function save_action( ActionScheduler_Action $action, \DateTime $schedule
* @return int Action ID.
* @throws \RuntimeException Throws exception when saving the action fails.
*/
private function save_action_to_db( ActionScheduler_Action $action, DateTime $date = null, $unique = false ) {
private function save_action_to_db( ActionScheduler_Action $action, ?DateTime $date = null, $unique = false ) {
global $wpdb;

try {
Expand Down Expand Up @@ -847,14 +847,14 @@ protected function get_date_gmt( $action_id ) {
/**
* Stake a claim on actions.
*
* @param int $max_actions Maximum number of action to include in claim.
* @param \DateTime $before_date Jobs must be schedule before this date. Defaults to now.
* @param array $hooks Hooks to filter for.
* @param string $group Group to filter for.
* @param int $max_actions Maximum number of action to include in claim.
* @param DateTime|null $before_date Jobs must be schedule before this date. Defaults to now.
* @param array $hooks Hooks to filter for.
* @param string $group Group to filter for.
*
* @return ActionScheduler_ActionClaim
*/
public function stake_claim( $max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
public function stake_claim( $max_actions = 10, ?DateTime $before_date = null, $hooks = array(), $group = '' ) {
$claim_id = $this->generate_claim_id();

$this->claim_before_date = $before_date;
Expand Down Expand Up @@ -914,17 +914,17 @@ public function get_claim_filter( $filter_name ) {
/**
* Mark actions claimed.
*
* @param string $claim_id Claim Id.
* @param int $limit Number of action to include in claim.
* @param \DateTime $before_date Should use UTC timezone.
* @param array $hooks Hooks to filter for.
* @param string $group Group to filter for.
* @param string $claim_id Claim Id.
* @param int $limit Number of action to include in claim.
* @param DateTime|null $before_date Should use UTC timezone.
* @param array $hooks Hooks to filter for.
* @param string $group Group to filter for.
*
* @return int The number of actions that were claimed.
* @throws \InvalidArgumentException Throws InvalidArgumentException if group doesn't exist.
* @throws \RuntimeException Throws RuntimeException if unable to claim action.
*/
protected function claim_actions( $claim_id, $limit, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
protected function claim_actions( $claim_id, $limit, ?DateTime $before_date = null, $hooks = array(), $group = '' ) {
/**
* Global.
*
Expand Down
10 changes: 5 additions & 5 deletions classes/data-stores/ActionScheduler_HybridStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class ActionScheduler_HybridStore extends Store {
/**
* ActionScheduler_HybridStore constructor.
*
* @param Config $config Migration config object.
* @param Config|null $config Migration config object.
*/
public function __construct( Config $config = null ) {
public function __construct( ?Config $config = null ) {
$this->demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 );
if ( empty( $config ) ) {
$config = Controller::instance()->get_migration_config_object();
Expand Down Expand Up @@ -240,7 +240,7 @@ public function action_counts() {
*
* @return ActionScheduler_ActionClaim
*/
public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
public function stake_claim( $max_actions = 10, ?DateTime $before_date = null, $hooks = array(), $group = '' ) {
$claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group );

$claimed_actions = $claim->get_actions();
Expand All @@ -266,11 +266,11 @@ private function migrate( $action_ids ) {
* Save an action to the primary store.
*
* @param ActionScheduler_Action $action Action object to be saved.
* @param DateTime $date Optional. Schedule date. Default null.
* @param DateTime|null $date Optional. Schedule date. Default null.
*
* @return int The action ID
*/
public function save_action( ActionScheduler_Action $action, DateTime $date = null ) {
public function save_action( ActionScheduler_Action $action, ?DateTime $date = null ) {
return $this->primary_store->save_action( $action, $date );
}

Expand Down
8 changes: 4 additions & 4 deletions classes/data-stores/ActionScheduler_wpCommentLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
/**
* Create log entry.
*
* @param string $action_id Action ID.
* @param string $message Action log's message.
* @param DateTime $date Action log's timestamp.
* @param string $action_id Action ID.
* @param string $message Action log's message.
* @param DateTime|null $date Action log's timestamp.
*
* @return string The log entry ID
*/
public function log( $action_id, $message, DateTime $date = null ) {
public function log( $action_id, $message, ?DateTime $date = null ) {
if ( empty( $date ) ) {
$date = as_get_datetime_object();
} else {
Expand Down
Loading
Loading