Skip to content

Commit 6cac146

Browse files
committed
getOption() can return int
1 parent a4d8502 commit 6cac146

4 files changed

+5
-9
lines changed

Diff for: src/Rules/Symfony/InvalidOptionDefaultValueRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function processNode(Node $node, Scope $scope): array
6666

6767
// not an array
6868
if (($mode & 8) !== 8) {
69-
$checkType = new UnionType([new StringType(), new NullType()]);
69+
$checkType = new UnionType([new StringType(), new IntegerType(), new NullType()]);
7070
if (($mode & 4) === 4) { // https://symfony.com/doc/current/console/input.html#options-with-optional-arguments
7171
$checkType = TypeCombinator::union($checkType, new ConstantBooleanType(false));
7272
}

Diff for: src/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
6767
if (!$option->acceptValue()) {
6868
$optType = new BooleanType();
6969
} else {
70-
$optType = TypeCombinator::union(new StringType(), new NullType());
70+
$optType = TypeCombinator::union(new StringType(), new IntegerType(), new NullType());
7171
if ($option->isValueRequired() && ($option->isArray() || $option->getDefault() !== null)) {
7272
$optType = TypeCombinator::removeNull($optType);
7373
}
7474
if ($option->isArray()) {
75-
$optType = new ArrayType(new IntegerType(), $optType);
75+
$optType = new ArrayType(new IntegerType(), TypeCombinator::remove($optType, new IntegerType()));
7676
}
7777
$optType = TypeCombinator::union($optType, $scope->getTypeFromValue($option->getDefault()));
7878
}

Diff for: tests/Rules/Symfony/InvalidOptionDefaultValueRuleTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ public function testGetArgument(): void
2424
'Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<int, string>|null, array<int, int> given.',
2525
29,
2626
],
27-
[
28-
'Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects string|false|null, int given.',
29-
30,
30-
],
3127
]
3228
);
3329
}

Diff for: tests/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtensionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function testArgumentTypes(string $expression, string $type): void
2424
public function argumentTypesProvider(): Iterator
2525
{
2626
yield ['$a', 'bool'];
27-
yield ['$b', 'string|null'];
28-
yield ['$c', 'string|null'];
27+
yield ['$b', 'int|string|null'];
28+
yield ['$c', 'int|string|null'];
2929
yield ['$d', 'array<int, string|null>'];
3030
yield ['$e', 'array<int, string>'];
3131

0 commit comments

Comments
 (0)