SexyMF
SexyMF

Reputation: 11165

PhpStorm shortcut to generate constructor params functionality

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;
       ....          
    }
}

Upvotes: 3

Views: 2778

Answers (3)

Afraj Sarkar Adian
Afraj Sarkar Adian

Reputation: 1

You can initialize and create __construct method by shortcut

Place your cursor where you want to create __construct method then press ALT + Insert Select constructor and choose your propertise

Upvotes: 0

LazyOne
LazyOne

Reputation: 165278

  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

Upvotes: 5

Jakub Matczak
Jakub Matczak

Reputation: 15676

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.

Upvotes: 2

Related Questions