Skip to content

Commit f19dac1

Browse files
committed
Introduced role, description and space separated URIs to the author tag.
1 parent 0ba0ad6 commit f19dac1

File tree

2 files changed

+185
-10
lines changed

2 files changed

+185
-10
lines changed

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ class AuthorTag extends Tag
2626
/** @var string The name of the author */
2727
protected $name = '';
2828

29-
/** @var string The email of the author */
30-
protected $email = '';
29+
/** @var array Array of URIs belonging to the author, including email */
30+
protected $uris = array();
31+
32+
/** @var string The role of the author */
33+
protected $role = '';
3134

3235
/**
3336
* Parses a tag and populates the member variables.
@@ -37,12 +40,36 @@ class AuthorTag extends Tag
3740
*/
3841
public function __construct($type, $content)
3942
{
40-
parent::__construct($type, $content);
41-
if (preg_match('/^([^\<]*)(\<([^\>]*)\>)?$/', $content, $matches)) {
43+
$this->tag = $type;
44+
$this->content = $content;
45+
if (preg_match(
46+
'/^
47+
# Name
48+
([^\<]*)
49+
(?:
50+
# URIs
51+
\<([^>]*)\>\s*
52+
# Role
53+
(?:
54+
\(([^\)]*)\)
55+
)?
56+
# Description
57+
(.*)
58+
)?
59+
$/sux',
60+
$content,
61+
$matches
62+
)
63+
) {
4264
$this->name = trim($matches[1]);
43-
if (isset($matches[3])) {
44-
$this->email = trim($matches[3]);
65+
if (isset($matches[2])) {
66+
$matches[2] = trim($matches[2]);
67+
if ('' !== $matches[2]) {
68+
$this->uris = preg_split('/\s+/u', $matches[2]);
69+
}
4570
}
71+
$this->role = isset($matches[3]) ? trim($matches[3]) : '';
72+
$this->description = isset($matches[4]) ? trim($matches[4]) : '';
4673
}
4774
}
4875

@@ -57,12 +84,22 @@ public function getAuthorName()
5784
}
5885

5986
/**
60-
* Gets the author's email.
87+
* Gets the author's URIs.
6188
*
62-
* @return string The author's email.
89+
* @return array Array of URIs belonging to the author, including email.
6390
*/
64-
public function getAuthorEmail()
91+
public function getAuthorURIs()
6592
{
66-
return $this->email;
93+
return $this->uris;
94+
}
95+
96+
/**
97+
* Gets the author's role.
98+
*
99+
* @return string The role of the author.
100+
*/
101+
public function getAuthorRole()
102+
{
103+
return $this->role;
67104
}
68105
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* phpDocumentor Author tag test.
4+
*
5+
* PHP version 5.3
6+
*
7+
* @author Vasil Rangelov <[email protected]>
8+
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection\DocBlock\Tag;
14+
15+
/**
16+
* Test class for \phpDocumentor\Reflection\DocBlock\AuthorTag.
17+
*
18+
* @author Vasil Rangelov <[email protected]>
19+
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
20+
* @license http://www.opensource.org/licenses/mit-license.php MIT
21+
* @link http://phpdoc.org
22+
*/
23+
class AuthorTagTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\AuthorTag can
27+
* understand the @author DocBlock.
28+
*
29+
* @param string $type
30+
* @param string $content
31+
* @param string $extractedType
32+
* @param string $extractedVarName
33+
* @param string $extractedDescription
34+
*
35+
* @dataProvider provideDataForConstructor
36+
*
37+
* @return void
38+
*/
39+
public function testConstructorParsesInputsIntoCorrectFields(
40+
$type,
41+
$content,
42+
$extractedName,
43+
$extractedURIs,
44+
$extractedRole,
45+
$extractedDescription
46+
) {
47+
$tag = new AuthorTag($type, $content);
48+
49+
$this->assertEquals($extractedName, $tag->getAuthorName());
50+
$this->assertEquals($extractedURIs, $tag->getAuthorURIs());
51+
$this->assertEquals($extractedRole, $tag->getAuthorRole());
52+
$this->assertEquals($extractedDescription, $tag->getDescription());
53+
}
54+
55+
/**
56+
* Data provider for testConstructorParsesInputsIntoCorrectFields()
57+
*
58+
* @return array
59+
*/
60+
public function provideDataForConstructor()
61+
{
62+
return array(
63+
array('author', 'Mike van Riel', 'Mike van Riel', array(), '', ''),
64+
array(
65+
'author',
66+
'Mike van Riel <[email protected]>',
67+
'Mike van Riel',
68+
69+
'',
70+
''
71+
),
72+
array(
73+
'author',
74+
'Mike van Riel <[email protected] >',
75+
'Mike van Riel',
76+
77+
'',
78+
''
79+
),
80+
array(
81+
'author',
82+
'Mike van Riel < [email protected]>',
83+
'Mike van Riel',
84+
85+
'',
86+
''
87+
),
88+
array(
89+
'author',
90+
'Mike van Riel < [email protected] >',
91+
'Mike van Riel',
92+
93+
'',
94+
''
95+
),
96+
array(
97+
'author',
98+
'Mike van Riel <[email protected] @mvriel>',
99+
'Mike van Riel',
100+
array('[email protected]', '@mvriel'),
101+
'',
102+
''
103+
),
104+
array(
105+
'author',
106+
'Mike van Riel <[email protected]> (lead)',
107+
'Mike van Riel',
108+
109+
'lead',
110+
''
111+
),
112+
array(
113+
'author',
114+
'Mike van Riel <[email protected]> (lead) The one',
115+
'Mike van Riel',
116+
117+
'lead',
118+
'The one'
119+
),
120+
array(
121+
'author',
122+
'Mike van Riel <[email protected]> The one',
123+
'Mike van Riel',
124+
125+
'',
126+
'The one'
127+
),
128+
array(
129+
'author',
130+
'Mike van Riel <> The one',
131+
'Mike van Riel',
132+
array(),
133+
'',
134+
'The one'
135+
)
136+
);
137+
}
138+
}

0 commit comments

Comments
 (0)