Accounting for class prefixing?

Hello everyone,

A few days ago I downloaded PHPStorm for the first time. Currently I'm still using the trial version but at this rate I'm most definitely going to purchase a subscription. So far it's been really complete and has made PHP development a lot more pleasant.

However, there's something I haven't yet managed to figure out. And I was wondering if PHPStorm supports in some way, shape or form accounting for Class prefixes.

I'm developing an application for the Invision Community suite, for those of you who know what I'm talking about, you can probably see where I'm going. They had independent development of external applications in mind when they developed the framework so they accounted for this by monkey patching the classes when they're autoloaded such that the classes may be overloaded safely.

Here's the description of the process by the developers themselves, as well as some code snippets to understand the process:
https://invisioncommunity.com/developers/docs/general/autoloading-classes-r6/

These are a few fragments of my code:

As you can see, the classes are declared starting with an underscore. So when I attempt to call methods or access properties that I know exist for a given class, PHPStorm raises a warning about undefined methods and properties. 

So I was wondering if there is the possibility of accounting for this by having PHPStorm lookup the methods of "_ClassName" when I call a method from a "ClassName" object.

Thank you for your time.

0
2 comments

Hi there,

Sounds like PHP's class alias should do the job here.

The idea is: if you define "Application" as an alias for "_Application" class then calling "Application::someStaticMethod()" should resolve the same as "_Application::someStaticMethod()".

Such code is for IDE eyes only so can be placed in some file and named appropriately (e.g. "PROJECT_ROOT/.phpstorm/class-aliases.php" or alike)

1

Thank you so much for your answer. This has worked perfectly. It's extremely helpful and I can tell it's going to save me a fair amount of headaches.

In a way, it's a "shame" that this framework has got so many classes because I'm going to have to do this manually for each one, but it's a lot better than not having anything all.

Cheers!

0

Please sign in to leave a comment.