Skip to content

Commit 87e4789

Browse files
committed
Merge pull request #74 from jaapio/feature/interfaceExtends
add interface parents
2 parents da27bc2 + df17108 commit 87e4789

File tree

8 files changed

+73
-7
lines changed

8 files changed

+73
-7
lines changed

src/phpDocumentor/Reflection/Php/Factory/Interface_.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Reflection\Php\Factory;
1515
use InvalidArgumentException;
1616
use phpDocumentor\Reflection\Element;
17+
use phpDocumentor\Reflection\Fqsen;
1718
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1819
use phpDocumentor\Reflection\Php\StrategyContainer;
1920
use phpDocumentor\Reflection\Types\Context;
@@ -63,8 +64,12 @@ public function create($object, StrategyContainer $strategies, Context $context
6364
}
6465

6566
$docBlock = $this->createDocBlock($object->getDocComment(), $strategies, $context);
67+
$parents = array();
68+
foreach ($object->extends as $extend) {
69+
$parents['\\' . (string)$extend] = new Fqsen('\\' . (string)$extend);
70+
}
6671

67-
$interface = new InterfaceElement($object->fqsen, $docBlock);
72+
$interface = new InterfaceElement($object->fqsen, $parents, $docBlock);
6873

6974
if (isset($object->stmts)) {
7075
foreach ($object->stmts as $stmt) {

src/phpDocumentor/Reflection/Php/Interface_.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ final class Interface_ implements Element
3636
/** @var Method[] $methods */
3737
protected $methods = array();
3838

39+
/** @var Fqsen[] $parents */
40+
protected $parents = array();
41+
3942
/**
4043
* Initializes the object.
4144
*
4245
* @param Fqsen $fqsen
46+
* @param Fqsen[] $parents
4347
* @param DocBlock $docBlock
4448
*/
45-
public function __construct(Fqsen $fqsen, DocBlock $docBlock = null)
49+
public function __construct(Fqsen $fqsen, array $parents = array(), DocBlock $docBlock = null)
4650
{
4751
$this->fqsen = $fqsen;
4852
$this->docBlock = $docBlock;
53+
$this->parents = $parents;
4954
}
5055

5156
/**
@@ -119,4 +124,14 @@ public function getDocBlock()
119124
{
120125
return $this->docBlock;
121126
}
127+
128+
/**
129+
* Returns the Fqsen of the interfaces this interface is extending.
130+
*
131+
* @return Fqsen[]
132+
*/
133+
public function getParents()
134+
{
135+
return $this->parents;
136+
}
122137
}

tests/component/ProjectCreationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,18 @@ public function testWithTrait()
165165

166166
$this->assertArrayHasKey('\\Luigi\\ExampleNestedTrait', $project->getFiles()[$fileName]->getTraits());
167167
}
168+
169+
public function testInterfaceExtends()
170+
{
171+
$fileName = __DIR__ . '/project/Luigi/Packing.php';
172+
$project = $this->fixture->create([
173+
$fileName
174+
]);
175+
176+
$this->assertArrayHasKey('\\Luigi\\Packing', $project->getFiles()[$fileName]->getInterfaces());
177+
$interface = current($project->getFiles()[$fileName]->getInterfaces());
178+
179+
$this->assertEquals(['\\Packing' => new Fqsen('\\Packing')], $interface->getParents());
180+
181+
}
168182
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2015-2015 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace Luigi;
14+
15+
interface Packing extends \Packing
16+
{
17+
18+
}

tests/component/project/Packing.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2015-2015 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
interface Packing
14+
{
15+
public function getName();
16+
}

tests/unit/phpDocumentor/Reflection/Php/Factory/Interface_Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private function buildClassMock()
156156
{
157157
$interfaceMock = m::mock(InterfaceNode::class);
158158
$interfaceMock->fqsen = new Fqsen('\Space\MyInterface');
159+
$interfaceMock->extends = [];
159160
return $interfaceMock;
160161
}
161162
}

tests/unit/phpDocumentor/Reflection/Php/FileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testAddAndGetInterfaces()
9999
{
100100
$this->assertEmpty($this->fixture->getInterfaces());
101101

102-
$interface = new Interface_(new Fqsen('\MySpace\MyInterface'));
102+
$interface = new Interface_(new Fqsen('\MySpace\MyInterface'), array());
103103
$this->fixture->addInterface($interface);
104104

105105
$this->assertEquals(array('\MySpace\MyInterface' => $interface), $this->fixture->getInterfaces());

tests/unit/phpDocumentor/Reflection/Php/Interface_Test.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
namespace phpDocumentor\Reflection\Php;
1414

1515
use Mockery as m;
16-
use phpDocumentor\Reflection\Php\Tag\AuthorDescriptor;
17-
use phpDocumentor\Reflection\Php\Tag\VersionDescriptor;
1816
use phpDocumentor\Reflection\DocBlock;
1917
use phpDocumentor\Reflection\Fqsen;
20-
use PhpParser\Comment\Doc;
2118

2219
/**
2320
* Tests the functionality for the Interface_ class.
@@ -45,7 +42,7 @@ protected function setUp()
4542
{
4643
$this->fqsen = new Fqsen('\MySpace\MyInterface');
4744
$this->docBlock = new DocBlock('');
48-
$this->fixture = new Interface_($this->fqsen, $this->docBlock);
45+
$this->fixture = new Interface_($this->fqsen, array(), $this->docBlock);
4946
}
5047

5148
/**

0 commit comments

Comments
 (0)