File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed
Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ class ClassType extends Nette\Object
6565 */
6666 public static function from ($ from )
6767 {
68- $ from = $ from instanceof \ReflectionClass ? $ from : new \ ReflectionClass ( $ from );
68+ $ from = new \ ReflectionClass ( $ from instanceof \ReflectionClass ? $ from-> getName () : $ from );
6969 if (PHP_VERSION_ID >= 70000 && $ from ->isAnonymous ()) {
7070 $ class = new static ('anonymous ' );
7171 } else {
@@ -81,12 +81,12 @@ public static function from($from)
8181 $ class ->implements = array_diff ($ class ->implements , $ from ->getParentClass ()->getInterfaceNames ());
8282 }
8383 foreach ($ from ->getProperties () as $ prop ) {
84- if ($ prop ->getDeclaringClass () == $ from) { // intentionally ==
84+ if ($ prop ->getDeclaringClass ()-> getName () === $ from-> getName ()) {
8585 $ class ->properties [$ prop ->getName ()] = Property::from ($ prop );
8686 }
8787 }
8888 foreach ($ from ->getMethods () as $ method ) {
89- if ($ method ->getDeclaringClass () == $ from) { // intentionally ==
89+ if ($ method ->getDeclaringClass ()-> getName () === $ from-> getName ()) {
9090 $ class ->methods [$ method ->getName ()] = Method::from ($ method )->setNamespace ($ class ->namespace );
9191 }
9292 }
Original file line number Diff line number Diff line change @@ -57,4 +57,10 @@ class Class2 extends Class1 implements Interface2
5757 {
5858 }
5959
60- }
60+ }
61+
62+ class Class3
63+ {
64+ public $prop1;
65+
66+ }
Original file line number Diff line number Diff line change 77namespace Abc ;
88
99use Nette \PhpGenerator \ClassType ;
10- use ReflectionClass ;
1110use Tester \Assert ;
1211
1312
@@ -62,10 +61,17 @@ class Class2 extends Class1 implements Interface2
6261 {}
6362}
6463
64+ class Class3
65+ {
66+ public $ prop1 ;
67+ }
6568
6669$ res [] = ClassType::from ('Abc\Interface1 ' );
6770$ res [] = ClassType::from ('Abc\Interface2 ' );
6871$ res [] = ClassType::from ('Abc\Class1 ' );
69- $ res [] = ClassType::from (new ReflectionClass ('Abc\Class2 ' ));
72+ $ res [] = ClassType::from (new \ReflectionClass ('Abc\Class2 ' ));
73+ $ obj = new Class3 ;
74+ $ obj ->prop2 = 1 ;
75+ $ res [] = ClassType::from (new \ReflectionObject ($ obj ));
7076
7177Assert::matchFile (__DIR__ . '/ClassType.from.expect ' , implode ("\n" , $ res ));
You can’t perform that action at this time.
0 commit comments