Repository: symfony/symfony
File: src/Symfony/Component/Console/Command/Command.php (PHP)

Code before:
            return $attribute[0]->newInstance()->name;
        }

        return null;
    }

    /**
     * @deprecated since Symfony 7.3, use the #[AsCommand] attribute instead
     */
    public static function getDefaultDescription(): ?string
    {
        trigger_deprecation('symfony/console', '7.3', 'Method "%s()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', __METHOD__);

        if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) {
            return $attribute[0]->newInstance()->description;
        }

        return null;
    }

    /**
     * @param string|callable|null $name The name of the command or an invokable object that uses AsCommand attribute; passing null means it must be set in configure()
     *
     * @throws LogicException When the command name is empty
     */
    public function __construct(null|callable|string $name = null)
    {
        $this->definition = new InputDefinition();

        if (is_callable($name)) {
            if (!\is_object($name) || $name instanceof \Closure) {
                throw new InvalidArgumentException(\sprintf('The command must be an instance of "%s" or an invokable object.', Command::class));
            }

            /** @var AsCommand $attribute */
            $attribute = ((new \ReflectionObject($name))->getAttributes(AsCommand::class)[0] ?? null)?->newInstance()
                ?? throw new LogicException(\sprintf('The command must use the "%s" attribute.', AsCommand::class));

            $this->setName($attribute->name)
                ->setDescription($attribute->description ?? '')
                ->setHelp($attribute->help ?? '')
                ->setCode($name);

            foreach ($attribute->usages as $usage) {
                $this->addUsage($usage);
            }

            return;
        }

        $attribute = ((new \ReflectionClass(static::class))->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();

Review comment (suggestion):
We don't have to keep the parameter name, they are not covered by out BC promise (except for attribute constructors).

@yceruto suggested `$subject` https://github.com/symfony/symfony/pull/60823#discussion_r2154807468.

On a 2nd thought, we can have a 2nd parameter named `$code` that can be any callable, and would require to be an invokable object with the `#[AsCommand]` attribute only when `$name` is `null`.

```suggestion
    public function __construct(?string $name = null, ?callable $code = null)
```


Code after:
            return $attribute[0]->newInstance()->name;
        }

        return null;
    }

    /**
     * @deprecated since Symfony 7.3, use the #[AsCommand] attribute instead
     */
    public static function getDefaultDescription(): ?string
    {
        trigger_deprecation('symfony/console', '7.3', 'Method "%s()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', __METHOD__);

        if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) {
            return $attribute[0]->newInstance()->description;
        }

        return null;
    }

    /**
     * @param string|null $name The name of the command; passing null means it must be set in configure()
     *
     * @throws LogicException When the command name is empty
     */
    public function __construct(?string $name = null, ?callable $code = null)
    {
        $this->definition = new InputDefinition();

        if ($code !== null) {
            if (!\is_object($code) || $code instanceof \Closure) {
                throw new InvalidArgumentException(\sprintf('The command must be an instance of "%s" or an invokable object.', Command::class));
            }

            /** @var AsCommand $attribute */
            $attribute = ((new \ReflectionObject($code))->getAttributes(AsCommand::class)[0] ?? null)?->newInstance()
                ?? throw new LogicException(\sprintf('The command must use the "%s" attribute.', AsCommand::class));

            $this->setName($name ?? $attribute->name)
                ->setDescription($attribute->description ?? '')
                ->setHelp($attribute->help ?? '')
                ->setCode($code);

            foreach ($attribute->usages as $usage) {
                $this->addUsage($usage);
            }

            return;
        }

        $attribute = ((new \ReflectionClass(static::class))->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();