1

I am working with a custom PHP framework and would like to generate a .phpstorm.meta.php file for it.

The factory methods I have are of the following syntax:

<?php

// Models
$project = Loader::model('Transform', 'Project'); 
    // returns instance of \Framework\Base\Model
$user = Loader::model('Base', 'User'); 
    // returns instance of \Framework\Base\Model
$asset = Loader::model('Transform', 'Asset'); 
    // returns instance of \Framework\Hunk\Transform\Model\Asset

// Helpers
$router = Loader::service('Router', 'Router'); 
    // returns instance of \Framework\Hunk\Router\Service\Router
$helper = Loader::service('Transform', 'Helper');
    // returns instance of \Framework\Hunk\Transform\Service\Helper

What I've tried so far with no luck:

<?php
namespace PHPSTORM_META {
    /** @noinspection PhpUnusedLocalVariableInspection */
    /** @noinspection PhpIllegalArrayKeyTypeInspection */
    /** @noinspection PhpLanguageLevelInspection */
    $STATIC_METHOD_TYPES = [
        \Framework\Loader::model('Transform', '') => [
            '' = '@',
            'Product' instanceof \Framework\Base\Model,
            'Asset' instanceof \Framework\Hunk\Transform\Model\Asset,
            'Step' instanceof \Framework\Base\Model,
            'Stage' instanceof \Framework\Base\Model,
        ],
        \Framework\Loader::model('Hansel', '') => [
            '' = '@',
            'User' instanceof \Framework\Base\Model,
        ],
        \Framework\Loader::service('Transform', '') => [
            '' = '@',
            'Helper' instanceof \Framework\Hunk\Transform\Service\Helper,
        ],
        \Framework\Loader::service('Router', '') => [
            '' = '@',
            'Router' instanceof \Framework\Hunk\Router\Service\Router,
        ],
    ];

}

How can I get PhpStorm to recognize multiple arguments for the factories in the meta file so it can properly do autocompletion and declaration finding?

I have looked over the phpstorm meta docs, but they don't seem to be very in-depth.

1 Answer 1

2

Well, as an author of a said .phpstorm.meta.php I can quickly give you a definitive answer.

As of 2016.3, PhpStorm only matches FIRST argument value, and this is hardcoded.

You see, this entire functionality has evolved from very particular feature request and being constantly enhanced, but this very part is still works only as I described.

There is a slightly related request https://youtrack.jetbrains.com/issue/WI-27832

Feel free to https://youtrack.jetbrains.com/issues/WI so we can discuss possible approaches.

Also, the syntax you're using now is obsolete, see https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata - sample.meta.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.