Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
use PHPStan\Type\ArrayType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\IntegerType;
use PHPStan\Type\NullType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;
use function in_array;

final class InputInterfaceGetArgumentDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
Expand Down Expand Up @@ -76,6 +78,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
}
}

$method = $scope->getFunction();
if (
$method instanceof MethodReflection
&& $method->getName() === 'interact'
&& in_array('Symfony\Component\Console\Command\Command', $method->getDeclaringClass()->getParentClassesNames(), true)
) {
$argTypes[] = new NullType();
}

return count($argTypes) > 0 ? TypeCombinator::union(...$argTypes) : null;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Type/Symfony/data/ExampleBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ protected function configure(): void
$this->addArgument('base');
}

protected function interact(InputInterface $input, OutputInterface $output): int
{
assertType('string|null', $input->getArgument('base'));
assertType('string|null', $input->getArgument('aaa'));
assertType('string|null', $input->getArgument('bbb'));
assertType('array<int, string>|string|null', $input->getArgument('diff'));
assertType('array<int, string>|null', $input->getArgument('arr'));
assertType('string|null', $input->getArgument('both'));
assertType('Symfony\Component\Console\Helper\QuestionHelper', $this->getHelper('question'));
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
assertType('string|null', $input->getArgument('base'));
Expand Down