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

Appearance settings

Commit 2abf5a4

Browse filesBrowse files
bug #41966 [Console] Revert "bug #41952 fix handling positional arguments" (chalasr, nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [Console] Revert "bug #41952 fix handling positional arguments" | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Reverts #41952 as it breaks tests on 5.3 due to an implicit string cast: We added the `string` typehint to the `$name` argument in 5.x, removing it now to allow for `string|int` would be a BC break which I don't think is worth it. Commits ------- 6ac2776 [Console] Fix type annotation on InputInterface::hasArgument() 9928be0 Revert "minor #41949 [Console] fix type annotations on InputInterface (nicolas-grekas)" 8fc58aa Revert "bug #41952 [Console] fix handling positional arguments (nicolas-grekas)"
2 parents e1b0be3 + 6ac2776 commit 2abf5a4
Copy full SHA for 2abf5a4

File tree

3 files changed

+7
-16
lines changed
Filter options

3 files changed

+7
-16
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/Input.php
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ public function getArguments()
106106
*/
107107
public function getArgument($name)
108108
{
109-
if (!$this->definition->hasArgument($name)) {
109+
if (!$this->definition->hasArgument((string) $name)) {
110110
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
111111
}
112112

113-
$name = \is_int($name) ? key(\array_slice($this->definition->getArguments(), $name, 1, true)) : $name;
114-
115113
return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault();
116114
}
117115

@@ -120,12 +118,10 @@ public function getArgument($name)
120118
*/
121119
public function setArgument($name, $value)
122120
{
123-
if (!$this->definition->hasArgument($name)) {
121+
if (!$this->definition->hasArgument((string) $name)) {
124122
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
125123
}
126124

127-
$name = \is_int($name) ? key(\array_slice($this->definition->getArguments(), $name, 1, true)) : $name;
128-
129125
$this->arguments[$name] = $value;
130126
}
131127

@@ -134,7 +130,7 @@ public function setArgument($name, $value)
134130
*/
135131
public function hasArgument($name)
136132
{
137-
return $this->definition->hasArgument($name);
133+
return $this->definition->hasArgument((string) $name);
138134
}
139135

140136
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/InputInterface.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getArguments();
8383
/**
8484
* Returns the argument value for a given argument name.
8585
*
86-
* @param string|int $name The InputArgument name or position
86+
* @param string $name The argument name
8787
*
8888
* @return mixed
8989
*
@@ -94,8 +94,8 @@ public function getArgument($name);
9494
/**
9595
* Sets an argument value by name.
9696
*
97-
* @param string|int $name The InputArgument name or position
98-
* @param mixed $value The argument value
97+
* @param string $name The argument name
98+
* @param mixed $value The argument value
9999
*
100100
* @throws InvalidArgumentException When argument given doesn't exist
101101
*/
@@ -104,7 +104,7 @@ public function setArgument($name, $value);
104104
/**
105105
* Returns true if an InputArgument object exists by name or position.
106106
*
107-
* @param string|int $name The InputArgument name or position
107+
* @param string $name The InputArgument name or position
108108
*
109109
* @return bool true if the InputArgument object exists, false otherwise
110110
*/

‎src/Symfony/Component/Console/Tests/Input/InputTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Input/InputTest.php
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ public function testArguments()
7575
$input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')]));
7676
$this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
7777
$this->assertEquals(['name' => 'foo', 'bar' => 'default'], $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
78-
79-
$input = new ArrayInput(['arg1' => 'foo'], new InputDefinition([new InputArgument('arg1'), new InputArgument('arg2')]));
80-
$input->setArgument(1, 'bar');
81-
$this->assertEquals('bar', $input->getArgument(1));
82-
$this->assertEquals(['arg1' => 'foo', 'arg2' => 'bar'], $input->getArguments());
8378
}
8479

8580
public function testSetInvalidArgument()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.