-
Notifications
You must be signed in to change notification settings - Fork 590
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
2acc062
RoundFunctionReturnTypeExtension supports types with ConstantScalar
620b884
fix RoundFunctionReturnTypeExtension
c9dc80f
add tests
13eb139
fix style
89dc32e
add tests
e6c7c06
fix
83af3d5
refactor method
9ab5547
fix
77a4c85
fix
cb58585
fix : Return null directly for unsupported constant values
ShioPy0101 283b980
feat : Support RoundingMode in round constant evaluation
ShioPy0101 83b0304
test : Add RoundingMode constant evaluation tests
ShioPy0101 7d93f5d
test : Test named RoundingMode argument
ShioPy0101 aea5c96
test : Test RoundingMode union fallback
ShioPy0101 030b87c
refactor : round mode resolution
ShioPy0101 14fc602
fix : coding style
ShioPy0101 b8f635e
feat : support constant numeric strings in non-strict mode
ShioPy0101 8defbf0
fix : Cast numeric strings before constant evaluation
ShioPy0101 948fa39
test : numeric string constant evaluation
ShioPy0101 34344eb
Fix coding style
ShioPy0101 c371271
fix : round mode return type
ShioPy0101 5b3ac6d
fix : narrow round mode return type
ShioPy0101 6cce71b
fix : lint
ShioPy0101 54255ca
fix : keep round mode resolution compatible with PHP 7.4
ShioPy0101 c83de21
test : update PHP 7 numeric string tests
ShioPy0101 4b4b1dc
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 ?