This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-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 11
11
12
12
use Zend \Code \Generator \ParameterGenerator ;
13
13
use Zend \Code \Generator \ValueGenerator ;
14
+ use Zend \Code \Reflection \MethodReflection ;
14
15
use Zend \Code \Reflection \ParameterReflection ;
16
+ use ZendTest \Code \Generator \TestAsset \ParameterClass ;
15
17
use ZendTest \Code \TestAsset \ClassTypeHintedClass ;
16
18
use ZendTest \Code \TestAsset \DocBlockOnlyHintsClass ;
17
19
use ZendTest \Code \TestAsset \InternalHintsClass ;
@@ -98,6 +100,22 @@ public function testFromReflectionGetDefaultValue()
98
100
$ this ->assertEquals ('\'foo \'' , (string ) $ defaultValue );
99
101
}
100
102
103
+ /**
104
+ * @group 95
105
+ */
106
+ public function testFromReflectionGetDefaultValueNotOptional ()
107
+ {
108
+ $ method = new MethodReflection (ParameterClass::class, 'defaultObjectEqualsNullAndNotOptional ' );
109
+
110
+ $ params = $ method ->getParameters ();
111
+
112
+ $ this ->assertCount (2 , $ params );
113
+
114
+ $ firstParameter = ParameterGenerator::fromReflection ($ params [0 ]);
115
+ $ this ->assertInstanceOf (ValueGenerator::class, $ firstParameter ->getDefaultValue ());
116
+ $ this ->assertNull ($ firstParameter ->getDefaultValue ()->getSourceContent ());
117
+ }
118
+
101
119
public function testFromReflectionGetArrayHint ()
102
120
{
103
121
$ 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