This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree 3 files changed +21
-1
lines changed
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public static function fromReflection(ParameterReflection $reflectionParameter)
63
63
64
64
$ param ->setVariadic ($ variadic );
65
65
66
- if (! $ variadic && $ reflectionParameter ->isOptional ()) {
66
+ if (! $ variadic && ( $ reflectionParameter ->isOptional () || $ reflectionParameter -> isDefaultValueAvailable () )) {
67
67
try {
68
68
$ param ->setDefaultValue ($ reflectionParameter ->getDefaultValue ());
69
69
} catch (\ReflectionException $ e ) {
Original file line number Diff line number Diff line change @@ -98,6 +98,21 @@ public function testFromReflectionGetDefaultValue()
98
98
$ this ->assertEquals ('\'foo \'' , (string ) $ defaultValue );
99
99
}
100
100
101
+ public function testFromReflectionGetDefaultValueNotOptional ()
102
+ {
103
+ $ reflectionClass = new \Zend \Code \Reflection \ClassReflection (
104
+ 'ZendTest\Code\Generator\TestAsset\ParameterClass '
105
+ );
106
+ $ method = $ reflectionClass ->getMethod ('defaultObjectEqualsNullAndNotOptional ' );
107
+
108
+ $ params = $ method ->getParameters ();
109
+ $ this ->assertCount (2 , $ params );
110
+
111
+ $ firstParameter = $ codeGenParam = ParameterGenerator::fromReflection ($ params [0 ]);
112
+ $ this ->assertInstanceOf (ValueGenerator::class, $ firstParameter ->getDefaultValue ());
113
+ $ this ->assertNull ($ firstParameter ->getDefaultValue ()->getSourceContent ());
114
+ }
115
+
101
116
public function testFromReflectionGetArrayHint ()
102
117
{
103
118
$ reflectionParameter = $ this ->getFirstReflectionParameter ('fromArray ' );
Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ public function defaultConstant($con = self::FOO)
82
82
83
83
}
84
84
85
+ public function defaultObjectEqualsNullAndNotOptional (\stdClass $ a = null , $ b )
86
+ {
87
+
88
+ }
89
+
85
90
/**
86
91
* @param int $integer
87
92
*/
You can’t perform that action at this time.
0 commit comments