File tree 3 files changed +65
-5
lines changed
3 files changed +65
-5
lines changed Original file line number Diff line number Diff line change 20
20
*/
21
21
final class ParamTag extends AbstractTypeableTag
22
22
{
23
- /**
24
- * @var string
25
- */
26
23
protected string $ variableName ;
27
24
25
+ private bool $ variadic = false ;
26
+
28
27
/**
29
28
* ParamTag constructor.
30
29
* @param string|null $variableName
@@ -67,14 +66,35 @@ public function getVariableName(): string
67
66
return $ this ->variableName ;
68
67
}
69
68
69
+ /**
70
+ * @param bool $variadic
71
+ *
72
+ * @return ParamTag
73
+ */
74
+ public function setVariadic ($ variadic ): self
75
+ {
76
+ $ this ->variadic = (bool ) $ variadic ;
77
+
78
+ return $ this ;
79
+ }
80
+
81
+ /**
82
+ * @return bool
83
+ */
84
+ public function getVariadic (): bool
85
+ {
86
+ return $ this ->variadic ;
87
+ }
88
+
70
89
/**
71
90
* @return string
72
91
*/
73
92
public function generate (): string
74
93
{
75
94
$ output = '@param '
76
95
. (! empty ($ this ->types ) ? ' ' . $ this ->getTypesAsString () : '' )
77
- . (! empty ($ this ->variableName ) ? ' $ ' . $ this ->variableName : '' )
96
+ . ($ this ->variadic ? ' ... ' : ' ' )
97
+ . (! empty ($ this ->variableName ) ? '$ ' . $ this ->variableName : '' )
78
98
. (! empty ($ this ->description ) ? ' ' . $ this ->description : '' );
79
99
80
100
return $ output ;
Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ private function generateAttributes(): array
265
265
if ($ typeHint = $ parameter ->getTypeDocBlockHint ()) {
266
266
$ types = $ typeHint ;
267
267
}
268
- $ docBlock ->addTag (new ParamTag ($ parameter ->getName (), $ types ));
268
+ $ docBlock ->addTag (( new ParamTag ($ parameter ->getName (), $ types))-> setVariadic ( $ parameter -> getVariadic () ));
269
269
}
270
270
271
271
$ returnType = null ;
Original file line number Diff line number Diff line change @@ -82,6 +82,46 @@ public function getItems() : array;
82
82
$ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
83
83
}
84
84
85
+ /**
86
+ * @test
87
+ */
88
+ public function it_generates_method_with_variadic_doc_block (): void
89
+ {
90
+ $ method = new MethodGenerator ('setItems ' );
91
+ $ method ->setParameter ((new ParameterGenerator ('items ' ))->setVariadic (true )->setTypeDocBlockHint ('mixed ' ));
92
+ $ method ->setReturnType ('void ' );
93
+ $ method ->setDocBlockComment ('' );
94
+
95
+ $ expectedOutput = <<<'EOF'
96
+ <?php
97
+
98
+ /**
99
+ * @param mixed ...$items
100
+ */
101
+ public function setItems(...$items) : void;
102
+ EOF;
103
+
104
+ $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
105
+ }
106
+
107
+ /**
108
+ * @test
109
+ */
110
+ public function it_generates_method_with_mixed_variadic_without_doc_block (): void
111
+ {
112
+ $ method = new MethodGenerator ('setItems ' );
113
+ $ method ->setParameter ((new ParameterGenerator ('items ' ))->setVariadic (true )->setType ('mixed ' ));
114
+ $ method ->setReturnType ('void ' );
115
+
116
+ $ expectedOutput = <<<'EOF'
117
+ <?php
118
+
119
+ public function setItems(mixed ...$items) : void;
120
+ EOF;
121
+
122
+ $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
123
+ }
124
+
85
125
/**
86
126
* @test
87
127
*/
You can’t perform that action at this time.
0 commit comments