How to Generate constructors in Magento 2

- Magento 2

Magento 2 Development

Because of Dependency Injection pattern Magento 2 have huge constructors for every class. World best PHP IDE PHP Storm can help you generate constructors and save lots of time in Magento 2 development.

With constructor generator you will be able to create constructors with arguments, with the value assigned to the field variables.

To generate a constructor

  1. Go the main menu and select Code | Generate, or you can right-click the editor and choose Generate from the context menu. Besides, it is possible to use Alt+Insert keyboard shortcut.

  2. Then, select Constructor option in the pop-up list displayed in the editor.

  3. In case when the class in question contains fields, you should select the fields to be initialized by constructor.

  4. Now, click OK.

Check the example below:

More tips from Magento 2 Developer’s Cookbook

For further information, follow this link: Source