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 some other nullable parameters explicitly nullable #1220

Merged
merged 1 commit into from
Dec 6, 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
14 changes: 7 additions & 7 deletions classes/ActionScheduler_ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ class ActionScheduler_ActionFactory {
/**
* Return stored actions for given params.
*
* @param string $status The action's status in the data store.
* @param string $hook The hook to trigger when this action runs.
* @param array $args Args to pass to callbacks when the hook is triggered.
* @param ActionScheduler_Schedule $schedule The action's schedule.
* @param string $group A group to put the action in.
* @param string $status The action's status in the data store.
* @param string $hook The hook to trigger when this action runs.
* @param array $args Args to pass to callbacks when the hook is triggered.
* @param ActionScheduler_Schedule|null $schedule The action's schedule.
* @param string $group A group to put the action in.
* phpcs:ignore Squiz.Commenting.FunctionComment.ExtraParamComment
* @param int $priority The action priority.
* @param int $priority The action priority.
*
* @return ActionScheduler_Action An instance of the stored action.
*/
public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
public function get_stored_action( $status, $hook, array $args = array(), ?ActionScheduler_Schedule $schedule = null, $group = '' ) {
// The 6th parameter ($priority) is not formally declared in the method signature to maintain compatibility with
// third-party subclasses created before this param was added.
$priority = func_num_args() >= 6 ? (int) func_get_arg( 5 ) : 10;
Expand Down
2 changes: 1 addition & 1 deletion deprecated/ActionScheduler_Schedule_Deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class ActionScheduler_Schedule_Deprecated implements ActionScheduler_Sc
*
* @return DateTime|null
*/
public function next( DateTime $after = null ) {
public function next( ?DateTime $after = null ) {
if ( empty( $after ) ) {
$return_value = $this->get_date();
$replacement_method = 'get_date()';
Expand Down
2 changes: 1 addition & 1 deletion lib/cron-expression/CronExpression.php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is a 3rd party library, I wondered if we should be directly editing the files in it. It looks like it is abandoned, which might be why we've got it under version control rather than as a composer dependency. At some point, the package was forked, and the new maintainer is still active. The latest version does add the necessary nullable type, but the readme also says there are breaking changes since the version that we're using.

So in short, probably fine to edit this file, but perhaps we should look into updating this to a composer dependency using the latest version, both for PHP compatibility reasons, and also potentially security reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue for this: #1221

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @coreymckrill! 💯 Same thought crossed my mind when I was modifying that file but forgot to mention it in the description.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CronExpression
*
* @return CronExpression
*/
public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null)
public static function factory($expression, ?CronExpression_FieldFactory $fieldFactory = null)
{
$mappings = array(
'@yearly' => '0 0 1 1 *',
Expand Down
2 changes: 1 addition & 1 deletion tests/ActionScheduler_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function count(): int {
*
* @param null|\PHPUnit\Framework\TestResult $result Test result.
*/
public function run( PHPUnit\Framework\TestResult $result = null ): \PHPUnit\Framework\TestResult {
public function run( ?PHPUnit\Framework\TestResult $result = null ): \PHPUnit\Framework\TestResult {

if ( is_null( $result ) ) {
$result = $this->createResult();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/ActionScheduler_Mocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ActionScheduler_Mocker {
*
* @param null|ActionScheduler_Store $store Store instance.
*/
public static function get_queue_runner( ActionScheduler_Store $store = null ) {
public static function get_queue_runner( ?ActionScheduler_Store $store = null ) {

if ( ! $store ) {
$store = ActionScheduler_Store::instance();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/deprecated/ActionScheduler_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function count() {
*
* @param null|PHPUnit_Framework_TestResult $result Test result.
*/
public function run( PHPUnit_Framework_TestResult $result = null ) {
public function run( ?PHPUnit_Framework_TestResult $result = null ) {

if ( is_null( $result ) ) {
$result = $this->createResult();
Expand Down
Loading