Skip to content

Commit

Permalink
Merge pull request #656 from kukulich/prototype
Browse files Browse the repository at this point in the history
`ReflectionMethod::getPrototype()` should report implementing vlass prototype, and skip constructors
  • Loading branch information
Ocramius committed Jun 10, 2020
2 parents 7a3cb05 + 3a484fe commit 18bb4a7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Reflection/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getAliasName() : ?string
*/
public function getPrototype() : self
{
$currentClass = $this->getDeclaringClass();
$currentClass = $this->getImplementingClass();

while ($currentClass) {
foreach ($currentClass->getImmediateInterfaces() as $interface) {
Expand All @@ -121,6 +121,10 @@ public function getPrototype() : self
$prototype = $currentClass->getMethod($this->getName())->findPrototype();

if ($prototype !== null) {
if ($this->isConstructor() && ! $prototype->isAbstract()) {
break;
}

return $prototype;
}
}
Expand Down
47 changes: 47 additions & 0 deletions test/unit/Fixture/PrototypeTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,50 @@ interface Boo extends Bar {}
class A implements Foo {}
class B extends A implements Boo {}
}

namespace Construct {
class Foo
{
public function __construct(int $i)
{
}
}

class Bar extends Foo
{
public function __construct(string $s)
{
}
}

abstract class Lorem
{
abstract public function __construct(int $i);
}

class Ipsum extends Lorem
{
public function __construct(int $i)
{
}
}
}

namespace Traits {
interface FooInterface
{
public function doFoo(): void;
}

trait FooTrait
{
public function doFoo(): void
{
}
}

class Foo implements FooInterface
{
use FooTrait;
}
}
3 changes: 3 additions & 0 deletions test/unit/Reflection/ReflectionMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public function prototypeProvider() : array
['Foom\A', 'foo', 'Foom\Foo'],
['ClassE', 'boo', 'ClassC'],
['ClassF', 'zoo', 'ClassD'],
['Construct\Bar', '__construct', null],
['Construct\Ipsum', '__construct', 'Construct\Lorem'],
['Traits\Foo', 'doFoo', 'Traits\FooInterface'],
];
}

Expand Down

0 comments on commit 18bb4a7

Please sign in to comment.