PhpStorm: Code inspection issues

Hello!

Here is a piece of code as for PhpStorm 5.0 EAP 120.177:


foreach ($suitedControllers as $controller)
{
    $routes = $controller->routes;
    $activeRoute = $routes[$controller->activeRouteIndex];
    $currentRoute = $activeRoute->buildChain($routes, $controller->activeRouteIndex);
    while(!is_null($currentRoute))
    {
        $callback = $currentRoute->getCallback();
        $controller->$callback();
        $currentRoute = $currentRoute->getChild();
    }
    if($currentRoute->getView()->isBase())
    {
        $renderer = new Renderer($currentRoute->getView()->getFileName());
        $controller->beforeRender($renderer);
        $output = $renderer->render($controller->data);
    }
}


Items colored red are marked by code inspector as "Method not found in class null" warning, though all of them are existing public methods of class Route. Method "buildChain" has the following signature: public function Route::buildChain($relativeRoutes, $thisIndex) Route.

Another strange thing is that in PhpStorm 4.0.3 I have totally different picture:

foreach ($suitedControllers as $controller)
{
    $routes = $controller->routes;
    $activeRoute = $routes[$controller->activeRouteIndex];
    $currentRoute = $activeRoute->buildChain($routes, $controller->activeRouteIndex);
    while(!is_null($currentRoute))
    {
        $callback = $currentRoute->getCallback();
        $controller->$callback();
        $currentRoute = $currentRoute->getChild();
    }
    if($currentRoute->getView()->isBase())
    {
        $renderer = new Renderer($currentRoute->getView()->getFileName());
        $controller->beforeRender($renderer);
        $output = $renderer->render($controller->data);
    }
}


Red items from above are inspected ok, but now pink items get same warning as the red ones before. Method "getView" has the following signature: public function Route::getView() View

Any thoughts?

Thanks in advance.

6 comments
Comment actions Permalink

I think I found the reason why it happens like that in PhpStorm 5.0 EAP 120.177: is_null() is the hot spot!!! If  I remove the check for null everything starts to behave as expected.  Seems like code inspector is kind of paranoic in this case. Especially  considering that all actions with $currentRoute are performed if it's NOT null.

0
Comment actions Permalink

Hi there,

Yes, this is known behaviour (method lost in chain), there are few tickets for that ... but I still would recommend submitting a separate ticket on Issue Tracker with your code example and explanation -- maybe it will give some clues to speed up fixing it for everyone (standalone/complete code example is  extremely welcome).

0
Comment actions Permalink

I'm not quite sure I understand how "method lost in chain" could be applied here. I just checked and can tell that $currentRoute acts just as expected to do a normal object of the Route class BEFORE while(!is_null($currentRoute)) block, but INSIDE of  the block and all the way AFTER it things goes weird - no intellisense, code inspector warnings...

0
Comment actions Permalink

v5 EAP build has quite a few bugs in code inspector (because of changes in engine or whatever), so a lot of code that was perfectly fine in v4 now marked as invalid in v5 (hey, it's first public build, no big surprise here). Few examples:


As for "method lost in chain" -- I was referring to $currentRoute->getView()->getFileName() example. In v4 IDE sometimes marked subsequent (2nd, 3rd in chain) method call as undefined for no obvious reason, while the same code splitted into 2 instructions (via usage of intermediate variable) showed no error.

In any case -- it's a bug no matter how you call it.

0
Comment actions Permalink

Ok, seems like I have to wait for more polished build to come... Till then stick to 4.0.3... However thanks for explaination

Keep up your hard work, guys!

0
Comment actions Permalink

I'm working with version 4.0.3 but the code analysis system seems to work VERY slow.
When I change something in my code, the code analysis signals some errors, but there are none.  But the red lines just don't get removed automaticly.

When I remove all the code and paste it again in the screen the red lines are gone.  But I don't know what the problem might be.

0

Please sign in to leave a comment.