Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Throwable::getCode() method return type #767

Closed
wants to merge 1 commit into from
Closed

Fix Throwable::getCode() method return type #767

wants to merge 1 commit into from

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Nov 13, 2021

Fixes: phpstan/phpstan#6001

Based on #680 from @akondas.

My contribution here is mostly my stubborness :)

@ondrejmirtes
Copy link
Member

Hi, this would be too annoying. In 99 % of cases it returns an int. With this change you'd require people on levels < 9 to suddenly also handle string in places where it can't occur. Although it's nice to do that from type safety perspective, I also often make pragmatic choices.

What I'd accept is this method to return a BenevolentUnionType of int|string. You can't express that in PHPDoc, it'd need dynamic return type extension.

@herndlm
Copy link
Contributor Author

herndlm commented Nov 16, 2021

Hi, this would be too annoying. In 99 % of cases it returns an int. With this change you'd require people on levels < 9 to suddenly also handle string in places where it can't occur. Although it's nice to do that from type safety perspective, I also often make pragmatic choices.

What I'd accept is this method to return a BenevolentUnionType of int|string. You can't express that in PHPDoc, it'd need dynamic return type extension.

Ok thx, I can take a look at that.
Just one thing - I might have misunderstood you, but as it currently is typed with returning mixed wouldn't this change remove some of the annoyances? :)
UPDATE: I definitely misunderstood you, the important part is "< 9" I guess. Well, I'll take a look at the extension then next

@ondrejmirtes
Copy link
Member

it currently is typed with returning mixed wouldn't this change remove some of the annoyances? :)

Would you mind to show them as phpstan.org example?

@herndlm
Copy link
Contributor Author

herndlm commented Nov 16, 2021

Would you mind to show them as phpstan.org example?

I was misunderstanding you. The type is mixed, but this is irrelevant in phpstan < 9 as you said, see https://phpstan.org/r/ef5e659e-83ce-4157-8117-5e7d818188ad

So only ”annoying" for level 9 users. Sorry and thx again :)

@herndlm herndlm deleted the fix-throwable-get-code-return-type branch November 16, 2021 13:14
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.

Throwable::getCode() should return int|string instead of mixed
2 participants