Skip to content

Commit aac8356

Browse files
Update getArgument return type in interact method
1 parent 51183fe commit aac8356

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Type/Symfony/InputInterfaceGetArgumentDynamicReturnTypeExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Type\ArrayType;
1111
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1212
use PHPStan\Type\IntegerType;
13+
use PHPStan\Type\NullType;
1314
use PHPStan\Type\StringType;
1415
use PHPStan\Type\Type;
1516
use PHPStan\Type\TypeCombinator;
@@ -76,6 +77,11 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
7677
}
7778
}
7879

80+
$method = $scope->getFunction();
81+
if ($method instanceof MethodReflection && $method->getName() === 'interact') {
82+
$argTypes[] = new NullType();
83+
}
84+
7985
return count($argTypes) > 0 ? TypeCombinator::union(...$argTypes) : null;
8086
}
8187

tests/Type/Symfony/data/ExampleBaseCommand.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ protected function configure(): void
1717
$this->addArgument('base');
1818
}
1919

20+
protected function interact(InputInterface $input, OutputInterface $output): int
21+
{
22+
assertType('string|null', $input->getArgument('base'));
23+
assertType('string|null', $input->getArgument('aaa'));
24+
assertType('string|null', $input->getArgument('bbb'));
25+
assertType('array<int, string>|string|null', $input->getArgument('diff'));
26+
assertType('array<int, string>|null', $input->getArgument('arr'));
27+
assertType('string|null', $input->getArgument('both'));
28+
assertType('Symfony\Component\Console\Helper\QuestionHelper', $this->getHelper('question'));
29+
}
30+
2031
protected function execute(InputInterface $input, OutputInterface $output): int
2132
{
2233
assertType('string|null', $input->getArgument('base'));

0 commit comments

Comments
 (0)