Closed
Description
Symfony version(s) affected: 5.2.4, 4.4.20,
Description
Console's InputOption::getDefault
will return the following types:
/**
* Returns the default value.
*
* @return string|string[]|int|bool|null The default value
*/
public function getDefault()
{
return $this->default;
}
Input::getOption
(with Input
implementing InputInterface
falls back to the default value:
public function getOption($name)
{
if (!$this->definition->hasOption($name)) {
throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
}
return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
}
So InputInterface::getOption
should provide all these types as well, but is it missing the int
type:
/**
* Returns the option value for a given option name.
*
* @param string $name The option name
*
* @return string|string[]|bool|null The option value
*
* @throws InvalidArgumentException When option given doesn't exist
*/
public function getOption($name);
This will confuse static type checkers like PHPStan when an int is handled.
Possible Solution
Add the int
type the the return type annotation of the interface.