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

Code before:
     * Validates a command name.
     *
     * It must be non-empty and parts can optionally be separated by ":".
     *
     * @throws InvalidArgumentException When the name is invalid
     */
    private function validateName(string $name): void
    {
        if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
            throw new InvalidArgumentException(\sprintf('Command name "%s" is invalid.', $name));
        }
    }

    private function getCommandAttribute(?callable $code): ?AsCommand
    {
        if (null === $code) {
            /** @var AsCommand|null $attribute */
            $attribute = (new \ReflectionClass(static::class)->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();

            return $attribute;
        }

        $reflection = new \ReflectionFunction($code(...));

        if ($reflection->isAnonymous() || !$class = $reflection->getClosureScopeClass()) {
            throw new InvalidArgumentException(\sprintf('The command must be an instance of "%s", an invokable object or method.', self::class));
        }

        /** @var AsCommand|null $attribute */
        $attribute = ($reflection->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();

        if (!$attribute && $reflection->getName() === '__invoke') {
            /** @var AsCommand|null $attribute */
            $attribute = ($class->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();
        }

        if (!$attribute) {
            throw new LogicException(\sprintf('The command must use the "%s" attribute.', AsCommand::class));
        }

        return $attribute;
    }
}


Review comment (suggestion):
```suggestion
            throw new InvalidArgumentException(\sprintf('The command must be an instance of "%s", an invokable object or a method of an object.', self::class));
```

Code after:
    public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false
    {
        return $this->code?->handleSignal($signal, $previousExitCode) ?? false;
    }

    /**
     * Validates a command name.
     *
     * It must be non-empty and parts can optionally be separated by ":".
     *
     * @throws InvalidArgumentException When the name is invalid
     */
    private function validateName(string $name): void
    {
        if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
            throw new InvalidArgumentException(\sprintf('Command name "%s" is invalid.', $name));
        }
    }

    private function getCommandAttribute(?callable $code): ?AsCommand
    {
        if (null === $code) {
            /** @var AsCommand|null $attribute */
            $attribute = (new \ReflectionClass(static::class)->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();

            return $attribute;
        }

        $reflection = new \ReflectionFunction($code(...));

        if ($reflection->isAnonymous() || !$class = $reflection->getClosureScopeClass()) {
            throw new InvalidArgumentException(\sprintf('The command must be an instance of "%s", an invokable object or a method of an object.', self::class));
        }

        /** @var AsCommand|null $attribute */
        $attribute = ($reflection->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();

        if (!$attribute && $reflection->getName() === '__invoke') {
            /** @var AsCommand|null $attribute */
            $attribute = ($class->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();
        }

        if (!$attribute) {
            throw new LogicException(\sprintf('The command must use the "%s" attribute.', AsCommand::class));
        }

        return $attribute;
    }
}