File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55namespace Rector \Symfony \Symfony73 \NodeAnalyzer ;
66
7+ use PhpParser \Node \Expr ;
78use PhpParser \Node \Stmt \ClassMethod ;
89use Rector \PhpParser \Node \Value \ValueResolver ;
910use Rector \Symfony \Symfony73 \NodeFinder \MethodCallFinder ;
1011use Rector \Symfony \Symfony73 \ValueObject \CommandArgument ;
12+ use Symfony \Component \Console \Input \InputArgument ;
1113
1214final readonly class CommandArgumentsResolver
1315{
@@ -30,12 +32,22 @@ public function resolve(ClassMethod $configureClassMethod): array
3032
3133 $ argumentName = $ this ->valueResolver ->getValue ($ addArgumentArgs [0 ]->value );
3234
35+ $ modeExpr = $ addArgumentArgs [1 ]->value ?? null ;
36+
37+ $ isArray = false ;
38+ if ($ modeExpr instanceof Expr) {
39+ $ modeValue = $ this ->valueResolver ->getValue ($ modeExpr );
40+ // binary check for InputArgument::IS_ARRAY
41+ $ isArray = (bool ) ($ modeValue & 4 );
42+ }
43+
3344 $ commandArguments [] = new CommandArgument (
3445 $ argumentName ,
3546 $ addArgumentArgs [0 ]->value ,
3647 $ addArgumentArgs [1 ]->value ?? null ,
3748 $ addArgumentArgs [2 ]->value ?? null ,
3849 $ addArgumentArgs [3 ]->value ?? null ,
50+ $ isArray
3951 );
4052 }
4153
Original file line number Diff line number Diff line change @@ -49,7 +49,12 @@ private function createArgumentParams(array $commandArguments): array
4949 foreach ($ commandArguments as $ commandArgument ) {
5050 $ variableName = $ this ->createCamelCase ($ commandArgument ->getNameValue ());
5151 $ argumentParam = new Param (new Variable ($ variableName ));
52- $ argumentParam ->type = new Identifier ('string ' );
52+
53+ if ($ commandArgument ->isArray ()) {
54+ $ argumentParam ->type = new Identifier ('array ' );
55+ } else {
56+ $ argumentParam ->type = new Identifier ('string ' );
57+ }
5358
5459 if ($ commandArgument ->getDefault () instanceof Expr) {
5560 $ argumentParam ->default = $ commandArgument ->getDefault ();
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public function __construct(
1414 private ?Expr $ mode ,
1515 private ?Expr $ description ,
1616 private ?Expr $ default ,
17+ private bool $ isArray
1718 ) {
1819 }
1920
@@ -41,4 +42,9 @@ public function getDefault(): ?Expr
4142 {
4243 return $ this ->default ;
4344 }
45+
46+ public function isArray (): bool
47+ {
48+ return $ this ->isArray ;
49+ }
4450}
You can’t perform that action at this time.
0 commit comments