Skip to content

Commit 1352ef5

Browse files
committed
Renamed LongDescription to Description, to better serve its new dual role as "holder for a place where inline tags can occur";
Removed Tag::setDocblock() in favor of an additional constructor argument that defaults to NULL; Tag::createInstance() and Description's constructor now have a second argument, allowing the specification of an owning DocBlock; Description::getParsedContents() assigns the Description's owning DocBlock object when creating tags.
1 parent 6df31db commit 1352ef5

File tree

4 files changed

+50
-48
lines changed

4 files changed

+50
-48
lines changed

src/phpDocumentor/Reflection/DocBlock.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function __construct(
8383

8484
list($short, $long, $tags) = $this->splitDocBlock($docblock);
8585
$this->short_description = $short;
86-
$this->long_description = new DocBlock\LongDescription($long);
86+
$this->long_description = new DocBlock\Description($long);
8787
$this->parseTags($tags);
8888

8989
$this->namespace = $namespace;
@@ -222,9 +222,7 @@ protected function parseTags($tags)
222222

223223
// create proper Tag objects
224224
foreach ($result as $key => $tag_line) {
225-
$tag = DocBlock\Tag::createInstance($tag_line);
226-
$tag->setDocBlock($this);
227-
$result[$key] = $tag;
225+
$result[$key] = DocBlock\Tag::createInstance($tag_line, $this);
228226
}
229227
}
230228

src/phpDocumentor/Reflection/DocBlock/LongDescription.php renamed to src/phpDocumentor/Reflection/DocBlock/Description.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
namespace phpDocumentor\Reflection\DocBlock;
1414

