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

Code before:
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
 * Represents an invokable command.
 *
 * @author Yonel Ceruto <open@yceruto.dev>
 *
 * @internal
 */
class InvokableCommand implements SignalableCommandInterface
{
    private readonly \Closure $code;
    private readonly ?SignalableCommandInterface $signalableCommand;
    private readonly \ReflectionFunction $reflection;
    private bool $triggerDeprecations = false;
    private $callable;

    public function __construct(
        private readonly Command $command,
        callable $callable,
    ) {
        $this->callable = $callable;
        $this->code = $this->getClosure($callable);
        $this->signalableCommand = $callable instanceof SignalableCommandInterface ? $callable : null;
        $this->reflection = new \ReflectionFunction($this->code);
    }

    /**
     * Invokes a callable with parameters generated from the input interface.
     */
    public function __invoke(InputInterface $input, OutputInterface $output): int
    {
        $statusCode = ($this->code)(...$this->getParameters($input, $output));

        if (!\is_int($statusCode)) {
            if ($this->triggerDeprecations) {
                trigger_deprecation('symfony/console', '7.3', \sprintf('Returning a non-integer value from the command "%s" is deprecated and will throw an exception in Symfony 8.0.', $this->command->getName()));

                return 0;
            }

            throw new \TypeError(\sprintf('The command "%s" must return an integer value in the "%s" method, but "%s" was returned.', $this->command->getName(), $this->reflection->getName(), get_debug_type($statusCode)));
        }

        return $statusCode;

Review comment (suggestion):
CPP can be used here.
```suggestion
        private callable $callable,
```

Code after:
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
 * Represents an invokable command.
 *
 * @author Yonel Ceruto <open@yceruto.dev>
 *
 * @internal
 */
class InvokableCommand implements SignalableCommandInterface
{
    private readonly \Closure $closure;
    private readonly ?SignalableCommandInterface $signalableCommand;
    private readonly \ReflectionFunction $reflection;
    private bool $triggerDeprecations = false;
    private $code;

    public function __construct(
        private readonly Command $command,
        callable $code,
    ) {
        $this->code = $code;
        $this->closure = $this->getClosure($code);
        $this->signalableCommand = $code instanceof SignalableCommandInterface ? $code : null;
        $this->reflection = new \ReflectionFunction($this->closure);
    }

    /**
     * Invokes a callable with parameters generated from the input interface.
     */
    public function __invoke(InputInterface $input, OutputInterface $output): int
    {
        $statusCode = ($this->closure)(...$this->getParameters($input, $output));

        if (!\is_int($statusCode)) {
            if ($this->triggerDeprecations) {
                trigger_deprecation('symfony/console', '7.3', \sprintf('Returning a non-integer value from the command "%s" is deprecated and will throw an exception in Symfony 8.0.', $this->command->getName()));

                return 0;
            }

            throw new \TypeError(\sprintf('The command "%s" must return an integer value in the "%s" method, but "%s" was returned.', $this->command->getName(), $this->reflection->getName(), get_debug_type($statusCode)));
        }

        return $statusCode;