php - PhpStorm refactor local variable to class field -
like in topic, want refactor local variable class field.
i thinking of 2 approaches:
a. quick , simple:
want refactor name of variable $var
$this->var
.
b. extended version:
from:
class x { function y() { $var = new targetclass; } }
to:
class x { /** @var targetclass $var */ // version c, optional (public|protected|private) $var; function y() { $this->var = new targetclass; } }
can't of this, when try refactor $var
, refactoring $this->var
, end message:
inserted identifier invalid
defining $this->var
first doesn't either.
only workaround found type $this->var
, loose focus on refactoring variable, type whatever , delete it. phpstorm cheated , variable changed. simple dirty-covers approach a.
select variable , rightclick. choose refactor->extract->field. enter name wan't field.