-
Notifications
You must be signed in to change notification settings - Fork 7
fix: XMLBuilder phpstan support #5
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @13DaGGeR, 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!
Summary of Changes
This pull request addresses a PHPStan warning related to the toString() method not being recognized on the XMLBuilder class after calling setRootTag() on an ArrayExporter instance. To resolve this, I've updated the return types of the disableRootTag() and setRootTag() methods in the XMLBuilder class from self to static. Additionally, I've updated the references to self::DEFAULT_ROOT to static::DEFAULT_ROOT within the getRootTag() and getFieldName() methods to ensure proper inheritance and avoid potential issues in derived classes.
Highlights
- PHPStan Fix: The primary goal is to eliminate the PHPStan warning regarding the undefined
toString()method onXMLBuilder. - Return Type Update: The return types of
disableRootTag()andsetRootTag()methods are changed fromselftostaticto improve type hinting and method chaining. - Static Property Access: Replaced
self::DEFAULT_ROOTwithstatic::DEFAULT_ROOTingetRootTag()andgetFieldName()for better inheritance support.
Changelog
- src/XMLBuilder.php
- Changed return type of
disableRootTag()fromselftostatic(lines 52, 54). - Changed return type of
setRootTag()fromselftostatic(lines 64, 66). - Replaced
self::DEFAULT_ROOTwithstatic::DEFAULT_ROOTingetRootTag()(line 153). - Replaced
self::DEFAULT_ROOTwithstatic::DEFAULT_ROOTingetFieldName()(line 173).
- Changed return type of
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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.
A static call, a type so clear,
Banishes warnings, dispels all fear.
From 'self' to 'static', the change is made,
PHPStan's approval, a code parade.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request addresses a phpstan warning related to the return type of the setRootTag method in the XMLBuilder class. The changes involve updating the return type from self to static and adjusting the usage of self::DEFAULT_ROOT to static::DEFAULT_ROOT. This ensures that the correct class is returned when chaining methods, resolving the phpstan issue. The changes look good overall.
Summary of Findings
- Return type of
setRootTaganddisableRootTag: The return type ofsetRootTaganddisableRootTagwas changed fromselftostaticto allow for proper method chaining and to avoid phpstan warnings. This is a good change as it allows for more flexibility in the API. - Usage of
self::DEFAULT_ROOT: The usage ofself::DEFAULT_ROOTwas changed tostatic::DEFAULT_ROOTto allow for proper inheritance and to avoid potential issues with child classes overriding theDEFAULT_ROOTconstant. This is a good change as it makes the code more robust.
Merge Readiness
The code changes appear to correctly address the phpstan warning and improve the flexibility of the API. I recommend merging this pull request after verifying that the changes do not introduce any regressions. I am unable to directly approve the pull request, and users should have others review and approve this code before merging.
| { | ||
| return is_string($this->rootTag) ? $this->rootTag : self::DEFAULT_ROOT; | ||
| return is_string($this->rootTag) ? $this->rootTag : static::DEFAULT_ROOT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thanks! |
Problem:
the following code:
Will result in phpstan warning: