phpstan: Call to an undefined method RdKafka\Producer::purge()

Bug report

With the newest phpstan version i am getting Call to undefined method for a few methods:

  • Consumer|KafkaConsumer::offsetsForTimes
  • Consumer|KafkaConsumer::queryWatermarkOffsets
  • Producer::purge
  • Producer::flush

Also the function newTopic that is in the base class claims to return Rdkafka\Topic, but depending on your class (consumer / producer) will actually return Rdkafka\ConsumerTopic or Rdkafka\ProducerTopic.

Code snippet that reproduces the problem

This happens in the master of this project: https://github.com/jobcloud/php-kafka-lib

Expected output

From what i can see from the stubs, the functions are there. The return type might need a different fix, it is not added in the stubs because of 5.x compatibility,
it is just present in the comment section.

Thanks in advance for helping out with this 🙇

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Thank you for figuring this out 😃

Sry for the confusion, it seems that the stubs are indeed, not a 100% correct, i created a PR to fix this: https://github.com/JetBrains/phpstorm-stubs/pull/897

I will create a PR for phpstan-src afterwards to use the newest stubs as well, once it is merged. I think this happened from 0.12.32 onward because the stubs were added / changed

Yes, you can debug in ondrejmirtes/better-reflection why the method gets lost 😃 Ideally as a new test case in https://github.com/ondrejmirtes/BetterReflection/blob/master/test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php 😃

If BetterReflection reports the method correctly then the problem will be here in phpstan-src.