Skip to content

Commit

Permalink
Merge pull request #379 from proophsoftware/fix/interface_method_body…
Browse files Browse the repository at this point in the history
…_ast_is_null

Return empty ast for interface method body
  • Loading branch information
Ocramius authored Nov 1, 2017
2 parents bbeaf81 + 578bcbe commit 9583638
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Reflection/ReflectionFunctionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function __clone()
*/
public function getBodyAst() : array
{
return $this->node->stmts;
return $this->node->stmts ?: [];
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/unit/Fixture/InterfaceWithMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflectionTest\Fixture;

interface InterfaceWithMethod
{
public function someMethod();
}
9 changes: 9 additions & 0 deletions test/unit/Reflection/ReflectionMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Roave\BetterReflectionTest\Fixture\ClassWithNonStaticMethod;
use Roave\BetterReflectionTest\Fixture\ClassWithStaticMethod;
use Roave\BetterReflectionTest\Fixture\ExampleClass;
use Roave\BetterReflectionTest\Fixture\InterfaceWithMethod;
use Roave\BetterReflectionTest\Fixture\Methods;
use Roave\BetterReflectionTest\Fixture\Php4StyleConstructInNamespace;
use Roave\BetterReflectionTest\Fixture\UpperCaseConstructDestruct;
Expand Down Expand Up @@ -615,4 +616,12 @@ public function testInvokeOfObjectMethod() : void
self::assertSame(103, $methodReflection->invoke($object, 1, 2));
self::assertSame(107, $methodReflection->invoke($object, 3, 4));
}

public function testInterfaceMethodBodyAst() : void
{
$classInfo = $this->reflector->reflect(InterfaceWithMethod::class);
$methodInfo = $classInfo->getMethod('someMethod');

self::assertSame([], $methodInfo->getBodyAst());
}
}

0 comments on commit 9583638

Please sign in to comment.