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

RoundFunctionReturnTypeExtension supports types with ConstantScalar #3349

Open
wants to merge 9 commits into
base: 1.12.x
Choose a base branch
from

Conversation

Shio3001
Copy link

Returns a constant when $num parameter and option of the round function are constants.

In this case , the conventional type is returned.

  • $num parameter is a numeric string.
  • $num parameter union contains a numeric string.
  • round() option is not a constant.

@Shio3001 Shio3001 changed the title ReturnFunctionReturnTypeExtension supports types with ConstantScalar RoundFunctionReturnTypeExtension supports types with ConstantScalar Aug 26, 2024
@Shio3001 Shio3001 force-pushed the feature/add-type-round-function branch from 465733b to 276f471 Compare August 26, 2024 05:47
@staabm
Copy link
Contributor

staabm commented Aug 26, 2024

which problem does this change solve? whats your real world use-case?

}

if (count($returnValueTypes) >= 1) {
return TypeCombinator::union(...array_map(static fn ($l) => $l, $returnValueTypes));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return TypeCombinator::union(...array_map(static fn ($l) => $l, $returnValueTypes));
return TypeCombinator::union(...$returnValueTypes);

@zonuexe
Copy link
Contributor

zonuexe commented Aug 26, 2024

@staabm

I'm sure there are several use cases for this, but one I quickly spotted in my private code is the following pattern, which uses $last_page for some logic other than just printing it.

Ideally it would be even more useful if a float range type was implemented, but I feel like this is worthwhile enough on its own.

const MAX = 1000;
const PER_PAGE = 30;
$last_page = (int)floor(MAX / PER_PAGE);

https://phpstan.org/r/b583dc30-3b4e-4b1f-af60-713159f43309

@Shio3001 Shio3001 force-pushed the feature/add-type-round-function branch from 98e7404 to e4ad097 Compare August 28, 2024 01:08
@Shio3001 Shio3001 changed the base branch from 1.11.x to 1.12.x August 28, 2024 01:09
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.

3 participants