@@ -24,11 +24,9 @@ class Factory
24
24
*/
25
25
public function fromClassReflection (\ReflectionClass $ from )
26
26
{
27
- if (PHP_VERSION_ID >= 70000 && $ from ->isAnonymous ()) {
28
- $ class = new ClassType ;
29
- } else {
30
- $ class = new ClassType ($ from ->getShortName (), new PhpNamespace ($ from ->getNamespaceName ()));
31
- }
27
+ $ class = $ from ->isAnonymous ()
28
+ ? new ClassType
29
+ : new ClassType ($ from ->getShortName (), new PhpNamespace ($ from ->getNamespaceName ()));
32
30
$ class ->setType ($ from ->isInterface () ? 'interface ' : ($ from ->isTrait () ? 'trait ' : 'class ' ));
33
31
$ class ->setFinal ($ from ->isFinal () && $ class ->getType () === 'class ' );
34
32
$ class ->setAbstract ($ from ->isAbstract () && $ class ->getType () === 'class ' );
@@ -71,7 +69,7 @@ public function fromMethodReflection(\ReflectionMethod $from)
71
69
$ method ->setReturnReference ($ from ->returnsReference ());
72
70
$ method ->setVariadic ($ from ->isVariadic ());
73
71
$ method ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
74
- if (PHP_VERSION_ID >= 70000 && $ from ->hasReturnType ()) {
72
+ if ($ from ->hasReturnType ()) {
75
73
$ method ->setReturnType ((string ) $ from ->getReturnType ());
76
74
$ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
77
75
}
@@ -91,7 +89,7 @@ public function fromFunctionReflection(\ReflectionFunction $from)
91
89
if (!$ from ->isClosure ()) {
92
90
$ function ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
93
91
}
94
- if (PHP_VERSION_ID >= 70000 && $ from ->hasReturnType ()) {
92
+ if ($ from ->hasReturnType ()) {
95
93
$ function ->setReturnType ((string ) $ from ->getReturnType ());
96
94
$ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
97
95
}
@@ -106,22 +104,8 @@ public function fromParameterReflection(\ReflectionParameter $from)
106
104
{
107
105
$ param = new Parameter ($ from ->getName ());
108
106
$ param ->setReference ($ from ->isPassedByReference ());
109
- if (PHP_VERSION_ID >= 70000 ) {
110
- $ param ->setTypeHint ($ from ->hasType () ? (string ) $ from ->getType () : NULL );
111
- $ param ->setNullable ($ from ->hasType () && $ from ->getType ()->allowsNull ());
112
- } elseif ($ from ->isArray () || $ from ->isCallable ()) {
113
- $ param ->setTypeHint ($ from ->isArray () ? 'array ' : 'callable ' );
114
- } else {
115
- try {
116
- $ param ->setTypeHint ($ from ->getClass () ? $ from ->getClass ()->getName () : NULL );
117
- } catch (\ReflectionException $ e ) {
118
- if (preg_match ('#Class (.+) does not exist# ' , $ e ->getMessage (), $ m )) {
119
- $ param ->setTypeHint ($ m [1 ]);
120
- } else {
121
- throw $ e ;
122
- }
123
- }
124
- }
107
+ $ param ->setTypeHint ($ from ->hasType () ? (string ) $ from ->getType () : NULL );
108
+ $ param ->setNullable ($ from ->hasType () && $ from ->getType ()->allowsNull ());
125
109
if ($ from ->isDefaultValueAvailable ()) {
126
110
$ param ->setOptional (TRUE );
127
111
$ param ->setDefaultValue ($ from ->isDefaultValueConstant ()
@@ -139,8 +123,7 @@ public function fromParameterReflection(\ReflectionParameter $from)
139
123
public function fromPropertyReflection (\ReflectionProperty $ from )
140
124
{
141
125
$ prop = new Property ($ from ->getName ());
142
- $ defaults = $ from ->getDeclaringClass ()->getDefaultProperties ();
143
- $ prop ->setValue (isset ($ defaults [$ prop ->getName ()]) ? $ defaults [$ prop ->getName ()] : NULL );
126
+ $ prop ->setValue ($ from ->getDeclaringClass ()->getDefaultProperties ()[$ prop ->getName ()] ?? NULL );
144
127
$ prop ->setStatic ($ from ->isStatic ());
145
128
$ prop ->setVisibility ($ from ->isPrivate () ? 'private ' : ($ from ->isProtected () ? 'protected ' : 'public ' ));
146
129
$ prop ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
0 commit comments