1515
/**
16-
* Parses a Long Description of a DocBlock.
16+
* Parses a Description of a DocBlock or tag.
1717
*
1818
* @author Mike van Riel <[email protected]>
1919
* @license http://www.opensource.org/licenses/mit-license.php MIT
2020
* @link http://phpdoc.org
2121
*/
22-
class LongDescription implements \Reflector
22+
class Description implements \Reflector
2323
{
2424
/** @var string */
2525
protected $contents = '';
@@ -30,15 +30,20 @@ class LongDescription implements \Reflector
3030
/** @var \phpDocumentor\Reflection\DocBlock\Tags[] */
3131
protected $tags = array();
3232

33+
/** @var DocBlock The DocBlock which this description belongs to. */
34+
protected $docblock = null;
35+
3336
/**
3437
* Parses the string for inline tags and if the Markdown class is included;
3538
* format the found text.
3639
*
37-
* @param string $content the DocBlock contents without asterisks.
40+
* @param string $content The DocBlock contents without asterisks.
41+
* @param DocBlock $docblock The DocBlock which this description belongs to.
3842
*/
39-
public function __construct($content)
43+
public function __construct($content, DocBlock $docblock = null)
4044
{
4145
$this->contents = trim($content);
46+
$this->docblock = $docblock;
4247
}
4348

4449
/**
@@ -97,7 +102,8 @@ public function getParsedContents()
97102
);
98103
for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) {
99104
$this->parsedContents[$i] = Tag::createInstance(
100-
$this->parsedContents[$i]
105+
$this->parsedContents[$i],
106+
$this->docblock
101107
);
102108
}
103109

src/phpDocumentor/Reflection/DocBlock/Tag.php

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace phpDocumentor\Reflection\DocBlock;
1414

15+
use phpDocumentor\Reflection\DocBlock;
16+
1517
/**
1618
* Parses a tag definition for a DocBlock.
1719
*
@@ -36,8 +38,8 @@ class Tag implements \Reflector
3638
/** @var int Line number of the tag */
3739
protected $line_number = 0;
3840

39-
/** @var \phpDocumentor\Reflection\DocBlock docblock class */
40-
protected $docblock;
41+
/** @var DocBlock The DocBlock which this tag belongs to. */
42+
protected $docblock = null;
4143

4244
/**
4345
* @var array An array with a tag as a key, and an FQCN to a class that
@@ -78,14 +80,17 @@ class Tag implements \Reflector
7880
/**
7981
* Factory method responsible for instantiating the correct sub type.
8082
*
81-
* @param string $tag_line The text for this tag, including description.
83+
* @param string $tag_line The text for this tag, including description.
84+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
8285
*
8386
* @throws \InvalidArgumentException if an invalid tag line was presented.
8487
*
85-
* @return \phpDocumentor\Reflection\DocBlock\Tag
88+
* @return static A new tag object.
8689
*/
87-
final public static function createInstance($tag_line)
88-
{
90+
final public static function createInstance(
91+
$tag_line,
92+
DocBlock $docblock = null
93+
) {
8994
if (!preg_match(
9095
'/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us',
9196
$tag_line,
@@ -100,10 +105,15 @@ final public static function createInstance($tag_line)
100105
$handler = self::$tagHandlerMappings[$matches[1]];
101106
return new $handler(
102107
$matches[1],
103-
isset($matches[2]) ? $matches[2] : ''
108+
isset($matches[2]) ? $matches[2] : '',
109+
$docblock
104110
);
105111
}
106-
return new self($matches[1], isset($matches[2]) ? $matches[2] : '');
112+
return new self(
113+
$matches[1],
114+
isset($matches[2]) ? $matches[2] : '',
115+
$docblock
116+
);
107117
}
108118

109119
/**
@@ -141,14 +151,16 @@ final public static function registerTagHandler($tag, $handler)
141151
/**
142152
* Parses a tag and populates the member variables.
143153
*
144-
* @param string $type Name of the tag.
145-
* @param string $content The contents of the given tag.
154+
* @param string $type Name of the tag.
155+
* @param string $content The contents of the given tag.
156+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
146157
*/
147-
public function __construct($type, $content)
158+
public function __construct($type, $content, DocBlock $docblock = null)
148159
{
149160
$this->tag = $type;
150161
$this->content = $content;
151162
$this->description = $content;
163+
$this->docblock = $docblock;
152164
}
153165

154166
/**
@@ -190,7 +202,7 @@ public function getDescription()
190202
public function getParsedDescription()
191203
{
192204
if (null === $this->parsedDescription) {
193-
$description = new LongDescription($this->description);
205+
$description = new Description($this->description, $this->docblock);
194206
$this->parsedDescription = $description->getParsedContents();
195207
}
196208
return $this->parsedDescription;
@@ -218,20 +230,6 @@ public function getLineNumber()
218230
return $this->line_number;
219231
}
220232

221-
/**
222-
* Inject the docblock class
223-
*
224-
* This exposes some common functionality contained in the docblock abstract.
225-
*
226-
* @param object $docblock Object containing the DocBlock.
227-
*
228-
* @return void
229-
*/
230-
public function setDocBlock($docblock)
231-
{
232-
$this->docblock = $docblock;
233-
}
234-
235233
/**
236234
* Builds a string representation of this object.
237235
*

tests/phpDocumentor/Reflection/DocBlock/LongDescriptionTest.php renamed to tests/phpDocumentor/Reflection/DocBlock/DescriptionTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* phpDocumentor Long Description Test
3+
* phpDocumentor Description Test
44
*
55
* PHP Version 5.3
66
*
@@ -13,21 +13,21 @@
1313
namespace phpDocumentor\Reflection\DocBlock;
1414

1515
/**
16-
* Test class for phpDocumentor\Reflection\DocBlock\LongDescription
16+
* Test class for phpDocumentor\Reflection\DocBlock\Description
1717
*
1818
* @author Vasil Rangelov <[email protected]>
1919
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
2020
* @license http://www.opensource.org/licenses/mit-license.php MIT
2121
* @link http://phpdoc.org
2222
*/
23-
class LongDescriptionTest extends \PHPUnit_Framework_TestCase
23+
class DescriptionTest extends \PHPUnit_Framework_TestCase
2424
{
2525
public function testConstruct()
2626
{
2727
$fixture = <<<LONGDESC
2828
This is text for a description.
2929
LONGDESC;
30-
$object = new LongDescription($fixture);
30+
$object = new Description($fixture);
3131
$this->assertSame($fixture, $object->getContents());
3232

3333
$parsedContents = $object->getParsedContents();
@@ -41,7 +41,7 @@ public function testInlineTagParsing()
4141
This is text for a {@link http://phpdoc.org/ description} that uses inline
4242
tags.
4343
LONGDESC;
44-
$object = new LongDescription($fixture);
44+
$object = new Description($fixture);
4545
$this->assertSame($fixture, $object->getContents());
4646

4747
$parsedContents = $object->getParsedContents();
@@ -64,7 +64,7 @@ public function testInlineTagAtStartParsing()
6464
{@link http://phpdoc.org/ This} is text for a description that uses inline
6565
tags.
6666
LONGDESC;
67-
$object = new LongDescription($fixture);
67+
$object = new Description($fixture);
6868
$this->assertSame($fixture, $object->getContents());
6969

7070
$parsedContents = $object->getParsedContents();
@@ -88,7 +88,7 @@ public function testNestedInlineTagParsing()
8888
This is text for a description with {@internal inline tag with
8989
{@link http://phpdoc.org another inline tag} in it}.
9090
LONGDESC;
91-
$object = new LongDescription($fixture);
91+
$object = new Description($fixture);
9292
$this->assertSame($fixture, $object->getContents());
9393

9494
$parsedContents = $object->getParsedContents();
@@ -119,7 +119,7 @@ public function testLiteralOpeningDelimiter()
119119
$fixture = <<<LONGDESC
120120
This is text for a description containing { that is literal.
121121
LONGDESC;
122-
$object = new LongDescription($fixture);
122+
$object = new Description($fixture);
123123
$this->assertSame($fixture, $object->getContents());
124124

125125
$parsedContents = $object->getParsedContents();
@@ -133,7 +133,7 @@ public function testNestedLiteralOpeningDelimiter()
133133
This is text for a description containing {@internal inline tag that has { that
134134
is literal}.
135135
LONGDESC;
136-
$object = new LongDescription($fixture);
136+
$object = new Description($fixture);
137137
$this->assertSame($fixture, $object->getContents());
138138

139139
$parsedContents = $object->getParsedContents();
@@ -160,7 +160,7 @@ public function testLiteralClosingDelimiter()
160160
$fixture = <<<LONGDESC
161161
This is text for a description with {} that is not a tag.
162162
LONGDESC;
163-
$object = new LongDescription($fixture);
163+
$object = new Description($fixture);
164164
$this->assertSame($fixture, $object->getContents());
165165

166166
$parsedContents = $object->getParsedContents();
@@ -177,7 +177,7 @@ public function testNestedLiteralClosingDelimiter()
177177
This is text for a description with {@internal inline tag with {} that is not an
178178
inline tag}.
179179
LONGDESC;
180-
$object = new LongDescription($fixture);
180+
$object = new Description($fixture);
181181
$this->assertSame($fixture, $object->getContents());
182182

183183
$parsedContents = $object->getParsedContents();
@@ -204,7 +204,7 @@ public function testInlineTagEscapingSequence()
204204
$fixture = <<<LONGDESC
205205
This is text for a description with literal {{@}link}.
206206
LONGDESC;
207-
$object = new LongDescription($fixture);
207+
$object = new Description($fixture);
208208
$this->assertSame($fixture, $object->getContents());
209209

210210
$parsedContents = $object->getParsedContents();
@@ -221,7 +221,7 @@ public function testNestedInlineTagEscapingSequence()
221221
This is text for a description with an {@internal inline tag with literal
222222
{{@}link{} in it}.
223223
LONGDESC;
224-
$object = new LongDescription($fixture);
224+
$object = new Description($fixture);
225225
$this->assertSame($fixture, $object->getContents());
226226

227227
$parsedContents = $object->getParsedContents();

0 commit comments

Comments
 (0)