Skip to content

implement gettype() inference in TypeSpecifier#1611

Merged
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
staabm:gettype-specifying
Aug 12, 2022
Merged

implement gettype() inference in TypeSpecifier#1611
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
staabm:gettype-specifying

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Aug 12, 2022

@staabm staabm marked this pull request as ready for review August 12, 2022 07:26
Copy link
Copy Markdown
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 test some more scenarios.

  1. Three equal signs: if (gettype($x) === 'int')
  2. Negative context:
// $x is int|string|bool
if (gettype($x) === 'integer') {
    // assert int
    return;
}

// assert string|bool
  1. BooleanOr:
if (gettype($x) === 'string' || gettype($x) === 'integer') {
    // assert int|string
}

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Aug 12, 2022

great feedback thx. added tests and simplified the implementation based on it :)

@ondrejmirtes ondrejmirtes merged commit eb40029 into phpstan:1.8.x Aug 12, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@staabm staabm deleted the gettype-specifying branch August 12, 2022 13:55
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.

switch on gettype($var), then caseing on result, doesn't appear to take result into account

2 participants