Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c4da70e

Browse files
committed
Fix invalid option default argument
1 parent 1f1527e commit c4da70e

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

‎src/Rules/Symfony/InvalidOptionDefaultValueRule.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Type\Constant\ConstantBooleanType;
1212
use PHPStan\Type\Constant\ConstantIntegerType;
1313
use PHPStan\Type\IntegerType;
14+
use PHPStan\Type\MixedType;
1415
use PHPStan\Type\NullType;
1516
use PHPStan\Type\ObjectType;
1617
use PHPStan\Type\StringType;
@@ -76,8 +77,8 @@ public function processNode(Node $node, Scope $scope): array
7677
}
7778

7879
// is array
79-
if (($mode & 8) === 8 && !(new UnionType([new ArrayType(new IntegerType(), new StringType()), new NullType()]))->isSuperTypeOf($defaultType)->yes()) {
80-
return [sprintf('Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<int, string>|null, %s given.', $defaultType->describe(VerbosityLevel::typeOnly()))];
80+
if (($mode & 8) === 8 && !(new UnionType([new ArrayType(new MixedType(), new StringType()), new NullType()]))->isSuperTypeOf($defaultType)->yes()) {
81+
return [sprintf('Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<string>|null, %s given.', $defaultType->describe(VerbosityLevel::typeOnly()))];
8182
}
8283

8384
return [];

‎tests/Rules/Symfony/ExampleCommand.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ protected function configure(): void
2929
$this->addOption('b', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', [1]);
3030
$this->addOption('c', null, InputOption::VALUE_OPTIONAL, '', 1);
3131
$this->addOption('d', null, InputOption::VALUE_OPTIONAL, '', false);
32+
33+
/** @var string[] $defaults */
34+
$defaults = [];
35+
$this->addOption('e', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', $defaults);
3236
}
3337

3438
protected function execute(InputInterface $input, OutputInterface $output): int

‎tests/Rules/Symfony/InvalidOptionDefaultValueRuleTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testGetArgument(): void
2121
],
2222
[
2323
[
24-
'Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<int, string>|null, array<int, int> given.',
24+
'Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<string>|null, array<int, int> given.',
2525
29,
2626
],
2727
]

‎tests/Rules/Symfony/UndefinedArgumentRuleTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetArgument(): void
3535
[
3636
[
3737
'Command "example-rule" does not define argument "undefined".',
38-
37,
38+
41,
3939
],
4040
]
4141
);

‎tests/Rules/Symfony/UndefinedOptionRuleTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetArgument(): void
3535
[
3636
[
3737
'Command "example-rule" does not define option "bbb".',
38-
44,
38+
48,
3939
],
4040
]
4141
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /