Skip to content

use conditional parameter for is_a() via stub#1306

Closed
staabm wants to merge 12 commits into
phpstan:1.7.xfrom
staabm:is-a-cond
Closed

use conditional parameter for is_a() via stub#1306
staabm wants to merge 12 commits into
phpstan:1.7.xfrom
staabm:is-a-cond

Conversation

@staabm

@staabm staabm commented May 12, 2022

Copy link
Copy Markdown
Contributor

Comment thread stubs/core.stub Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

stub taken 1:1 from psalm

@staabm staabm May 12, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

update: psalm was missing the type for $allow_string, which will be added with vimeo/psalm#7951

@ondrejmirtes

Copy link
Copy Markdown
Member

Please read the title of the linked issue: is_a: "if third argument is false then do not allow string in first argument"

Which means that there should be a new test in CallToFunctionParametersRuleTest (or ImpossibleCheckTypeFunctionCallRuleTest, that depends) that reports a new error here https://phpstan.org/r/44b40ab5-7c7f-4ced-8048-e084d3d63f1d on line 10.

@staabm

staabm commented May 12, 2022

Copy link
Copy Markdown
Contributor Author

yeah, it seems the initially reported bug in 4371 is different from the one I had in phpstan/phpstan#4371 (comment)

but I am fine, with also covering the original issue here then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is no longer considered "fine" because Foo is not a subclass of Throwable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But also please test Foo::class (which is different thanks to namespace resolution), the class isn't final so a subclass might implement Throwable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm I guess you mean I should test class-string<Foo> as a parameter not Foo::class.. at least thats what I did for now.. see added tests at the end of this file

@staabm staabm marked this pull request as draft May 13, 2022 07:34
Comment thread tests/PHPStan/Rules/Comparison/data/bug-4371.php Outdated

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this gets a few rough edges, therefore I pushed the current development state and hope for feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm I guess you mean I should test class-string<Foo> as a parameter not Foo::class.. at least thats what I did for now.. see added tests at the end of this file

@staabm staabm May 13, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

with 3e955af I dropped the conditional return type stub again, as I am no longer sure its worth to report about string vs. class-string type errors for $class.. might be tedious.

since we already have extensions for is_a in place the stub itself was nevertheless only partly usefull, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

because I dropped this early-return, I had to compensate a few false positives in the IsAFunctionTypeSpecifyingExtension - added a few early returns.

@staabm staabm May 13, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

especially this condition is pretty ugly .. would love feedback on how to improve it.

at first I only had the $classType instanceof ClassStringType part, but later on needed to add !$classType instanceof GenericClassStringType to prevent regressions of existing tests

@ondrejmirtes

Copy link
Copy Markdown
Member

This is already quite messy again :/ I think the stub solved a problem so I really don't want to have it reverted here 3e955af.

But this is truly a minor problem. I'd rather be if you worked on the NamedArgumentsHelper improvements :) Thanks.

@staabm

staabm commented May 13, 2022

Copy link
Copy Markdown
Contributor Author

I started workin on this topic, because we had a production issue, which would be great if beeing covered by phpstan the next time.

it looked easy at first, but it seems I have no luck in picking topics to work on, since most of the time it turns into walking thru rabbit holes, like we can see here :-/.

will do NamedArguments stuff, when free time allows again.

@ondrejmirtes

Copy link
Copy Markdown
Member

You can just send the conditional stub in a separate PR alongside with the tests as you initially did, without marking phpstan/phpstan#4371 as closing :)

@ondrejmirtes

Copy link
Copy Markdown
Member

Basically this commit 6bbb2a6 :)

@ondrejmirtes

Copy link
Copy Markdown
Member

I have no luck in picking topics to work on

That's normal, I just spent several hours today trying to clean up something about named arguments and I'm not happy with the result either. The combination of php-8-stubs, phpstorm-stubs and php-8-stubs is a mess in some situations. And PHP itself is a mess too :)

@staabm staabm deleted the is-a-cond branch May 13, 2022 13:38
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.

is_a: if third argument is false then do not allow string in first argument

3 participants