M
M
Maxim2015-11-09 11:42:01
symfony
Maxim, 2015-11-09 11:42:01

How to explicitly specify the type of an array element in phpDoc?

Hello!
Please tell me how to solve this problem, there is a method:

public function create(Request $request, Application $app){
        $data = json_decode($request->getContent(), true);
        $app['user']->setData($data);
        ...
}

PhpStorm does not want to determine that $app['user'] is of type User, tried to set it in different ways, but does not want to. Working option:
/**
*@var User $user
*/
$user = $app['user'];
$user->setData($data);

but it does not fit, since there are a lot of such places, and there is no way to shovel everything, I just want to specify once just where phpStorm should look and where to look for a method or object and write further. The option to change the Application is also not suitable, since Application implements ArrayAccess and everything is already written to work with such access as an array.
Are there any solutions to the problem through phpDoc?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-11-09
@ua6xh

It is possible through .phpstorm.meta.php :

namespace PHPSTORM_META {
    $STATIC_METHOD_TYPES = [
        \Application => [
            "user" instanceof \User,
        ]
    ];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question