Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Jul 26, 2025

Related to phpstan/phpstan#1452

but does not close it unfortunately since the %a is complicated.

@VincentLanglet VincentLanglet force-pushed the fix/1452 branch 2 times, most recently from 34d5241 to ffb94a4 Compare July 26, 2025 14:32
@VincentLanglet VincentLanglet requested a review from staabm July 26, 2025 14:52
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Please add regression test for https://phpstan.org/r/66bd52bc-2c1c-4b6e-ac27-57c2a7261982.

I'd like both a test in InvalidBinaryOperationRule, and assertType for %a.

@VincentLanglet VincentLanglet marked this pull request as draft September 10, 2025 10:54
@VincentLanglet
Copy link
Contributor Author

Please add regression test for phpstan.org/r/66bd52bc-2c1c-4b6e-ac27-57c2a7261982.

I'd like both a test in InvalidBinaryOperationRule, and assertType for %a.

This doesn't solve the InvalidBinaryOperationRule issue indeed, I just added a nsrt test to show why.

%a can return either a numeric string or (unknown), and we cannot know the DateTimeInterval is coming from a DateTime::diff call or was just instantiated with something like new DateInterval(...).

So this PR is still an improvement but doesn't solve the issue.

@VincentLanglet VincentLanglet marked this pull request as ready for review September 10, 2025 11:07
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

$constantStrings = $arg->getConstantStrings();
if (count($constantStrings) === 0) {
if ($arg->isNonEmptyString()->yes()) {
return new IntersectionType([new StringType(), new AccessoryNonEmptyStringType()]);
Copy link
Contributor

Choose a reason for hiding this comment

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

TypeCombinator::intersect() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We generally use directly IntersectionType for string type + accessories because it doesn't require any extra manipulation while intersect does lot of different things useless in this case

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.

4 participants