Skip to content

declare Countable stub#1027

Closed
staabm wants to merge 5 commits intophpstan:masterfrom
staabm:positive-int
Closed

declare Countable stub#1027
staabm wants to merge 5 commits intophpstan:masterfrom
staabm:positive-int

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 21, 2022

this should make https://phpstan.org/r/d06ab690-e37c-4aab-ad37-e250d3d29a29 error as expected

-> it does not.. seems to be a different bug.. but still the added type-inference should make sense as is

@staabm staabm marked this pull request as ready for review February 21, 2022 09:26
@BackEndTea
Copy link
Contributor

I understand that count should normally return a positive int. But I suspect there are usecases for having it be negative

@staabm
Copy link
Contributor Author

staabm commented Feb 21, 2022

@BackEndTea thx for the feedback.

I agree there might be code in the wild which returns magic values like -1 or similar, but IMO this code is violating the count-contract (IMO a class implementing Countable should behave like the native count() function.)

@ondrejmirtes
Copy link
Member

I'd merge this but the build failures block me.

@staabm
Copy link
Contributor Author

staabm commented Feb 22, 2022

I'd merge this but the build failures block me.

didn't realized the errors. fixed.

$this->analyse([__DIR__ . '/data/bug-3997.php'], [
[
'Return type (string) of method Bug3997\Ipsum::count() should be compatible with return type (int) of method Countable::count()',
'Return type (int) of method Bug3997\Baz::count() should be covariant with return type (int<0, max>) of method Countable::count()',
Copy link
Member

Choose a reason for hiding this comment

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

Oh, this is actually an annoying BC break :( Can you please do a similar thing that was done here phpstan/phpstan-doctrine#290 and have the Countable stub be applied only for bleedingEdge? Putting Countable stub into a separate file called Countable.stub and configure it only in bleedingEdge.neon should be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fixed, I think.

@ondrejmirtes
Copy link
Member

I did an easier version and used your tests, thanks :) 1e77aed

@staabm staabm deleted the positive-int branch February 23, 2022 10:36
@staabm
Copy link
Contributor Author

staabm commented Feb 23, 2022

Ohh indeed.. didn't thought it could be that easy ;-)

Thank you

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