vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 659 forks source link

Getting MismatchingDocblockParamType error even when there's no docblock #11013

Open toviet opened 4 months ago

toviet commented 4 months ago

Hi,

Since upgrading to v5.2.1, Psalm seems to show these weird MismatchingDocblockParamType errors on my codes which have no docblock at all.

For example

$featureResult = $this->cache->get(
        $key,
        function (ItemInterface $item) use ($feature, $dataCache) {
            $item->expiresAfter(Time::SIX_HOURS_IN_SECONDS);

            return $this->compileFeatureResult($feature, $dataCache);

And I get:

Service.php:173:27: MismatchingDocblockParamType: Parameter $item has wrong type 'Psr\Cache\CacheItemInterface', should be 'Symfony\Contracts\Cache\ItemInterface' (see https://psalm.dev/141)

Even more odd that this only happens on a selected of files which use similar caching pattern, but not all of them.

Does anyone know what's the issue here?

orklah commented 4 months ago

Can you check what the docblock of the get() function on cache is?

toviet commented 4 months ago

The cache is drawn from Symfony Memcache Adapter (https://symfony.com/doc/current/components/cache/adapters/memcached_adapter.html) so should be the standard. We have other places where the same adapter is used but having no Psalm error at all.