Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm shortcut to generate constructor params functionality

Tags:

phpstorm

Is there a shortcut in PhpStorm to generate code for $model2 same as $model1?

class Test{    
    private $model1;
    public function __construct(string $model1, $model2)
    {
       $this->model1 = $model1;
       ....          
    }
}
like image 622
SexyMF Avatar asked Nov 28 '25 06:11

SexyMF


2 Answers

  1. Place caret on __construct or inside its' parameters .. and invoke Quick Fix menu (Alt + Enter or via light bulb icon).

  2. Choose appropriate option there -- it will be Initialize fields

enter image description here

like image 171
LazyOne Avatar answered Dec 01 '25 07:12

LazyOne


Yes, place cursor on $model2, then press Alt+Enter and choose option Initialize fields.

It will create a private field in your class (if it doesn't exists yet), and assign it inside constructor.

like image 40
Jakub Matczak Avatar answered Dec 01 '25 07:12

Jakub Matczak