How to deal with “method not found in class” warning for magically implemented methods?

后端 未结 4 1778
长发绾君心
长发绾君心 2020-12-05 09:08

I am sitting on a large codebase that contains several classes that expose functionality through magically implemented methods (using __call and __callSta

相关标签:
4条回答
  • 2020-12-05 09:40

    You can use a dynamic variable :

    $test = 'test';
    $chaine = $f->$test();   // no phpStorm flag, & the code works
    
    0 讨论(0)
  • 2020-12-05 09:48

    Rather than globally turning off inspections by downgrading the severity of the inspection, you can add a comment to the single line to ignore just that particular inspection.

        /** @noinspection PhpUndefinedMethodInspection */
        Assertion::NullOrAssertionDoesNotExist();
    
    0 讨论(0)
  • 2020-12-05 09:53

    Well, you can go to the preference menu, under Inspections, go to Undefined -> Undefined Method and check Downgrade severity if __magic methods are present.

    That would make the flag less severe, (instead of Warning, as Info), which would still give you a green light on your document check.

    There's nothing else I'm aware of aside from having @property or @method PHPDoc notations on the target class for every method that's likely to be used.

    enter image description here

    0 讨论(0)
  • 2020-12-05 09:54

    Building on what Madara said, I found it wouldn't downgrade down far enough for my liking no matter what severity I set it to, so I made a new Severity for undefined method that has no attributes whatsoever, and turned off the downgrade checkbox (see image below)

    If I hover over my magic methods now, it still brings up the popup message, but otherwise it doesn't distract me. One step better than just turning off inspection, because at least this way an actual undefined method can still be detected by hovering over the name

    0 讨论(0)
提交回复
热议问题