Created
August 31, 2016 10:20
-
-
Save rskuipers/66c2b8e85c733915d38184aa7e40ee91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This file is not a CODE, it makes no sense and won't run or validate | |
// Its AST serves IDE as DATA source to make advanced type inference decisions. | |
namespace PHPSTORM_META { | |
$STATIC_METHOD_TYPES = [ | |
\Zend\ServiceManager\ServiceLocatorInterface::get('') => [ | |
// STATIC call key to make static (1) & dynamic (2) calls work | |
"special" instanceof \Exception, | |
// "KEY" instanceof Class maps KEY to Class | |
], | |
]; | |
} |
Note: this can be used also with any PSR-11 container 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using a Service Manager and you supply the class name as argument for
get()
, you can use the above META to get automatic autocomplete working. Just put this file in the root of your project (the root being the PhpStorm project root), it will be picked up instantly).Make sure your Service Manager is type-hinted and the type-hint matches the class name used in the META file.
Zend Service Manager is used as an example but this works for pretty much anything.
Source: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata