Question on PhpStorm Advanced Metadata


Assume the following code/files

.phpstorm.meta.php
<?php

namespace PHPSTORM_META {                                                 // we want to avoid the pollution

$STATIC_METHOD_TYPES = [                                              // we make sections for scopes

    \Load::Component('') => [                                      // call to match

        'Filter' instanceof \FilterComponent,

    ],
    \Component::component('') => [

        'Filter' instanceof \FilterComponent,

    ]

];

}



filter.php

<?php

class
FilterComponent extends Component
{

    function getDate($returnStyle = null){

 
        $date = strtotime('Today');
 
    
 
        if ($returnStyle == 'mysql') {
            return date('Y-m-d 00:00:00', $date);
        } else if($returnStyle
== 'java') {
            return date('Y-m-d\T00:00:00', $date);
        } else {
            return $date;
}

    }

}



component.php

<?php

class Component {
 
    protected function component($objName){
        return Load::component($objName, $this->controller);
    }
}



testUsage.php

<?php

class TestComponent extends Component {

    function test() {

        $date = $this->component('Filter')->getDate('java');
        $date = Load::component('Filter')->getDate('java');

    }

}



In the testUsage.php file, the first call in the test function, $this->component('Filter')->getDate('java'); PhpStorm will say "cannot find declaration to go to" for getDate()

However it will work in the 2nd call, Load::component('Filter')->getDate('java');

Is there any possible way for me to get this to work with the 1st call?

2 comments
Comment actions Permalink

Hi there,

ATM PhpStorm supports static factories only (

"Load::component()")


I'm not sure about "
$this->component()"
(how exactly it will work/what syntax has to be used) but such support for not-static factories was added in most recent v9 EAP build. Unfortunately there is no documentation yet available (but expected soon).

In any case -- it will be supported in v9 when it will be released (some point in July).
0
Comment actions Permalink

Actually -- documentation was updated: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata

Just those example metadata file uses truff like "$factory->component()" while you have "$this->component()" -- not sure how it supposed to be declared here...

0

Please sign in to leave a comment.