Skip to content

Improvement of quick fix Add construct from properties ... #198

@Zerotask

Description

@Zerotask

Assume you have the following:

<?php

class User
{
    private ?string $name;
    private int $age;
    private bool $isDeveloper;
}

The quick fix will generate the following:

<?php

class User
{
    private ?string $name;
    private int $age;
    private bool $isDeveloper;
    /**
     * @param $name ?string
     * @param $age int
     * @param $isDeveloper bool
     */
    function __construct(?string $name, int $age, bool $isDeveloper) {
        $this->name = $name;
        $this->age = $age;
        $this->isDeveloper = $isDeveloper;
    }
}

Suggestions:

  1. insert a new line before
  2. docblocks: swap param name and data type: @param $age int -> @param int $age
  3. docblocks: null is not ?: @param $name ?string -> @param null|string $name
  4. Add visibility (public by default)
  5. apply configured code formatting (in my case PSR12) -> have to click ctrl + s and then it gets formatted for PSR12

The expected output would be:

<?php

class User
{
    private ?string $name;
    private int $age;
    private bool $isDeveloper;

    /**
     * @param null|string $name
     * @param int $age
     * @param bool $isDeveloper
     */
    public function __construct(?string $name, int $age, bool $isDeveloper)
    {
        $this->name = $name;
        $this->age = $age;
        $this->isDeveloper = $isDeveloper;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions