Create class autocomplete with get in object manager Magento2 for phpstorm

In Magento 2, in order to create a new object, you have to call get or create method through object manager. But the instance after create is recognize by the IDE, so this is a little bit reduce productivity since you can’t hind methods and properties of the new objects.

Here is the guide to help Phpstorm recognize object create by using PhpStorm Advanced Metadata feature, with this update Phpstorm can understand a object created by magento 2 object manager or a block create by layout object

1. Create a new file: .phpstorm.meta.php at your Phpstorm project root
2. Update .phpstorm.meta.php with  content:

3. Save the file and restart Phpstorm. Let’s try to create some object or create some block in a controller assumed that have construct that assign object manager and layout:

Now you can save your time and enjoy type hinting with Phpstorm and Magento 2 of instance create by object manager now đŸ˜‰

If you want to create new rule for PhpStorm Advanced Metadata, please take a look at PhpStorm Advanced Metadata for more information.