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

Code before:
     * @throws LogicException When the command name is empty
     */
    public function __construct(?string $name = null, ?callable $code = null)
    {
        $this->definition = new InputDefinition();

        if ($name === null && $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($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();

        if (null === $name) {
            if (self::class !== (new \ReflectionMethod($this, 'getDefaultName'))->class) {
                trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultName()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', static::class);

                $name = static::getDefaultName();
            } else {
                $name = $attribute?->name;
            }
        }

        if (null !== $name) {
            $aliases = explode('|', $name);

            if ('' === $name = array_shift($aliases)) {
                $this->setHidden(true);
                $name = array_shift($aliases);
            }

            $this->setAliases($aliases);
        }

        if (null !== $name) {

Review comment (suggestion):
Like this, the `$name` can be overridden in the constructor.

```suggestion
        if ($code) {
            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;
        }
```

Code after:
     * @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();

        if (null === $name) {
            if (self::class !== (new \ReflectionMethod($this, 'getDefaultName'))->class) {
                trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultName()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', static::class);

                $name = static::getDefaultName();
            } else {
                $name = $attribute?->name;
            }
        }

        if (null !== $name) {
            $aliases = explode('|', $name);

            if ('' === $name = array_shift($aliases)) {
                $this->setHidden(true);
                $name = array_shift($aliases);
            }

            $this->setAliases($aliases);
        }

        if (null !== $name) {