Fixed PHP 8.5 deprecated code by Knit pay/main#244
Conversation
Suggested by Gemini Code Assist The null coalescing operator ?? in the method body is redundant. Since $price is already nullable, you can directly assign it. This simplifies the code and makes it consistent with set_discount_amount in the same file.
Simplify PaymentMethodsCollection::get by removing the explicit null !== $id check and relying on array_key_exists($id, $this->items) to determine presence. This cleans up the conditional logic; note that if $id is null and the collection has an empty-string key, the method may now return that entry (previously it would have returned null).
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing compatibility with PHP 8.0 and later by introducing explicit nullable type hints for parameters that can accept Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a deprecation in PHP 8.5 by adding nullable types to method parameters that have a default value of null. The changes are consistent across multiple files and improve the code's forward-compatibility. The simplification in set_unit_price is also a good improvement. I have one suggestion to improve documentation consistency.
There was a problem hiding this comment.
Pull request overview
This pull request fixes PHP 8.4+ deprecation warnings related to implicit nullable type hints. In PHP 8.4+, typed parameters that have a default value of null must be explicitly marked as nullable using the ? prefix. The PR updates method signatures across multiple payment-related classes to add the nullable type hint prefix.
Changes:
- Updated method signatures to use explicit nullable type hints (
?Typeinstead ofType = null) - Removed redundant null coalescing operator in
PaymentLine::set_unit_price() - Applied fixes consistently across Payment, PaymentInfo, PaymentLine, PaymentLines, Customer, and Address classes
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Payments/PaymentLines.php | Added nullable type hint to from_json() method parameter |
| src/Payments/PaymentLine.php | Added nullable type hints to set_unit_price() and set_discount_amount() methods, removed redundant null coalescing |
| src/Payments/PaymentInfo.php | Added nullable type hints to set_lines() and set_shipping_amount() methods |
| src/Payments/Payment.php | Added nullable type hint to set_failure_reason() method |
| src/Customer.php | Added nullable type hint to set_name() method |
| src/Address.php | Added nullable type hint to set_name() method |
Update PHPDoc for set_discount_amount to indicate the $discount_amount parameter can be null (Money|null), matching the method signature (?Money $discount_amount = null). This keeps documentation consistent with the code and avoids static analysis/IDE warnings.
See