@@ -27,8 +27,11 @@ final class Factory
27
27
public function fromClassReflection (
28
28
\ReflectionClass $ from ,
29
29
bool $ withBodies = false ,
30
- bool $ materializeTraits = true ,
30
+ ? bool $ materializeTraits = null ,
31
31
): ClassType {
32
+ if ($ materializeTraits !== null ) {
33
+ trigger_error (__METHOD__ . '() parameter $materializeTraits has been removed (is always false). ' , E_USER_DEPRECATED );
34
+ }
32
35
if ($ withBodies && $ from ->isAnonymous ()) {
33
36
throw new Nette \NotSupportedException ('The $withBodies parameter cannot be used for anonymous functions. ' );
34
37
}
@@ -69,9 +72,7 @@ public function fromClassReflection(
69
72
70
73
$ props = [];
71
74
foreach ($ from ->getProperties () as $ prop ) {
72
- $ declaringClass = $ materializeTraits
73
- ? $ prop ->getDeclaringClass ()
74
- : Reflection::getPropertyDeclaringClass ($ prop );
75
+ $ declaringClass = Reflection::getPropertyDeclaringClass ($ prop );
75
76
76
77
if ($ prop ->isDefault ()
77
78
&& $ declaringClass ->name === $ from ->name
@@ -86,40 +87,37 @@ public function fromClassReflection(
86
87
87
88
$ methods = $ resolutions = [];
88
89
foreach ($ from ->getMethods () as $ method ) {
89
- $ realMethod = Reflection::getMethodDeclaringMethod ($ method );
90
- $ declaringClass = ( $ materializeTraits ? $ method : $ realMethod ) ->getDeclaringClass ();
90
+ $ declaringMethod = Reflection::getMethodDeclaringMethod ($ method );
91
+ $ declaringClass = $ declaringMethod ->getDeclaringClass ();
91
92
92
93
if (
93
94
$ declaringClass ->name === $ from ->name
94
95
&& (!$ enumIface || !method_exists ($ enumIface , $ method ->name ))
95
96
) {
96
97
$ methods [] = $ m = $ this ->fromMethodReflection ($ method );
97
98
if ($ withBodies ) {
98
- $ realMethodClass = $ realMethod ->getDeclaringClass ();
99
- $ bodies = &$ this ->bodyCache [$ realMethodClass ->name ];
100
- $ bodies ??= $ this ->getExtractor ($ realMethodClass )->extractMethodBodies ($ realMethodClass ->name );
101
- if (isset ($ bodies [$ realMethod ->name ])) {
102
- $ m ->setBody ($ bodies [$ realMethod ->name ]);
99
+ $ bodies = &$ this ->bodyCache [$ declaringClass ->name ];
100
+ $ bodies ??= $ this ->getExtractor ($ declaringClass )->extractMethodBodies ($ declaringClass ->name );
101
+ if (isset ($ bodies [$ declaringMethod ->name ])) {
102
+ $ m ->setBody ($ bodies [$ declaringMethod ->name ]);
103
103
}
104
104
}
105
105
}
106
106
107
- $ modifier = $ realMethod ->getModifiers () !== $ method ->getModifiers ()
107
+ $ modifier = $ declaringMethod ->getModifiers () !== $ method ->getModifiers ()
108
108
? ' ' . $ this ->getVisibility ($ method )
109
109
: null ;
110
- $ alias = $ realMethod ->name !== $ method ->name ? ' ' . $ method ->name : '' ;
110
+ $ alias = $ declaringMethod ->name !== $ method ->name ? ' ' . $ method ->name : '' ;
111
111
if ($ modifier || $ alias ) {
112
- $ resolutions [] = $ realMethod ->name . ' as ' . $ modifier . $ alias ;
112
+ $ resolutions [] = $ declaringMethod ->name . ' as ' . $ modifier . $ alias ;
113
113
}
114
114
}
115
115
116
116
$ class ->setMethods ($ methods );
117
117
118
- if (!$ materializeTraits ) {
119
- foreach ($ from ->getTraitNames () as $ trait ) {
120
- $ class ->addTrait ($ trait , $ resolutions );
121
- $ resolutions = [];
122
- }
118
+ foreach ($ from ->getTraitNames () as $ trait ) {
119
+ $ class ->addTrait ($ trait , $ resolutions );
120
+ $ resolutions = [];
123
121
}
124
122
125
123
$ consts = $ cases = [];
0 commit comments