File tree Expand file tree Collapse file tree 3 files changed +65
-5
lines changed Expand file tree Collapse file tree 3 files changed +65
-5
lines changed Original file line number Diff line number Diff line change 2020 */
2121final class ParamTag extends AbstractTypeableTag
2222{
23- /**
24- * @var string
25- */
2623 protected string $ variableName ;
2724
25+ private bool $ variadic = false ;
26+
2827 /**
2928 * ParamTag constructor.
3029 * @param string|null $variableName
@@ -67,14 +66,35 @@ public function getVariableName(): string
6766 return $ this ->variableName ;
6867 }
6968
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+
7089 /**
7190 * @return string
7291 */
7392 public function generate (): string
7493 {
7594 $ output = '@param '
7695 . (! empty ($ this ->types ) ? ' ' . $ this ->getTypesAsString () : '' )
77- . (! empty ($ this ->variableName ) ? ' $ ' . $ this ->variableName : '' )
96+ . ($ this ->variadic ? ' ... ' : ' ' )
97+ . (! empty ($ this ->variableName ) ? '$ ' . $ this ->variableName : '' )
7898 . (! empty ($ this ->description ) ? ' ' . $ this ->description : '' );
7999
80100 return $ output ;
Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ private function generateAttributes(): array
265265 if ($ typeHint = $ parameter ->getTypeDocBlockHint ()) {
266266 $ types = $ typeHint ;
267267 }
268- $ docBlock ->addTag (new ParamTag ($ parameter ->getName (), $ types ));
268+ $ docBlock ->addTag (( new ParamTag ($ parameter ->getName (), $ types))-> setVariadic ( $ parameter -> getVariadic () ));
269269 }
270270
271271 $ returnType = null ;
Original file line number Diff line number Diff line change @@ -82,6 +82,46 @@ public function getItems() : array;
8282 $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
8383 }
8484
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+
85125 /**
86126 * @test
87127 */
You can’t perform that action at this time.
0 commit comments