You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/InputDefinition.php
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -30,8 +30,8 @@ class InputDefinition
30
30
{
31
31
private$arguments;
32
32
private$requiredCount;
33
-
private$hasAnArrayArgument = false;
34
-
private$hasOptional;
33
+
private$lastArrayArgument;
34
+
private$lastOptionalArgument;
35
35
private$options;
36
36
private$negations;
37
37
private$shortcuts;
@@ -72,8 +72,8 @@ public function setArguments(array $arguments = [])
72
72
{
73
73
$this->arguments = [];
74
74
$this->requiredCount = 0;
75
-
$this->hasOptional = false;
76
-
$this->hasAnArrayArgument = false;
75
+
$this->lastOptionalArgument = null;
76
+
$this->lastArrayArgument = null;
77
77
$this->addArguments($arguments);
78
78
}
79
79
@@ -100,22 +100,22 @@ public function addArgument(InputArgument $argument)
100
100
thrownewLogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
101
101
}
102
102
103
-
if ($this->hasAnArrayArgument) {
104
-
thrownewLogicException('Cannot add an argument after an array argument.');
103
+
if (null !== $this->lastArrayArgument) {
104
+
thrownewLogicException(sprintf('Cannot add a required argument "%s" after an array argument "%s".', $argument->getName(), $this->lastArrayArgument->getName()));
105
105
}
106
106
107
-
if ($argument->isRequired() && $this->hasOptional) {
108
-
thrownewLogicException('Cannot add a required argument after an optional one.');
107
+
if ($argument->isRequired() && null !== $this->lastOptionalArgument) {
108
+
thrownewLogicException(sprintf('Cannot add a required argument "%s" after an optional one "%s".', $argument->getName(), $this->lastOptionalArgument->getName()));
$this->expectExceptionMessage('Cannot add a required argument after an optional one.');
116
114
$this->initializeArguments();
115
+
$this->expectException(\LogicException::class);
116
+
$this->expectExceptionMessage(sprintf('Cannot add a required argument "%s" after an optional one "%s".', $this->foo2->getName(), $this->foo->getName()));
0 commit comments