From 8fc58aaa4576b054ad668d96df15dc49f778cbac Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 4 Jul 2021 00:48:29 +0200 Subject: [PATCH 1/3] Revert "bug #41952 [Console] fix handling positional arguments (nicolas-grekas)" This reverts commit e93f8c0ad37dbd6d14a3dbc615b2a198f6354006, reversing changes made to eb83be474cd54115f0cb7ad72d60fe06e4ee36de. --- src/Symfony/Component/Console/Input/Input.php | 4 ---- src/Symfony/Component/Console/Tests/Input/InputTest.php | 5 ----- 2 files changed, 9 deletions(-) diff --git a/src/Symfony/Component/Console/Input/Input.php b/src/Symfony/Component/Console/Input/Input.php index 6b093e7506bf4..6e4c01e95f851 100644 --- a/src/Symfony/Component/Console/Input/Input.php +++ b/src/Symfony/Component/Console/Input/Input.php @@ -110,8 +110,6 @@ public function getArgument($name) throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } - $name = \is_int($name) ? key(\array_slice($this->definition->getArguments(), $name, 1, true)) : $name; - return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault(); } @@ -124,8 +122,6 @@ public function setArgument($name, $value) throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } - $name = \is_int($name) ? key(\array_slice($this->definition->getArguments(), $name, 1, true)) : $name; - $this->arguments[$name] = $value; } diff --git a/src/Symfony/Component/Console/Tests/Input/InputTest.php b/src/Symfony/Component/Console/Tests/Input/InputTest.php index 3441351b4b7e5..48c287cd9d3b3 100644 --- a/src/Symfony/Component/Console/Tests/Input/InputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/InputTest.php @@ -75,11 +75,6 @@ public function testArguments() $input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')])); $this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments'); $this->assertEquals(['name' => 'foo', 'bar' => 'default'], $input->getArguments(), '->getArguments() returns all argument values, even optional ones'); - - $input = new ArrayInput(['arg1' => 'foo'], new InputDefinition([new InputArgument('arg1'), new InputArgument('arg2')])); - $input->setArgument(1, 'bar'); - $this->assertEquals('bar', $input->getArgument(1)); - $this->assertEquals(['arg1' => 'foo', 'arg2' => 'bar'], $input->getArguments()); } public function testSetInvalidArgument() From 9928be05fee46a664bacf3beaa7afed9eba779a2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 4 Jul 2021 11:02:18 +0200 Subject: [PATCH 2/3] Revert "minor #41949 [Console] fix type annotations on InputInterface (nicolas-grekas)" This reverts commit ed09dc138e2be63303eaf6ddacabdb1ad6e2965e, reversing changes made to 7e78fb1197dfc6626ff2a1490fa2865fba4ee313. --- src/Symfony/Component/Console/Input/InputInterface.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Input/InputInterface.php b/src/Symfony/Component/Console/Input/InputInterface.php index b96a0c6278f31..4ecab0f4fb10e 100644 --- a/src/Symfony/Component/Console/Input/InputInterface.php +++ b/src/Symfony/Component/Console/Input/InputInterface.php @@ -83,7 +83,7 @@ public function getArguments(); /** * Returns the argument value for a given argument name. * - * @param string|int $name The InputArgument name or position + * @param string $name The argument name * * @return mixed * @@ -94,8 +94,8 @@ public function getArgument($name); /** * Sets an argument value by name. * - * @param string|int $name The InputArgument name or position - * @param mixed $value The argument value + * @param string $name The argument name + * @param mixed $value The argument value * * @throws InvalidArgumentException When argument given doesn't exist */ From 6ac2776c470fb0e3d7207987ccd9c464a7e52dad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 4 Jul 2021 11:08:18 +0200 Subject: [PATCH 3/3] [Console] Fix type annotation on InputInterface::hasArgument() --- src/Symfony/Component/Console/Input/Input.php | 6 +++--- src/Symfony/Component/Console/Input/InputInterface.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Input/Input.php b/src/Symfony/Component/Console/Input/Input.php index 6e4c01e95f851..d7f29073e50d5 100644 --- a/src/Symfony/Component/Console/Input/Input.php +++ b/src/Symfony/Component/Console/Input/Input.php @@ -106,7 +106,7 @@ public function getArguments() */ public function getArgument($name) { - if (!$this->definition->hasArgument($name)) { + if (!$this->definition->hasArgument((string) $name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } @@ -118,7 +118,7 @@ public function getArgument($name) */ public function setArgument($name, $value) { - if (!$this->definition->hasArgument($name)) { + if (!$this->definition->hasArgument((string) $name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } @@ -130,7 +130,7 @@ public function setArgument($name, $value) */ public function hasArgument($name) { - return $this->definition->hasArgument($name); + return $this->definition->hasArgument((string) $name); } /** diff --git a/src/Symfony/Component/Console/Input/InputInterface.php b/src/Symfony/Component/Console/Input/InputInterface.php index 4ecab0f4fb10e..5d0db5c18872a 100644 --- a/src/Symfony/Component/Console/Input/InputInterface.php +++ b/src/Symfony/Component/Console/Input/InputInterface.php @@ -104,7 +104,7 @@ public function setArgument($name, $value); /** * Returns true if an InputArgument object exists by name or position. * - * @param string|int $name The InputArgument name or position + * @param string $name The InputArgument name or position * * @return bool true if the InputArgument object exists, false otherwise */