kotfire/vscode-php-add-property

[feature] add support for PHP 8: Constructor property promotion

Closed this issue · 5 comments

I'm already working on it 👍

Feel free to add here any particular examples (code before and after) to help me test it. Thanks!

ctf0 commented

// before

class CustomerDTO
{
    public $name;

    public $email;

    public $birth_date;

    public function __construct(
        $name, 
        $email, 
        $birth_date
    ) {
        $this->name = $name;
        $this->email = $email;
        $this->birth_date = $birth_date;
    }
}

// after

class CustomerDTO
{
    public function __construct(
        public $name, 
        public $email, 
        public $birth_date,
    ) {}
}

Let me see if I understand correctly. Do you want a command to transform from classic constructor to property promotion? It is doable, what I'm working on now is support inserting/adding properties as promoted.

// before

class CustomerDTO
{
    public function __construct(
        public $name, 
        public $email
    ) {}
}

//after

class CustomerDTO
{
    public function __construct(
        public $name, 
        public $email, 
        public $birth_date
    ) {}
}
ctf0 commented

having the 2 options would be much appreciated,

  • a cmnd to convert current to v8
  • and a new config that tell the current cmnd of adding new props to follow the v8 flow, exactly like ur example

👍