Repository navigation
RoundFunctionReturnTypeExtension supports types with ConstantScalar #3349
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
Open
ShioPy0101
wants to merge
26
commits into
phpstan:2.3.x
Choose a base branch
from
ShioPy0101:feature/add-type-round-function
base: 2.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+441
−33
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d2d350d
RoundFunctionReturnTypeExtension supports types with ConstantScalar
5b6cdac
fix RoundFunctionReturnTypeExtension
607719b
add tests
3b572ff
fix style
64c4ca7
add tests
54e3b01
fix
554c91e
refactor method
d0a2ff5
fix
138c672
fix
fa19d0e
fix : Return null directly for unsupported constant values
ShioPy0101 8f24d00
feat : Support RoundingMode in round constant evaluation
ShioPy0101 9e98ba5
test : Add RoundingMode constant evaluation tests
ShioPy0101 8088ed9
test : Test named RoundingMode argument
ShioPy0101 a5d46a6
test : Test RoundingMode union fallback
ShioPy0101 e20a253
refactor : round mode resolution
ShioPy0101 6502bc7
fix : coding style
ShioPy0101 4484897
feat : support constant numeric strings in non-strict mode
ShioPy0101 e34f023
fix : Cast numeric strings before constant evaluation
ShioPy0101 a6b95ae
test : numeric string constant evaluation
ShioPy0101 577dcc4
Fix coding style
ShioPy0101 a759e87
fix : round mode return type
ShioPy0101 92e8961
fix : narrow round mode return type
ShioPy0101 ae29831
fix : lint
ShioPy0101 5214d89
fix : keep round mode resolution compatible with PHP 7.4
ShioPy0101 dac9763
test : update PHP 7 numeric string tests
ShioPy0101 57d9187
fix : clarify RoundingMode fallback
ShioPy0101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why this mapping ?
This loose some case.
You could keep the original value when the Enum exists no ?
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.
I intentionally limited the mapping to the four RoundingMode cases that have direct equivalents in the legacy PHP_ROUND_HALF_* constants. The intent was to avoid making constant evaluation depend on the runtime availability of the RoundingMode enum.
For the remaining cases, I currently fall back to the existing return-type logic because they do not have a direct legacy constant mapping.
That said, I agree that this is an implementation limitation rather than a limitation of
RoundingModeitself. Preserving the enum case internally would allow all cases to be evaluated more precisely, so I think that would be a better direction.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.
I am still considering the best approach here. The README states that PHPStan's source code is developed on PHP 8.2, while the distributed package and PHAR are transformed to run on PHP 7.2 and higher. Given that, I would prefer to avoid making constant evaluation depend on the runtime availability of RoundingMode.
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.
Any suggestion @staabm ?