Skip to content

Commit bfdfb01

Browse files
[DependencyInjection][Console] tighten types
1 parent 83de78c commit bfdfb01

File tree

14 files changed

+36
-68
lines changed

14 files changed

+36
-68
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals
319319
/**
320320
* {@inheritdoc}
321321
*/
322-
public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false)
322+
public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false)
323323
{
324324
$values = (array) $values;
325325
$tokens = $this->tokens;

src/Symfony/Component/Console/Input/ArrayInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false)
80+
public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false)
8181
{
8282
$values = (array) $values;
8383

src/Symfony/Component/Console/Input/InputArgument.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class InputArgument
3131
private $description;
3232

3333
/**
34-
* @param string $name The argument name
35-
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
36-
* @param string $description A description text
37-
* @param mixed $default The default value (for self::OPTIONAL mode only)
34+
* @param string $name The argument name
35+
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
36+
* @param string $description A description text
37+
* @param string|bool|int|float|array|null $default The default value (for self::OPTIONAL mode only)
3838
*
3939
* @throws InvalidArgumentException When argument mode is not valid
4040
*/
41-
public function __construct(string $name, int $mode = null, string $description = '', mixed $default = null)
41+
public function __construct(string $name, int $mode = null, string $description = '', string|bool|int|float|array $default = null)
4242
{
4343
if (null === $mode) {
4444
$mode = self::OPTIONAL;
@@ -88,7 +88,7 @@ public function isArray()
8888
*
8989
* @throws LogicException When incorrect default value is given
9090
*/
91-
public function setDefault(mixed $default = null)
91+
public function setDefault(string|bool|int|float|array $default = null)
9292
{
9393
if (self::REQUIRED === $this->mode && null !== $default) {
9494
throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
@@ -108,7 +108,7 @@ public function setDefault(mixed $default = null)
108108
/**
109109
* Returns the default value.
110110
*
111-
* @return mixed
111+
* @return string|bool|int|float|array|null
112112
*/
113113
public function getDefault()
114114
{

src/Symfony/Component/Console/Input/InputDefinition.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ public function getArgumentRequiredCount()
182182
}
183183

184184
/**
185-
* Gets the default values.
186-
*
187-
* @return array An array of default values
185+
* @return array<string|bool|int|float|array|null>
188186
*/
189187
public function getArgumentDefaults()
190188
{
@@ -325,9 +323,7 @@ public function getOptionForShortcut(string $shortcut)
325323
}
326324

327325
/**
328-
* Gets an array of default values.
329-
*
330-
* @return array An array of all default values
326+
* @return array<string|bool|int|float|array|null>
331327
*/
332328
public function getOptionDefaults()
333329
{

src/Symfony/Component/Console/Input/InputInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals
5151
* Does not necessarily return the correct result for short options
5252
* when multiple flags are combined in the same option.
5353
*
54-
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
55-
* @param mixed $default The default value to return if no result is found
56-
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
54+
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
55+
* @param string|bool|int|float|array|null $default The default value to return if no result is found
56+
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
5757
*
5858
* @return mixed The option value
5959
*/
60-
public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false);
60+
public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false);
6161

6262
/**
6363
* Binds the current Input instance with the given arguments and options.
@@ -76,7 +76,7 @@ public function validate();
7676
/**
7777
* Returns all the given arguments merged with the default values.
7878
*
79-
* @return array
79+
* @return array<string|bool|int|float|array|null>
8080
*/
8181
public function getArguments();
8282

@@ -106,7 +106,7 @@ public function hasArgument(string $name);
106106
/**
107107
* Returns all the given options merged with the default values.
108108
*
109-
* @return array
109+
* @return array<string|bool|int|float|array|null>
110110
*/
111111
public function getOptions();
112112

src/Symfony/Component/Console/Input/InputOption.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ class InputOption
5353
private $description;
5454

5555
/**
56-
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
57-
* @param int|null $mode The option mode: One of the VALUE_* constants
58-
* @param mixed $default The default value (must be null for self::VALUE_NONE)
56+
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
57+
* @param int|null $mode The option mode: One of the VALUE_* constants
58+
* @param string|bool|int|float|array|null $default The default value (must be null for self::VALUE_NONE)
5959
*
6060
* @throws InvalidArgumentException If option mode is invalid or incompatible
6161
*/
62-
public function __construct(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null)
62+
public function __construct(string $name, string|array $shortcut = null, int $mode = null, string $description = '', string|bool|int|float|array $default = null)
6363
{
6464
if (0 === strpos($name, '--')) {
6565
$name = substr($name, 2);
@@ -172,12 +172,7 @@ public function isNegatable(): bool
172172
return self::VALUE_NEGATABLE === (self::VALUE_NEGATABLE & $this->mode);
173173
}
174174

175-
/**
176-
* Sets the default value.
177-
*
178-
* @throws LogicException When incorrect default value is given
179-
*/
180-
public function setDefault(mixed $default = null)
175+
public function setDefault(string|bool|int|float|array $default = null)
181176
{
182177
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
183178
throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
@@ -197,7 +192,7 @@ public function setDefault(mixed $default = null)
197192
/**
198193
* Returns the default value.
199194
*
200-
* @return mixed
195+
* @return string|bool|int|float|array|null
201196
*/
202197
public function getDefault()
203198
{

src/Symfony/Component/Console/Question/Question.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Question
3333
private $multiline = false;
3434

3535
/**
36-
* @param string $question The question to ask to the user
37-
* @param mixed $default The default answer to return if the user enters nothing
36+
* @param string $question The question to ask to the user
37+
* @param string|bool|int|float|null $default The default answer to return if the user enters nothing
3838
*/
39-
public function __construct(string $question, mixed $default = null)
39+
public function __construct(string $question, string|bool|int|float $default = null)
4040
{
4141
$this->question = $question;
4242
$this->default = $default;
@@ -55,7 +55,7 @@ public function getQuestion()
5555
/**
5656
* Returns the default answer.
5757
*
58-
* @return mixed
58+
* @return string|bool|int|float|null
5959
*/
6060
public function getDefault()
6161
{

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getParameterBag()
107107
/**
108108
* Gets a parameter.
109109
*
110-
* @return mixed
110+
* @return array|bool|string|int|float|null
111111
*
112112
* @throws InvalidArgumentException if the parameter is not defined
113113
*/
@@ -124,7 +124,7 @@ public function hasParameter(string $name)
124124
return $this->parameterBag->has($name);
125125
}
126126

127-
public function setParameter(string $name, mixed $value)
127+
public function setParameter(string $name, array|bool|string|int|float|null $value)
128128
{
129129
$this->parameterBag->set($name, $value);
130130
}

src/Symfony/Component/DependencyInjection/ContainerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function has(string $id);
5555
public function initialized(string $id);
5656

5757
/**
58-
* @return mixed
58+
* @return array|bool|string|int|float|null
5959
*
6060
* @throws InvalidArgumentException if the parameter is not defined
6161
*/
@@ -66,5 +66,5 @@ public function getParameter(string $name);
6666
*/
6767
public function hasParameter(string $name);
6868

69-
public function setParameter(string $name, mixed $value);
69+
public function setParameter(string $name, array|bool|string|int|float|null $value);
7070
}

src/Symfony/Component/DependencyInjection/ParameterBag/ContainerBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function all()
3636
/**
3737
* {@inheritdoc}
3838
*
39-
* @return mixed
39+
* @return array|bool|string|int|float|null
4040
*/
4141
public function get(string $name)
4242
{

src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function add(array $parameters)
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function set(string $name, mixed $value)
56+
public function set(string $name, array|bool|string|int|float|null $value)
5757
{
5858
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
5959
}

src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function get(string $name)
9999
/**
100100
* {@inheritdoc}
101101
*/
102-
public function set(string $name, mixed $value)
102+
public function set(string $name, array|bool|string|int|float|null $value)
103103
{
104104
$this->parameters[$name] = $value;
105105
}

src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBagInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function all();
4545
/**
4646
* Gets a service container parameter.
4747
*
48-
* @return mixed The parameter value
48+
* @return array|bool|string|int|float|null
4949
*
5050
* @throws ParameterNotFoundException if the parameter is not defined
5151
*/
@@ -61,7 +61,7 @@ public function remove(string $name);
6161
*
6262
* @throws LogicException if the parameter can not be set
6363
*/
64-
public function set(string $name, mixed $value);
64+
public function set(string $name, array|bool|string|int|float|null $value);
6565

6666
/**
6767
* Returns true if a parameter name is defined.

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
5252
use Symfony\Component\DependencyInjection\Tests\Fixtures\WitherStaticReturnType;
5353
use Symfony\Component\DependencyInjection\TypedReference;
54-
use Symfony\Component\DependencyInjection\Variable;
5554
use Symfony\Component\ExpressionLanguage\Expression;
5655

5756
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
@@ -170,28 +169,6 @@ public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor
170169
$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']));
171170
}
172171

173-
/**
174-
* @dataProvider provideInvalidParameters
175-
*/
176-
public function testExportParameters($parameters)
177-
{
178-
$this->expectException(\InvalidArgumentException::class);
179-
$container = new ContainerBuilder(new ParameterBag($parameters));
180-
$container->compile();
181-
$dumper = new PhpDumper($container);
182-
$dumper->dump();
183-
}
184-
185-
public function provideInvalidParameters()
186-
{
187-
return [
188-
[['foo' => new Definition('stdClass')]],
189-
[['foo' => new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]],
190-
[['foo' => new Reference('foo')]],
191-
[['foo' => new Variable('foo')]],
192-
];
193-
}
194-
195172
public function testAddParameters()
196173
{
197174
$container = include self::$fixturesPath.'/containers/container8.php';

0 commit comments

Comments
 (0)