Skip to content

Commit 7c965ce

Browse files
committed
Factory: fixed extended interfaces [Closes #87]
1 parent 59bb35e commit 7c965ce

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/PhpGenerator/Factory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function fromClassReflection(\ReflectionClass $from, bool $withBodies = f
3737
return !is_subclass_of($iface, $item);
3838
});
3939
}
40-
$class->setImplements($ifaces);
40+
if ($from->isInterface()) {
41+
$class->setExtends($ifaces);
42+
} else {
43+
$class->setImplements($ifaces);
44+
}
4145

4246
$class->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
4347
$class->setAttributes(self::getAttributes($from));

tests/PhpGenerator/ClassType.from.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require __DIR__ . '/../bootstrap.php';
1515

1616
$res[] = ClassType::from(Abc\Interface1::class);
1717
$res[] = ClassType::from(Abc\Interface2::class);
18+
$res[] = ClassType::from(Abc\Interface3::class);
19+
$res[] = ClassType::from(Abc\Interface4::class);
1820
$res[] = ClassType::from(Abc\Class1::class);
1921
$res[] = ClassType::from(new Abc\Class2);
2022
$obj = new Abc\Class3;

tests/PhpGenerator/expected/ClassType.from.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ interface Interface2
1111
{
1212
}
1313

14+
interface Interface3 extends Interface1
15+
{
16+
}
17+
18+
interface Interface4 extends Interface3, Interface2
19+
{
20+
}
21+
1422
abstract class Class1 implements Interface1
1523
{
1624
/**

tests/PhpGenerator/fixtures/classes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ interface Interface2
1919
}
2020

2121

22+
interface Interface3 extends Interface1
23+
{
24+
}
25+
26+
interface Interface4 extends Interface3, Interface2
27+
{
28+
}
29+
2230
abstract class Class1 implements Interface1
2331
{
2432
/** @return Class1 */

0 commit comments

Comments
 (0)