@@ -27,8 +27,11 @@ final class Factory
2727 public function fromClassReflection (
2828 \ReflectionClass $ from ,
2929 bool $ withBodies = false ,
30- bool $ materializeTraits = true ,
30+ ? bool $ materializeTraits = null ,
3131 ): ClassType {
32+ if ($ materializeTraits !== null ) {
33+ trigger_error (__METHOD__ . '() parameter $materializeTraits has been removed (is always false). ' , E_USER_DEPRECATED );
34+ }
3235 if ($ withBodies && $ from ->isAnonymous ()) {
3336 throw new Nette \NotSupportedException ('The $withBodies parameter cannot be used for anonymous functions. ' );
3437 }
@@ -69,9 +72,7 @@ public function fromClassReflection(
6972
7073 $ props = [];
7174 foreach ($ from ->getProperties () as $ prop ) {
72- $ declaringClass = $ materializeTraits
73- ? $ prop ->getDeclaringClass ()
74- : Reflection::getPropertyDeclaringClass ($ prop );
75+ $ declaringClass = Reflection::getPropertyDeclaringClass ($ prop );
7576
7677 if ($ prop ->isDefault ()
7778 && $ declaringClass ->name === $ from ->name
@@ -86,40 +87,37 @@ public function fromClassReflection(
8687
8788 $ methods = $ resolutions = [];
8889 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 ();
9192
9293 if (
9394 $ declaringClass ->name === $ from ->name
9495 && (!$ enumIface || !method_exists ($ enumIface , $ method ->name ))
9596 ) {
9697 $ methods [] = $ m = $ this ->fromMethodReflection ($ method );
9798 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 ]);
103103 }
104104 }
105105 }
106106
107- $ modifier = $ realMethod ->getModifiers () !== $ method ->getModifiers ()
107+ $ modifier = $ declaringMethod ->getModifiers () !== $ method ->getModifiers ()
108108 ? ' ' . $ this ->getVisibility ($ method )
109109 : null ;
110- $ alias = $ realMethod ->name !== $ method ->name ? ' ' . $ method ->name : '' ;
110+ $ alias = $ declaringMethod ->name !== $ method ->name ? ' ' . $ method ->name : '' ;
111111 if ($ modifier || $ alias ) {
112- $ resolutions [] = $ realMethod ->name . ' as ' . $ modifier . $ alias ;
112+ $ resolutions [] = $ declaringMethod ->name . ' as ' . $ modifier . $ alias ;
113113 }
114114 }
115115
116116 $ class ->setMethods ($ methods );
117117
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 = [];
123121 }
124122
125123 $ consts = $ cases = [];
0 commit comments