mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Merge pull request #10 from boenrobot/author
Introduced role, description and space separated URIs to the author tag.
This commit is contained in:
@@ -18,7 +18,7 @@ use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
/**
|
||||
* Reflection class for an @author tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||
* @author Vasil Rangelov <boen.robot@gmail.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
@@ -27,8 +27,11 @@ class AuthorTag extends Tag
|
||||
/** @var string The name of the author */
|
||||
protected $name = '';
|
||||
|
||||
/** @var string The email of the author */
|
||||
protected $email = '';
|
||||
/** @var array Array of URIs belonging to the author, including email */
|
||||
protected $uris = array();
|
||||
|
||||
/** @var string The role of the author */
|
||||
protected $role = '';
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
@@ -41,14 +44,32 @@ class AuthorTag extends Tag
|
||||
{
|
||||
parent::__construct($type, $content, $docblock);
|
||||
if (preg_match(
|
||||
'/^([^\<]*)(\<([^\>]*)\>)?$/',
|
||||
'/^
|
||||
# Name
|
||||
([^\<]*)
|
||||
(?:
|
||||
# URIs
|
||||
\<([^>]*)\>\s*
|
||||
# Role
|
||||
(?:
|
||||
\(([^\)]*)\)
|
||||
)?
|
||||
# Description
|
||||
(.*)
|
||||
)?
|
||||
$/sux',
|
||||
$this->description,
|
||||
$matches
|
||||
)) {
|
||||
$this->name = trim($matches[1]);
|
||||
if (isset($matches[3])) {
|
||||
$this->email = trim($matches[3]);
|
||||
$this->name = rtrim($matches[1]);
|
||||
if (isset($matches[2])) {
|
||||
$matches[2] = trim($matches[2]);
|
||||
if ('' !== $matches[2]) {
|
||||
$this->uris = preg_split('/\s+/u', $matches[2]);
|
||||
}
|
||||
}
|
||||
$this->role = isset($matches[3]) ? trim($matches[3]) : '';
|
||||
$this->description = isset($matches[4]) ? trim($matches[4]) : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +84,22 @@ class AuthorTag extends Tag
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the author's email.
|
||||
* Gets the author's URIs.
|
||||
*
|
||||
* @return string The author's email.
|
||||
* @return array Array of URIs belonging to the author, including email.
|
||||
*/
|
||||
public function getAuthorEmail()
|
||||
public function getAuthorURIs()
|
||||
{
|
||||
return $this->email;
|
||||
return $this->uris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the author's role.
|
||||
*
|
||||
* @return string The role of the author.
|
||||
*/
|
||||
public function getAuthorRole()
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Author tag test.
|
||||
*
|
||||
* PHP version 5.3
|
||||
*
|
||||
* @author Vasil Rangelov <[email protected]>
|
||||
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
/**
|
||||
* Test class for \phpDocumentor\Reflection\DocBlock\AuthorTag.
|
||||
*
|
||||
* @author Vasil Rangelov <[email protected]>
|
||||
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class AuthorTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\AuthorTag can
|
||||
* understand the @author DocBlock.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $extractedType
|
||||
* @param string $extractedVarName
|
||||
* @param string $extractedDescription
|
||||
*
|
||||
* @dataProvider provideDataForConstructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParsesInputsIntoCorrectFields(
|
||||
$type,
|
||||
$content,
|
||||
$extractedName,
|
||||
$extractedURIs,
|
||||
$extractedRole,
|
||||
$extractedDescription
|
||||
) {
|
||||
$tag = new AuthorTag($type, $content);
|
||||
|
||||
$this->assertEquals($extractedName, $tag->getAuthorName());
|
||||
$this->assertEquals($extractedURIs, $tag->getAuthorURIs());
|
||||
$this->assertEquals($extractedRole, $tag->getAuthorRole());
|
||||
$this->assertEquals($extractedDescription, $tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstructor()
|
||||
{
|
||||
return array(
|
||||
array('author', 'Mike van Riel', 'Mike van Riel', array(), '', ''),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <[email protected]>',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <[email protected] >',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel < [email protected]>',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel < [email protected] >',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <[email protected] @mvriel>',
|
||||
'Mike van Riel',
|
||||
array('[email protected]', '@mvriel'),
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <[email protected]> (lead)',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'lead',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <[email protected]> (lead) The one',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'lead',
|
||||
'The one'
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <[email protected]> The one',
|
||||
'Mike van Riel',
|
||||
array('[email protected]'),
|
||||
'',
|
||||
'The one'
|
||||
),
|
||||
array(
|
||||
'author',
|
||||
'Mike van Riel <> The one',
|
||||
'Mike van Riel',
|
||||
array(),
|
||||
'',
|
||||
'The one'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user