Type Hinting issues in PHP 4 EAP 116.101

I'm trying to get used to using many of the cool functions of PHPStorm and am running into a problem with Singletons and Instances in Joomla 2.5

To start with, there is this code in the main index.php file:

$app = JFactory::getApplication('site');


$app->initialise();



The JFactory class has a static method, getApplication which takes a string specifying which child class of JApplication to use.  JFactory calls JApplication::getInstance and passes the child class, setting it's $application property to the return from JApplication.  It then returns that property.
The JApplication class has a static method, getInstance, which given given the child class, creates a new instance of that class and returns it.  In this case, it creates a JSite object.

Right clicking on the initialize call [$app->initialize();] and choosing 'Go To -> Declaration' takes me to the initialize method in JApplication.. so at least it is close to what I need.

I updated the code to:

// Instantiate the application.
 /** @var JSite this is to tell PHPSTORM that this is JSite instance */
 $app = JFactory::getApplication('site');


$app->initialise();

So in theory, PHPStorm should now know that $app is a JSite instance.  I went to file->invalidate caches and restarted just in case there was something there.
After that, I was still being sent to the JApplication::initialize declaration.  However, I noticed a warning notice for $var JSite that it could not find the class, and looking at the full error message it specifies PHPStorm has trouble with multiple class declarations.  Searching for JSite classes in the code, I found that there was a fake JSite class in a deep subdirectory for a special use scenario.  As a test, I deleted that class file and restarted.  Now I don't get the warning and a right click on JSite and selecting GoTo->declaration takes me to the correct JSite class file.  However, right clicking on the intialize call[$app->initialize();] still takes me to JApplication.

I also tried:

// Instantiate the application.
 /** @var JSite this is to tell PHPSTORM that this is JSite instance */
 $app = JFactory::getApplication('site');


// Initialise the application.
 /** @var JSite this is to tell PHPSTORM that this is JSite instance */
$app->initialise();


But it still takes me to JApplication.

So there are 2 questions/desires here:
1) Is there a way to specify/force a specific class definition to be the correct one?  Ie instead of having to delete the second JSite class file, is there a way I can tell PHPStorm which file to use?  For example:
/** @var JSite this is to tell PHPSTORM that this is JSite instance */
/** @class JSite include/site.php  this is to tell PHPSTORM that the JSite class comes from the include/site.php file */


And 2:
How can I force PHPSTORM to treat the $app variable as an instance of JSite and not JApplication?


3 comments
Comment actions Permalink

Hi Gary,

You are using a bit wrong (incomplete) syntax in your PHPDoc comment block. It is correct for class variables (as such comment will precede variable declaration), but not for local variables (as it can be applied to any variable in complex statement) -- you have to provide variable name as well, like this:

/** @var JSite $app Your description here */
$app = JFactory::getApplication('site');


0
Comment actions Permalink
Searching for JSite classes in the code, I found that there was a fake JSite class in a deep subdirectory for a special use scenario.  As a test, I deleted that class file and restarted.  Now I don't get the warning and a right click on JSite and selecting GoTo->declaration takes me to the correct JSite class file.

Instead of deleting you could right click on that file in Project View panel and use "Mark as Plain Text" command (plain text = no file analysis/syntax highlighting etc)

Related ticket: http://youtrack.jetbrains.com/issue/WI-2760

0
Comment actions Permalink

Perfect.  Thanks, adding that in solved my issue.  Now it's working great.

0

Please sign in to leave a comment.