rector-symfony icon indicating copy to clipboard operation
rector-symfony copied to clipboard

[CommandPropertyToAttributeRector] is not setting all attributes

Open johanadivare opened this issue 3 years ago • 1 comments

Bug Report

CommandPropertyToAttributeRector is not setting aliases and hidden in AsCommand attribute

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/69d11564-5a50-458b-b185-de0c343b416b

<?php

class SunshineCommand extends \Symfony\Component\Console\Command\Command
{
    /** @var string|null */
    public static $defaultName = 'sunshine';

    /** @var string|null */
    public static $defaultDescription = 'Let the sun shine!';
    

    /**
     * {@inheritdoc}
     */
    protected function configure(): void
    {
        $this
            ->setAliases(['sun', 'shine'])
        ;
    }
}

Responsible rules

  • CommandPropertyToAttributeRector

Expected Behavior

<?php

#[\Symfony\Component\Console\Attribute\AsCommand('sunshine', 'Let the sun shine!', ['sun', 'shine'], false)
class SunshineCommand extends \Symfony\Component\Console\Command\Command
{
    /**
     * {@inheritdoc}
     */
    protected function configure(): void
    {
    }
}

johanadivare avatar Oct 03 '22 09:10 johanadivare

Maybe a new rule is more appropriate as the aliases and hidden are not set with properties but set with configure but they are properties in \Symfony\Component\Console\Command\Command

johanadivare avatar Oct 05 '22 07:10 johanadivare

@JohJohan have a look

johanadivare avatar Oct 24 '22 13:10 johanadivare

Also, the MakeCommandLazyRector is not migrating the description to $defaultDescription (probably because it is a lot newer than the $defaultName) and so it misses it in most cases too.

stof avatar Oct 24 '22 15:10 stof

@stof this is done with https://github.com/rectorphp/rector-symfony/pull/257 as discussed here https://github.com/rectorphp/rector-symfony/issues/229

JohJohan avatar Oct 24 '22 15:10 JohJohan

the rector present in that PR is not documented, which is why I missed it

stof avatar Oct 24 '22 15:10 stof

@stof good point, i created a pull request to add it to the docs: https://github.com/rectorphp/rector-symfony/pull/260

JohJohan avatar Oct 24 '22 16:10 JohJohan

Wip: https://github.com/rectorphp/rector-symfony/pull/259

johanadivare avatar Nov 09 '22 08:11 johanadivare

Fixed with https://github.com/rectorphp/rector-symfony/pull/259

johanadivare avatar Dec 06 '22 08:12 johanadivare