phpstan-drupal icon indicating copy to clipboard operation
phpstan-drupal copied to clipboard

Support checking method_exists for backward compatibility support

Open mglaman opened this issue 2 years ago • 3 comments

if (method_exists($this->moduleHandler, 'invokeAllWIth')) {
      $this->moduleHandler->invokeAllWith('mail', function (callable $hook, string $module) use (&$list) {
        $list[$module] = $this->moduleHandler->getName($module);
      });
    }
    else {
      foreach ($this->moduleHandler->getImplementations('mail') as $module) {
        $list[$module] = $this->moduleHandler->getName($module);
      }
    }

Let's see if the latter can not error. It currently does

mglaman avatar Jul 20 '22 13:07 mglaman

Actually, I'm not sure if this is possible since the error comes from phpstan-deprecation-rules

mglaman avatar Jul 20 '22 13:07 mglaman

Maybe there is some kind of hack that can be done with \PhpParser\NodeVisitorAbstract

mglaman avatar Jul 20 '22 14:07 mglaman

Can't be done. We need folks to use // @phpstan-ignore-next-line when providing backward compatibility support via if/else

mglaman avatar Jul 20 '22 15:07 mglaman

This is possible now that https://github.com/phpstan/phpstan-deprecation-rules/pull/99 has been merged, but depends on PHPStan 11.0.

mglaman avatar Jun 30 '23 14:06 mglaman

The issue was merged and it was released into the 1.10 branch, we can continue this without waiting for 1.11 :)

bbrala avatar Aug 05 '23 10:08 bbrala

Oh it did get released? I'll queue this up

mglaman avatar Aug 05 '23 14:08 mglaman

Since the pattern of the BC fixes in rector is pretty much done. Perhaps it is time to see if you can support that. Otherwise the Rector rule will need to be rewritten a little to support the ignore comment.

https://github.com/palantirnet/drupal-rector/pull/250

bbrala avatar Sep 23 '23 07:09 bbrala

I'll need to find some time for this. I did an investigation and the scope provided by PHPStan is not in-depth enough to make this kind of scope decisions. We don't know about the being processed. We may need drupal-rector to add the comment :/

mglaman avatar Sep 27 '23 19:09 mglaman

I feel like the the deprecated scope thingies should be able to do this. But only if the referred arguments on the deprecatedhelper class are anonimous functions. I understand that calls to other methods as arguments might not work. But anonimous functions should be doable?

bbrala avatar Sep 28 '23 05:09 bbrala

This isn't needed now that we have DeprecatedScopeResolver (#714)

mglaman avatar Feb 14 '24 04:02 mglaman