Field declared dynamically -> Quick Fix: Add Field (Template?)

Hi everyone! Im often declare new class members/fields on deamand in methods. There is a inspection "Field declared dynamically" including a Quick Fix "Add Field".

For example:

class foo
{

   public function __construct()
   {
       $this->bar = 'bar';
    }
}

Alt+Enter on $this->bar and Add Field:

class foo
{
    public $bar;

    public function __construct()
    {
        $this->bar = 'bar';
    }
}

Nice! But i nerver want a public field. I want a private field, ideally with a phpdoc block. Is there a way to change this behaviour?

Thanks

4 comments

You already can choose visibility, it's being focused on intention invocation, isn't it? http://recordit.co/61zSURUYbi

And adding a PHPDoc block will be possible in 2019.1 EAP which hopefully starts tomorrow: https://youtrack.jetbrains.com/issue/WI-4287

0

Hello Eugene, thanks for your answer. Yes public is in focus, but every time I use this function I must type "private" +  Enter + Cursor Up + "/**" + Enter. Thats a litte bit annoying. I've hoped there is a Template, like "File and Code Templates".

0

After using "add field" you can:

- type and use arrows to select visibility;

- type pri or pu and complete suggestion via Tab

After that you can hit Alt+Insert (Generate menu shortcut) and select new field there.

 

Btw it always adds private field for me - I recall there was a feature request to remember last used visibility when adding fields.

0

Ah, I use autocomplete only on demand with STRG + Space.

0

Please sign in to leave a comment.