Skip to content

[Console][DependencyInjection] tighten types #41992

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

Merged
merged 1 commit into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Input/InputArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class InputArgument
private $description;

/**
* @param string $name The argument name
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (for self::OPTIONAL mode only)
* @param string $name The argument name
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param string|bool|int|float|array|null $default The default value (for self::OPTIONAL mode only)
*
* @throws InvalidArgumentException When argument mode is not valid
*/
Expand Down Expand Up @@ -86,7 +86,7 @@ public function isArray()
/**
* Sets the default value.
*
* @param mixed $default The default value
* @param string|bool|int|float|array|null $default
*
* @throws LogicException When incorrect default value is given
*/
Expand All @@ -110,7 +110,7 @@ public function setDefault($default = null)
/**
* Returns the default value.
*
* @return mixed
* @return string|bool|int|float|array|null
*/
public function getDefault()
{
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Console/Input/InputDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ public function getArgumentRequiredCount()
}

/**
* Gets the default values.
*
* @return array An array of default values
* @return array<string|bool|int|float|array|null>
*/
public function getArgumentDefaults()
{
Expand Down Expand Up @@ -316,9 +314,7 @@ public function getOptionForShortcut($shortcut)
}

/**
* Gets an array of default values.
*
* @return array An array of all default values
* @return array<string|bool|int|float|array|null>
*/
public function getOptionDefaults()
{
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Console/Input/InputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function hasParameterOption($values, $onlyParams = false);
* Does not necessarily return the correct result for short options
* when multiple flags are combined in the same option.
*
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
* @param mixed $default The default value to return if no result is found
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
* @param string|bool|int|float|array|null $default The default value to return if no result is found
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
*
* @return mixed The option value
*/
Expand All @@ -76,7 +76,7 @@ public function validate();
/**
* Returns all the given arguments merged with the default values.
*
* @return array
* @return array<string|bool|int|float|array|null>
*/
public function getArguments();

Expand Down Expand Up @@ -113,7 +113,7 @@ public function hasArgument($name);
/**
* Returns all the given options merged with the default values.
*
* @return array
* @return array<string|bool|int|float|array|null>
*/
public function getOptions();

Expand Down
16 changes: 5 additions & 11 deletions src/Symfony/Component/Console/Input/InputOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ class InputOption
private $description;

/**
* @param string $name The option name
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::VALUE_NONE)
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the VALUE_* constants
* @param string|bool|int|float|array|null $default The default value (must be null for self::VALUE_NONE)
*
* @throws InvalidArgumentException If option mode is invalid or incompatible
*/
Expand Down Expand Up @@ -162,11 +160,7 @@ public function isArray()
}

/**
* Sets the default value.
*
* @param mixed $default The default value
*
* @throws LogicException When incorrect default value is given
* @param string|bool|int|float|array|null $default
*/
public function setDefault($default = null)
{
Expand All @@ -188,7 +182,7 @@ public function setDefault($default = null)
/**
* Returns the default value.
*
* @return mixed
* @return string|bool|int|float|array|null
*/
public function getDefault()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Console/Question/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Question
private $trimmable = true;

/**
* @param string $question The question to ask to the user
* @param mixed $default The default answer to return if the user enters nothing
* @param string $question The question to ask to the user
* @param string|bool|int|float|null $default The default answer to return if the user enters nothing
*/
public function __construct(string $question, $default = null)
{
Expand All @@ -54,7 +54,7 @@ public function getQuestion()
/**
* Returns the default answer.
*
* @return mixed
* @return string|bool|int|float|null
*/
public function getDefault()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getParameterBag()
*
* @param string $name The parameter name
*
* @return mixed
* @return array|bool|string|int|float|null
*
* @throws InvalidArgumentException if the parameter is not defined
*/
Expand All @@ -133,8 +133,8 @@ public function hasParameter($name)
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param string $name The parameter name
* @param array|bool|string|int|float|null $value The parameter value
*/
public function setParameter($name, $value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function initialized($id);
*
* @param string $name The parameter name
*
* @return mixed The parameter value
* @return array|bool|string|int|float|null
*
* @throws InvalidArgumentException if the parameter is not defined
*/
Expand All @@ -92,8 +92,8 @@ public function hasParameter($name);
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param string $name The parameter name
* @param array|bool|string|int|float|null $value The parameter value
*/
public function setParameter($name, $value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function all()
/**
* {@inheritdoc}
*
* @return mixed
* @return array|bool|string|int|float|null
*/
public function get($name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function all();
*
* @param string $name The parameter name
*
* @return mixed The parameter value
* @return array|bool|string|int|float|null
*
* @throws ParameterNotFoundException if the parameter is not defined
*/
Expand All @@ -63,8 +63,8 @@ public function remove($name);
/**
* Sets a service container parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param string $name The parameter name
* @param array|bool|string|int|float|null $value The parameter value
*
* @throws LogicException if the parameter can not be set
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
use Symfony\Component\DependencyInjection\TypedReference;
use Symfony\Component\DependencyInjection\Variable;
use Symfony\Component\ExpressionLanguage\Expression;

require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
Expand Down Expand Up @@ -164,28 +163,6 @@ public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor
$this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_mandatory_constructor_arguments.php', $dumper->dump(['base_class' => 'ConstructorWithMandatoryArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container']));
}

/**
* @dataProvider provideInvalidParameters
*/
public function testExportParameters($parameters)
{
$this->expectException(\InvalidArgumentException::class);
$container = new ContainerBuilder(new ParameterBag($parameters));
$container->compile();
$dumper = new PhpDumper($container);
$dumper->dump();
}

public function provideInvalidParameters()
{
return [
[['foo' => new Definition('stdClass')]],
[['foo' => new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]],
[['foo' => new Reference('foo')]],
[['foo' => new Variable('foo')]],
];
}

public function testAddParameters()
{
$container = include self::$fixturesPath.'/containers/container8.php';
Expand Down