Skip to content

Commit

Permalink
[minor] move setting Invokable::$io to initialize method
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed May 26, 2022
1 parent d6ebf15 commit 09b1f70
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Invokable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ public function addArgumentFactory(?string $type, callable $factory): self
return $this;
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = ($this->argumentFactories[IO::class] ?? static fn() => new IO($input, $output))($input, $output);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
self::invokeParameters();

$this->io = ($this->argumentFactories[IO::class] ?? static fn() => new IO($input, $output))($input, $output);

$parameters = \array_merge(
\array_map(
static function(callable $factory, ?string $type) use ($input, $output) {
Expand All @@ -57,10 +60,10 @@ static function(callable $factory, ?string $type) use ($input, $output) {
\array_keys($this->argumentFactories)
),
[
Parameter::untyped($this->io),
Parameter::untyped($this->io()),
Parameter::typed(InputInterface::class, $input, Argument::EXACT),
Parameter::typed(OutputInterface::class, $output, Argument::EXACT),
Parameter::typed(IO::class, $this->io, Argument::COVARIANCE),
Parameter::typed(IO::class, $this->io(), Argument::COVARIANCE),
Parameter::typed(IO::class, Parameter::factory(fn($class) => new $class($input, $output))),
]
);
Expand Down

0 comments on commit 09b1f70

Please sign in to comment.