Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command::addOption()'s $default expects wrong array format #47

Closed
Majkl578 opened this issue May 2, 2019 · 7 comments
Closed

Command::addOption()'s $default expects wrong array format #47

Majkl578 opened this issue May 2, 2019 · 7 comments

Comments

@Majkl578
Copy link

Majkl578 commented May 2, 2019

Symfony 4.0 documents Symfony\Component\Console\Command\Command::addOption()'s 5th parameter $default as mixed.

When using default values with InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL mode, the $default parameter expects array<int, string>|null.
This is wrong because keys are irrelevant and leads to error like this:

Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<int, string>|null, array<string> given.

Happens when $default is given an array documented as string[].

Sample code:

/** @var string[] $default */
$default = getSomeDefaults();

$command->addOption(
	'foo',
	null,
	InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
	'foo bar',
	$default
);

This error pops up at level 0 only with this extension enabled, not without it.

@lookyman
Copy link
Collaborator

lookyman commented May 2, 2019

Yep, I see. Thanks, I'll fix it asap.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented May 2, 2019 via email

@Majkl578
Copy link
Author

Majkl578 commented May 2, 2019

@ondrejmirtes Yes, it's strange but it's really reported on level 0 already.
Versions:

phpstan/phpstan                                  0.11.5
phpstan/phpstan-doctrine                         0.11.2
phpstan/phpstan-phpunit                          0.11
phpstan/phpstan-symfony                          0.11.5

@lookyman
Copy link
Collaborator

lookyman commented May 2, 2019

That's because the rule doesn't care about levels. I might change that too.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented May 2, 2019 via email

@lookyman
Copy link
Collaborator

Fixed in c4da70e

@github-actions
Copy link

github-actions bot commented May 1, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants