Skip to content

Commit af6ae0f

Browse files
Update getArgument return type in interact method
1 parent 2c3d666 commit af6ae0f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Type/Symfony/InputInterfaceGetArgumentDynamicReturnTypeExtension.php

+11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
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;
1617
use PHPStan\Type\TypeUtils;
1718
use function count;
19+
use function in_array;
1820

1921
final class InputInterfaceGetArgumentDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
2022
{
@@ -76,6 +78,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
7678
}
7779
}
7880

81+
$method = $scope->getFunction();
82+
if (
83+
$method instanceof MethodReflection
84+
&& $method->getName() === 'interact'
85+
&& in_array('Symfony\Component\Console\Command\Command', $method->getDeclaringClass()->getParentClassesNames(), true)
86+
) {
87+
$argTypes[] = new NullType();
88+
}
89+
7990
return count($argTypes) > 0 ? TypeCombinator::union(...$argTypes) : null;
8091
}
8192

tests/Type/Symfony/data/ExampleBaseCommand.php

+11
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)