Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 1, 2026

re-use types introduced in #4841

removes a few TypeCombinator::union calls

grafik

since TypeCombinator::union is the slowest path we have right now, this is a great thing to have.

grafik

@staabm staabm marked this pull request as ready for review February 1, 2026 10:55
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

return $truthy;
}

public static function getNonIntArrayKeyValueType(): Type
Copy link
Contributor

Choose a reason for hiding this comment

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

I think name could be challenged for 3 reasons:

  • Existing methods are called falsey (and truthy) and not getFalseyType.
    Should it be something like nonIntArrayKeyValue ?

  • I had trouble ton understand what was IntArrayKeyValueType and nonIntArrayKeyValueType. Should another name be use ? With offset maybe ?

  • nonInt is not really valid since we was using $offsetType->isInteger()->yes() for getIntArrayKeyValueType and getNonIntArrayKeyValueType in the other case, including the MAYBE case. So it's more a general case.

Maybe something like

generalOffsetAccessible()
intOffsetAccessible()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great suggestions. I was not happy with the names either.

I now have a mix of your suggestions and my own idea.

wdyt?

Copy link
Contributor

@VincentLanglet VincentLanglet Feb 2, 2026

Choose a reason for hiding this comment

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

You'll have to rename the variable inside the method too.

It's just unclear why you're calling this OffsetValueType.

If I have $foo[$bar] = $baz,

  • bar is the key/index/offset/dim type
  • baz is the value type

You seems to call $foo the offsetValue. Is it something often used in PHPStan codebase ?
I assume it's related to HasOffsetValueType but here we are doing nothing with the Value, so it's more HasOffsetType no ? Like hasIntOffset.

Copy link
Contributor Author

@staabm staabm Feb 2, 2026

Choose a reason for hiding this comment

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

the method is returning the Type for $baz (speaking from your example) - thats why I call it OffsetValueType

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I thought it was returning the type for $foo.
With the idea that $string[$int] is allowed but not $string[$string].

I'm surprise by the fact it returns $baz cause then, it shouldn't forbid scalar... (?)

Copy link
Contributor Author

@staabm staabm Feb 2, 2026

Choose a reason for hiding this comment

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

ohh you are right. its $foo not $baz and thats the wrong term as you already pointed out

@ondrejmirtes ondrejmirtes merged commit d4511b1 into phpstan:2.1.x Feb 2, 2026
633 of 639 checks passed
@ondrejmirtes
Copy link
Member

Nice, thank you!

@staabm staabm deleted the re-uuse branch February 2, 2026 17:23
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