Skip to content

Commit 26e2ead

Browse files
committed
Merge branch 'master' of github.com:boenrobot/ReflectionDocBlock into version-and-derivatives
2 parents 829a92e + 1ac9106 commit 26e2ead

File tree

12 files changed

+112
-92
lines changed

12 files changed

+112
-92
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: 25 additions & 27 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
@@ -84,14 +86,17 @@ class Tag implements \Reflector
8486
/**
8587
* Factory method responsible for instantiating the correct sub type.
8688
*
87-
* @param string $tag_line The text for this tag, including description.
89+
* @param string $tag_line The text for this tag, including description.
90+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
8891
*
8992
* @throws \InvalidArgumentException if an invalid tag line was presented.
9093
*
91-
* @return \phpDocumentor\Reflection\DocBlock\Tag
94+
* @return static A new tag object.
9295
*/
93-
final public static function createInstance($tag_line)
94-
{
96+
final public static function createInstance(
97+
$tag_line,
98+
DocBlock $docblock = null
99+
) {
95100
if (!preg_match(
96101
'/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us',
97102
$tag_line,
@@ -106,10 +111,15 @@ final public static function createInstance($tag_line)
106111
$handler = self::$tagHandlerMappings[$matches[1]];
107112
return new $handler(
108113
$matches[1],
109-
isset($matches[2]) ? $matches[2] : ''
114+
isset($matches[2]) ? $matches[2] : '',
115+
$docblock
110116
);
111117
}
112-
return new self($matches[1], isset($matches[2]) ? $matches[2] : '');
118+
return new self(
119+
$matches[1],
120+
isset($matches[2]) ? $matches[2] : '',
121+
$docblock
122+
);
113123
}
114124

115125
/**
@@ -147,14 +157,16 @@ final public static function registerTagHandler($tag, $handler)
147157
/**
148158
* Parses a tag and populates the member variables.
149159
*
150-
* @param string $type Name of the tag.
151-
* @param string $content The contents of the given tag.
160+
* @param string $type Name of the tag.
161+
* @param string $content The contents of the given tag.
162+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
152163
*/
153-
public function __construct($type, $content)
164+
public function __construct($type, $content, DocBlock $docblock = null)
154165
{
155166
$this->tag = $type;
156167
$this->content = $content;
157-
$this->description = $content;
168+
$this->description = trim($content);
169+
$this->docblock = $docblock;
158170
}
159171

160172
/**
@@ -196,7 +208,7 @@ public function getDescription()
196208
public function getParsedDescription()
197209
{
198210
if (null === $this->parsedDescription) {
199-
$description = new LongDescription($this->description);
211+
$description = new Description($this->description, $this->docblock);
200212
$this->parsedDescription = $description->getParsedContents();
201213
}
202214
return $this->parsedDescription;
@@ -224,20 +236,6 @@ public function getLineNumber()
224236
return $this->line_number;
225237
}
226238

227-
/**
228-
* Inject the docblock class
229-
*
230-
* This exposes some common functionality contained in the docblock abstract.
231-
*
232-
* @param object $docblock Object containing the DocBlock.
233-
*
234-
* @return void
235-
*/
236-
public function setDocBlock($docblock)
237-
{
238-
$this->docblock = $docblock;
239-
}
240-
241239
/**
242240
* Builds a string representation of this object.
243241
*

src/phpDocumentor/Reflection/DocBlock/Tag/AuthorTag.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
1516
use phpDocumentor\Reflection\DocBlock\Tag;
1617

1718
/**
@@ -32,13 +33,18 @@ class AuthorTag extends Tag
3233
/**
3334
* Parses a tag and populates the member variables.
3435
*
35-
* @param string $type Tag identifier for this tag (should be 'author').
36-
* @param string $content The contents of the given tag.
36+
* @param string $type Tag identifier for this tag (should be 'author').
37+
* @param string $content Contents for this tag.
38+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
3739
*/
38-
public function __construct($type, $content)
40+
public function __construct($type, $content, DocBlock $docblock = null)
3941
{
40-
parent::__construct($type, $content);
41-
if (preg_match('/^([^\<]*)(\<([^\>]*)\>)?$/', $content, $matches)) {
42+
parent::__construct($type, $content, $docblock);
43+
if (preg_match(
44+
'/^([^\<]*)(\<([^\>]*)\>)?$/',
45+
$this->description,
46+
$matches
47+
)) {
4248
$this->name = trim($matches[1]);
4349
if (isset($matches[3])) {
4450
$this->email = trim($matches[3]);

src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
1516
use phpDocumentor\Reflection\DocBlock\Tag;
1617

1718
/**
@@ -29,13 +30,14 @@ class LinkTag extends Tag
2930
/**
3031
* Parses a tag and populates the member variables.
3132
*
32-
* @param string $type Tag identifier for this tag (should be 'link').
33-
* @param string $content The contents of the given tag.
33+
* @param string $type Tag identifier for this tag (should be 'link').
34+
* @param string $content Contents for this tag.
35+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
3436
*/
35-
public function __construct($type, $content)
37+
public function __construct($type, $content, DocBlock $docblock = null)
3638
{
37-
$this->tag = $type;
38-
$pieces = explode(' ', $content);
39+
parent::__construct($type, $content, $docblock);
40+
$pieces = explode(' ', $this->description);
3941

4042
if (count($pieces) > 1) {
4143
$this->link = array_shift($pieces);

src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php

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

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
16+
use phpDocumentor\Reflection\DocBlock\Tag;
17+
1518
/**
1619
* Reflection class for a @method in a Docblock.
1720
*
@@ -31,13 +34,13 @@ class MethodTag extends ReturnTag
3134
/**
3235
* Parses a tag and populates the member variables.
3336
*
34-
* @param string $type Tag identifier for this tag (should be 'method').
35-
* @param string $content The contents of the given tag.
37+
* @param string $type Tag identifier for this tag (should be 'method').
38+
* @param string $content Contents for this tag.
39+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
3640
*/
37-
public function __construct($type, $content)
41+
public function __construct($type, $content, DocBlock $docblock = null)
3842
{
39-
$this->tag = $type;
40-
$this->content = $content;
43+
Tag::__construct($type, $content, $docblock);
4144

4245
$matches = array();
4346
// 1. none or more whitespace
@@ -51,7 +54,7 @@ public function __construct($type, $content)
5154
if (preg_match(
5255
'/^[\s]*(?:([\w\|_\\\\]+)[\s]+)?(?:[\w_]+\(\)[\s]+)?([\w\|_\\\\]+)'
5356
.'\(([^\)]*)\)[\s]*(.*)/u',
54-
$content,
57+
$this->description,
5558
$matches
5659
)) {
5760
list(

src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php

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

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
16+
use phpDocumentor\Reflection\DocBlock\Tag;
17+
1518
/**
1619
* Reflection class for a @param tag in a Docblock.
1720
*
@@ -29,16 +32,16 @@ class ParamTag extends ReturnTag
2932
/**
3033
* Parses a tag and populates the member variables.
3134
*
32-
* @param string $type Tag identifier for this tag (should be 'param').
33-
* @param string $content Contents for this tag.
35+
* @param string $type Tag identifier for this tag (should be 'param').
36+
* @param string $content Contents for this tag.
37+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
3438
*/
35-
public function __construct($type, $content)
39+
public function __construct($type, $content, DocBlock $docblock = null)
3640
{
37-
$this->tag = $type;
38-
$this->content = $content;
41+
Tag::__construct($type, $content, $docblock);
3942
$content = preg_split(
4043
'/(\s+)/u',
41-
trim($content),
44+
$this->description,
4245
3,
4346
PREG_SPLIT_DELIM_CAPTURE
4447
);

src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php

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

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
1516
use phpDocumentor\Reflection\DocBlock\Tag;
1617

1718
/**
@@ -29,15 +30,14 @@ class ReturnTag extends Tag
2930
/**
3031
* Parses a tag and populates the member variables.
3132
*
32-
* @param string $type Tag identifier for this tag (should be 'return').
33-
* @param string $content Contents for this tag.
33+
* @param string $type Tag identifier for this tag (should be 'return').
34+
* @param string $content Contents for this tag.
35+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
3436
*/
35-
public function __construct($type, $content)
37+
public function __construct($type, $content, DocBlock $docblock = null)
3638
{
37-
$this->tag = $type;
38-
$this->content = $content;
39-
40-
$content = preg_split('/[\ \t]+/u', trim($content), 2);
39+
parent::__construct($type, $content, $docblock);
40+
$content = preg_split('/[\ \t]+/u', $this->description, 2);
4141

4242
// any output is considered a type
4343
$this->type = array_shift($content);

src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
1516
use phpDocumentor\Reflection\DocBlock\Tag;
1617

1718
/**
@@ -29,13 +30,13 @@ class SeeTag extends Tag
2930
/**
3031
* Parses a tag and populates the member variables.
3132
*
32-
* @param string $type Tag identifier for this tag (should be 'see').
33-
* @param string $content Contents for this tag.
33+
* @param string $type Tag identifier for this tag (should be 'see').
34+
* @param string $content Contents for this tag.
35+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
3436
*/
35-
public function __construct($type, $content)
37+
public function __construct($type, $content, DocBlock $docblock = null)
3638
{
37-
$this->tag = $type;
38-
$this->content = $content;
39+
parent::__construct($type, $content, $docblock);
3940
$content = preg_split('/\s+/u', $content);
4041

4142
// any output is considered a type

src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php

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

1313
namespace phpDocumentor\Reflection\DocBlock\Tag;
1414

15+
use phpDocumentor\Reflection\DocBlock;
16+
use phpDocumentor\Reflection\DocBlock\Tag;
17+
1518
/**
1619
* Reflection class for a @var tag in a Docblock.
1720
*
@@ -24,14 +27,14 @@ class VarTag extends ParamTag
2427
/**
2528
* Parses a tag and populates the member variables.
2629
*
27-
* @param string $type Tag identifier for this tag (should be 'var').
28-
* @param string $content Contents for this tag.
30+
* @param string $type Tag identifier for this tag (should be 'var').
31+
* @param string $content Contents for this tag.
32+
* @param DocBlock $docblock The DocBlock which this tag belongs to.
2933
*/
30-
public function __construct($type, $content)
34+
public function __construct($type, $content, DocBlock $docblock = null)
3135
{
32-
$this->tag = $type;
33-
$this->content = $content;
34-
$content = preg_split('/\s+/u', $content);
36+
Tag::__construct($type, $content, $docblock);
37+
$content = preg_split('/\s+/u', $this->description);
3538

3639
if (count($content) == 0) {
3740
return;

0 commit comments

Comments
 (0)