File tree Expand file tree Collapse file tree 5 files changed +52
-5
lines changed Expand file tree Collapse file tree 5 files changed +52
-5
lines changed Original file line number Diff line number Diff line change @@ -185,9 +185,13 @@ public function generate(): ClassMethod
185185 $ docBlockTypes = [];
186186
187187 foreach ($ this ->getParameters () as $ parameter ) {
188- $ type = $ parameter ->getType ()->isNullable ()
189- ? $ parameter ->getType ()->type () . '|null '
190- : $ parameter ->getType ()->type ();
188+ if (null === $ parameter ->getType ()) {
189+ $ type = 'mixed ' ;
190+ } else {
191+ $ type = $ parameter ->getType ()->isNullable ()
192+ ? $ parameter ->getType ()->type () . '|null '
193+ : $ parameter ->getType ()->type ();
194+ }
191195
192196 if ($ typeHint = $ parameter ->getTypeDocBlockHint ()) {
193197 $ type = $ typeHint ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ public function setType($type): self
8888 return $ this ;
8989 }
9090
91- public function getType (): TypeGenerator
91+ public function getType (): ? TypeGenerator
9292 {
9393 return $ this ->type ;
9494 }
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ public function setType(string $type): self
8282 return $ this ;
8383 }
8484
85- public function getType (): TypeGenerator
85+ public function getType (): ? TypeGenerator
8686 {
8787 return $ this ->type ;
8888 }
Original file line number Diff line number Diff line change @@ -56,6 +56,33 @@ public function setType(?string $type);
5656 $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
5757 }
5858
59+ /**
60+ * @test
61+ */
62+ public function it_generates_method_with_mixed_type_doc_block (): void
63+ {
64+ $ method = new MethodGenerator (
65+ 'setType ' ,
66+ [
67+ new ParameterGenerator ('type ' ),
68+ ]
69+ );
70+ $ method ->setDocBlockComment ('Sets an awesome type ' );
71+
72+ $ expectedOutput = <<<'EOF'
73+ <?php
74+
75+ /**
76+ * Sets an awesome type
77+ *
78+ * @var mixed $type
79+ */
80+ public function setType($type);
81+ EOF;
82+
83+ $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
84+ }
85+
5986 /**
6087 * @test
6188 */
Original file line number Diff line number Diff line change @@ -64,6 +64,22 @@ public function it_generates_type(string $type): void
6464<?php
6565
6666$ type \$myParameter
67+ PHP ;
68+
69+ $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ parameter ->generate ()]));
70+ }
71+
72+ /**
73+ * @test
74+ */
75+ public function it_works_without_type ()
76+ {
77+ $ parameter = new ParameterGenerator ('myParameter ' );
78+
79+ $ expectedOutput = <<<PHP
80+ <?php
81+
82+ \$myParameter
6783PHP ;
6884
6985 $ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ parameter ->generate ()]));
You can’t perform that action at this time.
0 commit comments