Skip to content

Commit 21c3667

Browse files
committed
Merge pull request #10 from boenrobot/author
Introduced role, description and space separated URIs to the author tag.
2 parents ffcaa03 + 747e6d7 commit 21c3667

File tree

2 files changed

+180
-11
lines changed

2 files changed

+180
-11
lines changed

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Reflection class for an @author tag in a Docblock.
2020
*
21-
* @author Mike van Riel <mike.vanriel@naenius.com>
21+
* @author Vasil Rangelov <boen.robot@gmail.com>
2222
* @license http://www.opensource.org/licenses/mit-license.php MIT
2323
* @link http://phpdoc.org
2424
*/
@@ -27,8 +27,11 @@ class AuthorTag extends Tag
2727
/** @var string The name of the author */
2828
protected $name = '';
2929

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

3336
/**
3437
* Parses a tag and populates the member variables.
@@ -41,14 +44,32 @@ public function __construct($type, $content, DocBlock $docblock = null)
4144
{
4245
parent::__construct($type, $content, $docblock);
4346
if (preg_match(
44-
'/^([^\<]*)(\<([^\>]*)\>)?$/',
47+
'/^
48+
# Name
49+
([^\<]*)
50+
(?:
51+
# URIs
52+
\<([^>]*)\>\s*
53+
# Role
54+
(?:
55+
\(([^\)]*)\)
56+
)?
57+
# Description
58+
(.*)
59+
)?
60+
$/sux',
4561
$this->description,
4662
$matches
4763
)) {
48-
$this->name = trim($matches[1]);
49-
if (isset($matches[3])) {
50-
$this->email = trim($matches[3]);
64+
$this->name = rtrim($matches[1]);
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+
}
5170
}
71+
$this->role = isset($matches[3]) ? trim($matches[3]) : '';
72+
$this->description = isset($matches[4]) ? trim($matches[4]) : '';
5273
}
5374
}
5475

@@ -63,12 +84,22 @@ public function getAuthorName()
6384
}
6485

6586
/**
66-
* Gets the author's email.
87+
* Gets the author's URIs.
6788
*
68-
* @return string The author's email.
89+
* @return array Array of URIs belonging to the author, including email.
6990
*/
70-
public function getAuthorEmail()
91+
public function getAuthorURIs()
7192
{
72-
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;
73104
}
74105
}
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)