Depends on ReflectionClass being implemented fully, in #7
I'm not 100% sure how this should be implemented, as ReflectionMethod::getPrototype() docs are pretty vague, and also the fixture below, from which I tested against core reflection and created a test case (see below) seems inconsistent.
From what I understand, ClassB::foo prototype is ClassA::foo, yet ClassC::foo which directly implements FooInterface descends into FooInterface::foo as the prototype.
It looks like traits are ignored for deciding the prototypes, which makes things slightly easier at least. Either way, we depend on ReflectionClass::getInterfaces() and ReflectionClass::getParentClass() to be implemented before we can do this (see #7).
Fixture, PrototypeTree.php
<?php
interface FooInterface {
public function foo($a, $b);
}
abstract class ClassA implements FooInterface {
abstract public function foo($a, $b);
}
class ClassB extends ClassA {
public function foo($a, $b = 123) {}
}
class ClassC implements FooInterface {
public function foo($a, $b = 123) {}
}
interface BarInterface {
public function bar();
}
trait MyTrait {
abstract public function bar();
}
class ClassT {
use MyTrait;
public function bar() {}
}
Failing test case:
public function testGetPrototype()
{
$fixture = __DIR__ . '/../Fixture/PrototypeTree.php';
$reflector = new ClassReflector(new SingleFileSourceLocator($fixture));
$b = $reflector->reflect('ClassB')->getMethod('foo')->getPrototype();
$this->assertInstanceOf(ReflectionMethod::class, $b);
$this->assertSame('ClassA', $b->getDeclaringClass()->getName());
$c = $reflector->reflect('ClassC')->getMethod('foo')->getPrototype();
$this->assertInstanceOf(ReflectionMethod::class, $c);
$this->assertSame('FooInterface', $c->getDeclaringClass()->getName());
$this->setExpectedException(MethodPrototypeNotFound::class);
$t = $reflector->reflect('ClassT')->getMethod('bar')->getPrototype();
}
Depends on ReflectionClass being implemented fully, in #7
I'm not 100% sure how this should be implemented, as ReflectionMethod::getPrototype() docs are pretty vague, and also the fixture below, from which I tested against core reflection and created a test case (see below) seems inconsistent.
From what I understand,
ClassB::fooprototype isClassA::foo, yetClassC::foowhich directly implementsFooInterfacedescends intoFooInterface::fooas the prototype.It looks like traits are ignored for deciding the prototypes, which makes things slightly easier at least. Either way, we depend on
ReflectionClass::getInterfaces()andReflectionClass::getParentClass()to be implemented before we can do this (see #7).Fixture,
PrototypeTree.phpFailing test case: