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
185
185
$ docBlockTypes = [];
186
186
187
187
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
+ }
191
195
192
196
if ($ typeHint = $ parameter ->getTypeDocBlockHint ()) {
193
197
$ type = $ typeHint ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ public function setType($type): self
88
88
return $ this ;
89
89
}
90
90
91
- public function getType (): TypeGenerator
91
+ public function getType (): ? TypeGenerator
92
92
{
93
93
return $ this ->type ;
94
94
}
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ public function setType(string $type): self
82
82
return $ this ;
83
83
}
84
84
85
- public function getType (): TypeGenerator
85
+ public function getType (): ? TypeGenerator
86
86
{
87
87
return $ this ->type ;
88
88
}
Original file line number Diff line number Diff line change @@ -56,6 +56,33 @@ public function setType(?string $type);
56
56
$ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ method ->generate ()]));
57
57
}
58
58
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
+
59
86
/**
60
87
* @test
61
88
*/
Original file line number Diff line number Diff line change @@ -64,6 +64,22 @@ public function it_generates_type(string $type): void
64
64
<?php
65
65
66
66
$ 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
67
83
PHP ;
68
84
69
85
$ this ->assertSame ($ expectedOutput , $ this ->printer ->prettyPrintFile ([$ parameter ->generate ()]));
You can’t perform that action at this time.
0 commit comments