Skip to content

Commit

Permalink
Also support command argument and initialize method
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jun 19, 2024
1 parent bca27f1 commit 3176a7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
if (
$canBeNullInInteract
&& $method instanceof MethodReflection
&& $method->getName() === 'interact'
&& ($method->getName() === 'interact' || $method->getName() === 'initialize')
&& in_array('Symfony\Component\Console\Command\Command', $method->getDeclaringClass()->getParentClassesNames(), true)
) {
$argTypes[] = new NullType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
}
$argName = $argStrings[0]->getValue();

if ($argName === 'command') {
$method = $scope->getFunction();
if (
$method instanceof MethodReflection
&& ($method->getName() === 'interact' || $method->getName() === 'initialize')
&& in_array('Symfony\Component\Console\Command\Command', $method->getDeclaringClass()->getParentClassesNames(), true)
) {
return null;
}
}

$returnTypes = [];
foreach ($this->consoleApplicationResolver->findCommands($classReflection) as $command) {
try {
Expand Down
20 changes: 19 additions & 1 deletion tests/Type/Symfony/data/ExampleBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,24 @@ protected function configure(): void
$this->addArgument('base');
}

protected function interact(InputInterface $input, OutputInterface $output): int
protected function initialize(InputInterface $input, OutputInterface $output): void
{
assertType('bool', $input->hasArgument('command'));

assertType('string|null', $input->getArgument('base'));
assertType('string', $input->getArgument('aaa'));
assertType('string', $input->getArgument('bbb'));
assertType('string|null', $input->getArgument('required'));
assertType('array<int, string>|string', $input->getArgument('diff'));
assertType('array<int, string>', $input->getArgument('arr'));
assertType('string|null', $input->getArgument('both'));
assertType('Symfony\Component\Console\Helper\QuestionHelper', $this->getHelper('question'));
}

protected function interact(InputInterface $input, OutputInterface $output): void
{
assertType('bool', $input->hasArgument('command'));

assertType('string|null', $input->getArgument('base'));
assertType('string', $input->getArgument('aaa'));
assertType('string', $input->getArgument('bbb'));
Expand All @@ -33,6 +49,8 @@ protected function interact(InputInterface $input, OutputInterface $output): int

protected function execute(InputInterface $input, OutputInterface $output): int
{
assertType('true', $input->hasArgument('command'));

assertType('string|null', $input->getArgument('base'));
assertType('string', $input->getArgument('aaa'));
assertType('string', $input->getArgument('bbb'));
Expand Down

0 comments on commit 3176a7c

Please sign in to comment.