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

This PR fixes a few deprecation warnings thrown when used with PHP 8.4 #72

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Nov 30, 2024

Q A
Bugfix?
Breaks BC?
New feature? ✔️
Issues N/A
Docs PR N/A

When using this library with PHP 8.4, I noticed some deprecation warnings like this:

Deprecated: Spiral\RoadRunner\Jobs\Consumer::__construct(): Implicitly marking parameter $receivedTaskFactory as nullable is deprecated, the explicit nullable type must be used instead

This is due to this change https://wiki.php.net/rfc/deprecate-implicitly-nullable-types, in which initializing a method argument with value null is deprecated if the type is not explicitly nullable.

Summary by CodeRabbit

  • New Features

    • Enhanced flexibility in method parameters across multiple classes, allowing for nullable options.
  • Bug Fixes

    • Improved type safety in constructors and method signatures, ensuring more robust handling of optional parameters.

Copy link

coderabbitai bot commented Nov 30, 2024

Walkthrough

The pull request introduces nullable type declarations across several classes and interfaces, enhancing flexibility in parameter handling. The Consumer, Queue, QueueInterface, and PreparedTask classes have updated their method and constructor signatures to accept null values for specific parameters, without altering existing logic or functionality. This change aims to improve type safety and clarity in the codebase, ensuring that parameters can explicitly be null while maintaining default behaviors when necessary.

Changes

File Change Summary
src/Consumer.php Updated constructor parameters from WorkerInterface and ReceivedTaskFactoryInterface to ?WorkerInterface and ?ReceivedTaskFactoryInterface.
src/Queue.php Updated push and create method signatures from OptionsInterface $options = null to ?OptionsInterface $options = null.
src/QueueInterface.php Updated create method signature from OptionsInterface $options = null to ?OptionsInterface $options = null.
src/Task/PreparedTask.php Updated constructor parameter from OptionsInterface $options = null to ?OptionsInterface $options = null, ensuring $options can be null.

Poem

In the code where bunnies hop,
Nullable types make errors stop.
With options clear and choices bright,
Our tasks now dance in pure delight!
So let us cheer, both near and far,
For safer code is our shining star! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/Queue.php (1)

Line range hint 93-95: Remove redundant null check on $this->options.

The null check on $this->options is unnecessary since:

  1. $this->options is initialized in the constructor and is never null
  2. The property is not marked as nullable in the class definition
-        if ($this->options !== null && \method_exists($this->options, 'mergeOptional')) {
+        if (\method_exists($this->options, 'mergeOptional')) {
             /** @var OptionsInterface $options */
             $options = $this->options->mergeOptional($options);
         }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a1777e6 and 6ea6a8a.

📒 Files selected for processing (4)
  • src/Consumer.php (1 hunks)
  • src/Queue.php (2 hunks)
  • src/QueueInterface.php (1 hunks)
  • src/Task/PreparedTask.php (1 hunks)
🔇 Additional comments (6)
src/QueueInterface.php (1)

49-49: LGTM! Explicit nullable type declaration added correctly.

The change from OptionsInterface $options = null to ?OptionsInterface $options = null properly addresses the PHP 8.4 deprecation warning while maintaining backward compatibility.

Let's verify all implementing classes have been updated:

✅ Verification successful

Implementation matches interface - change is properly synchronized

The implementing class Queue correctly uses the same nullable type declaration ?OptionsInterface $options = null as the interface. Additionally, other usages of this parameter type in the codebase (like in Jobs::create) also follow the same pattern, showing consistency across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all classes implementing QueueInterface
ast-grep --pattern 'class $_ implements $$$QueueInterface$$$'

Length of output: 63


Script:

#!/bin/bash
# Let's try a different approach using ripgrep to find QueueInterface implementations
rg "implements.*QueueInterface" -l

Length of output: 50


Script:

#!/bin/bash
# Also search for class definitions that might have QueueInterface on a separate line
rg "class.*implements" -A 2 

Length of output: 2854


Script:

#!/bin/bash
# Let's also check the actual interface definition to understand its namespace
rg "interface QueueInterface"

Length of output: 79


Script:

#!/bin/bash
# Let's check the implementation in Queue.php to verify if it matches the interface
rg "create.*OptionsInterface" src/Queue.php -A 3

Length of output: 50


Script:

#!/bin/bash
# Let's try to get the full create method implementation from Queue.php
ast-grep --pattern 'public function create($$$)'  src/Queue.php

Length of output: 64


Script:

#!/bin/bash
# Also check the method signature directly
rg "public function create" src/Queue.php -A 1

Length of output: 98


Script:

#!/bin/bash
# Let's get more context around the create method implementation
rg "public function create" src/Queue.php -B 1 -A 5

Length of output: 305


Script:

#!/bin/bash
# Also check if there are any other files that might contain this method signature
rg "function create.*OptionsInterface" -A 2

Length of output: 388

src/Consumer.php (1)

41-42: LGTM! Explicit nullable types with proper default handling.

The changes correctly address PHP 8.4 deprecation warnings by:

  1. Making nullable types explicit for both parameters
  2. Maintaining existing behavior with default implementations
src/Task/PreparedTask.php (1)

28-28: LGTM! Explicit nullable type with proper fallback.

The change correctly addresses PHP 8.4 deprecation warnings while maintaining the existing behavior of defaulting to a new Options instance when null is provided.

src/Queue.php (3)

75-75: LGTM! Explicit nullable type declaration maintains backward compatibility.

The change from OptionsInterface $options = null to ?OptionsInterface $options = null properly addresses the PHP 8.4 deprecation warning while preserving the existing behavior and compatibility with RoadRunner 1.x.


90-90: LGTM! Explicit nullable type declaration is correctly applied.

The change from OptionsInterface $options = null to ?OptionsInterface $options = null properly addresses the PHP 8.4 deprecation warning.


75-75: Verify consistent nullable type declarations across the codebase.

Let's ensure that all related interfaces and implementations have been updated with explicit nullable types for the $options parameter.

Also applies to: 90-90

✅ Verification successful

Let me gather more information to verify the consistency of nullable type declarations.


Let me check the actual Queue class implementation to complete the verification.


Nullable type declarations are consistent across the codebase

The nullable type declarations for the $options parameter are consistent between:

  • The interface QueueInterface in withDefaultOptions(?OptionsInterface $options) and create(..., ?OptionsInterface $options = null)
  • The implementation in Queue class for both methods
  • The constructor parameter in Queue class
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for method signatures that might need similar updates
ast-grep --pattern 'function $_(
  $_,
  $_,
  OptionsInterface $options = null
)'

# Search for the updated interface definitions
rg "interface.*QueueInterface"

Length of output: 165


Script:

#!/bin/bash
# Search for method signatures with OptionsInterface parameter
rg "OptionsInterface.+\$options" -A 1

# Search specifically for Queue class implementations
ast-grep --pattern 'class $_ implements QueueInterface'

# Look for method signatures in the interface
cat src/QueueInterface.php

Length of output: 2065


Script:

#!/bin/bash
# Check the Queue class implementation
cat src/Queue.php

Length of output: 4716

@msmakouz
Copy link
Member

@acelaya Thanks!

@msmakouz msmakouz merged commit 52ae1fb into roadrunner-php:4.x Nov 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants