Skip to content

Conversation

Wosi
Copy link

@Wosi Wosi commented Nov 12, 2019

@ondrejmirtes
Copy link
Member

This needs a test, preferably inside ImpossibleCheckTypeFunctionCallRuleTest.

@Wosi Wosi force-pushed the fixes/1482_method_exists_with_string branch from bad1c12 to 07020b2 Compare November 12, 2019 10:32
@Wosi
Copy link
Author

Wosi commented Nov 12, 2019

@ondrejmirtes
I added a call to method_exists with a string variable as first parameter in check-type-function-call.php and don't expect to see an error for this line.
Is it OK this way?

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.

Yes, the test is fine :)

Copy link
Member

Choose a reason for hiding this comment

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

Try (new StringType())->isSuperTypeOf($objectType)->yes() instead. This will also account for unions of constant strings and is generally better.

Copy link
Author

Choose a reason for hiding this comment

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

If I do this then a call like this method_exists(MethodExists::class, 'undefinedMethod') will no longer produce the error

Call to function method_exists() with 'CheckTypeFunctionCa…' and 'undefinedMethod' will always evaluate to false.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's correct. Please write another test for that. See phpstan/phpstan#1267 it's also reported.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if I got you right. I changed the type check according to your request and removed the expected errors for this call:

method_exists(MethodExists::class, 'undefinedMethod')

@Wosi Wosi force-pushed the fixes/1482_method_exists_with_string branch from 07020b2 to bfd7b65 Compare November 12, 2019 11:28
@Wosi Wosi requested a review from ondrejmirtes November 12, 2019 11:38
@ondrejmirtes
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants