kokororin / vscode-phpfmt

Integrates phpfmt into VS Code
https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt
BSD 3-Clause "New" or "Revised" License
129 stars 30 forks source link

PHP8: attributes params and function Null-safe return spaces/indentation problem #116

Closed ili101 closed 10 months ago

ili101 commented 10 months ago

Null-safe return, extra space added before and after the "?". after adding the attribute with the parameters all the indentations got messed up. (PHP 8.2) Before: image After: Screenshot 2023-08-14 172313b

<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;

#[ApiResource(
    processor: 'App\State\UserStateProcessor',
    provider: 'App\State\UserStateProvider',
    operations: [
        new Get(
            input: false,
            output: false,
        ),
    ],
)]
class User
{
    private ?string $id = null;

    public function setId(string $id): ?static
    {
        $this->id = $id;
        return $this;
    }
}
driade commented 10 months ago

Thanks, I'll check it.

driade commented 10 months ago

There you go, fixed in the latest release.

driade commented 10 months ago

May you please run the command "phpfmt: Upgrade fmt.phar ot fmt.stub.php"?

ili101 commented 10 months ago

Thank you the attribute problem is solve as I see. regarding the null it still adds extra spaces. Also if you add additional function it not only add the extra space before the "?" but also one before the ":"

<?php

class User
{
    public function setId(): ?static
    {
        return $this;
    }
    public function setId2(): ?static
    {
        return $this;
    }
    public function setId3(): ?static
    {
        return $this;
    }
}

After:

<?php

class User
{
    public function setId():  ?static
    {
        return $this;
    }
    public function setId2() :  ?static
    {
        return $this;
    }
    public function setId3() :  ?static
    {
        return $this;
    }
}
driade commented 10 months ago

Thanks, fixed

ili101 commented 10 months ago

Thank you! looks good

VizGS commented 10 months ago

Hello, it's still has extra spaces in this case. How can I fix this ?

My vscode setting.json

"phpfmt.exclude": [
    "PSR2ModifierVisibilityStaticOrder"
]
<?php

class User
{
    public function setEnable(bool $enable): static
    {
        $this->enable = $enable;

        return $this;
    }

    public function getCreatedAt():  ? \DateTimeInterface    // this still has extra spaces
    {
        return $this->createdAt;
    }

    public function setCreatedAt(\DateTimeInterface $createdAt) : static    // this still has extra spaces
    {
        $this->createdAt = $createdAt;

        return $this;
    }
}
?>
driade commented 10 months ago

Thanks, I'll check.

driade commented 10 months ago

Confirmed, fixed

VizGS commented 10 months ago

Thank you!