Skip to content

Commit 0587bdc

Browse files
committed
Adds location to class
1 parent 4fc0979 commit 0587bdc

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/phpDocumentor/Reflection/Php/Class_.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpDocumentor\Reflection\DocBlock;
1616
use phpDocumentor\Reflection\Element;
1717
use phpDocumentor\Reflection\Fqsen;
18+
use phpDocumentor\Reflection\Location;
1819

1920
/**
2021
* Descriptor representing a Class.
@@ -59,6 +60,11 @@ final class Class_ implements Element
5960
/** @var Fqsen[] $usedTraits References to traits consumed by this class */
6061
private $usedTraits = array();
6162

63+
/**
64+
* @var null|Location
65+
*/
66+
private $location;
67+
6268
/**
6369
* Initializes a number of properties with the given values. Others are initialized by definition.
6470
*
@@ -67,19 +73,22 @@ final class Class_ implements Element
6773
* @param Fqsen $parent
6874
* @param bool $abstract
6975
* @param bool $final
76+
* @param Location|null $location
7077
*/
7178
public function __construct(
7279
Fqsen $fqsen,
7380
DocBlock $docBlock = null,
7481
Fqsen $parent = null,
7582
$abstract = false,
76-
$final = false
83+
$final = false,
84+
Location $location = null
7785
) {
7886
$this->fqsen = $fqsen;
7987
$this->parent = $parent;
8088
$this->docBlock = $docBlock;
8189
$this->abstract = $abstract;
8290
$this->final = $final;
91+
$this->location = $location;
8392
}
8493

8594
/**
@@ -243,4 +252,12 @@ public function getDocBlock()
243252
{
244253
return $this->docBlock;
245254
}
255+
256+
/**
257+
* @return null|Location
258+
*/
259+
public function getLocation()
260+
{
261+
return $this->location;
262+
}
246263
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use InvalidArgumentException;
1717
use phpDocumentor\Reflection\Element;
1818
use phpDocumentor\Reflection\Fqsen;
19+
use phpDocumentor\Reflection\Location;
1920
use phpDocumentor\Reflection\Php\Class_ as ClassElement;
2021
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
2122
use phpDocumentor\Reflection\Php\StrategyContainer;
@@ -65,7 +66,8 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
6566
$docBlock,
6667
$object->extends ? new Fqsen('\\' . $object->extends) : null,
6768
$object->isAbstract(),
68-
$object->isFinal()
69+
$object->isFinal(),
70+
new Location($object->getLine())
6971
);
7072

7173
if (isset($object->implements)) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Mockery as m;
1616
use phpDocumentor\Reflection\DocBlock;
1717
use phpDocumentor\Reflection\Fqsen;
18+
use phpDocumentor\Reflection\Location;
1819

1920
/**
2021
* Tests the functionality for the Class_ class.
@@ -52,7 +53,7 @@ protected function setUp()
5253
$this->fqsen = new Fqsen('\MyClass');
5354
$this->docBlock = new DocBlock('');
5455

55-
$this->fixture = new Class_($this->fqsen, $this->docBlock, null, false, false);
56+
$this->fixture = new Class_($this->fqsen, $this->docBlock, null, false, false, new Location(1));
5657
}
5758

5859
/**
@@ -61,10 +62,10 @@ protected function setUp()
6162
*/
6263
public function testGettingParent()
6364
{
64-
$class = new Class_($this->fqsen, $this->docBlock, null, false, false);
65+
$class = new Class_($this->fqsen, $this->docBlock, null, false, false, null);
6566
$this->assertNull($class->getParent());
6667

67-
$class = new Class_($this->fqsen, $this->docBlock, $this->parent, false, false);
68+
$class = new Class_($this->fqsen, $this->docBlock, $this->parent, false, false, null);
6869
$this->assertSame($this->parent, $class->getParent());
6970
}
7071

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ private function buildClassMock()
264264
$classMock->fqsen = new Fqsen('\Space\MyClass');
265265
$classMock->shouldReceive('isFinal')->andReturn(true);
266266
$classMock->shouldReceive('isAbstract')->andReturn(true);
267+
$classMock->shouldReceive('getLine')->andReturn(1);
267268
return $classMock;
268269
}
269270
}

0 commit comments

Comments
 (0)