Refactored all tags to have setters for all of their components;

Removed the special handling for VarTag (it's now equivalent to ParamTag);
Minor doc, CS and coverage fixes.
This commit is contained in:
Vasil Rangelov
2012-11-30 19:26:19 +02:00
parent bad318bc39
commit 8223e475fa
25 changed files with 481 additions and 266 deletions
+5 -5
View File
@@ -241,7 +241,7 @@ class DocBlock implements \Reflector
/** /**
* Returns the full description or also known as long description. * Returns the full description or also known as long description.
* *
* @return \phpDocumentor\Reflection\DocBlock\LongDescription * @return DocBlock\Description
*/ */
public function getLongDescription() public function getLongDescription()
{ {
@@ -271,7 +271,7 @@ class DocBlock implements \Reflector
/** /**
* Returns the tags for this DocBlock. * Returns the tags for this DocBlock.
* *
* @return \phpDocumentor\Reflection\DocBlock\Tag[] * @return DocBlock\Tag[]
*/ */
public function getTags() public function getTags()
{ {
@@ -284,13 +284,13 @@ class DocBlock implements \Reflector
* *
* @param string $name String to search by. * @param string $name String to search by.
* *
* @return \phpDocumentor\Reflection\DocBlock_Tag[] * @return DocBlock\Tag[]
*/ */
public function getTagsByName($name) public function getTagsByName($name)
{ {
$result = array(); $result = array();
/** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */ /** @var DocBlock\Tag $tag */
foreach ($this->getTags() as $tag) { foreach ($this->getTags() as $tag) {
if ($tag->getName() != $name) { if ($tag->getName() != $name) {
continue; continue;
@@ -311,7 +311,7 @@ class DocBlock implements \Reflector
*/ */
public function hasTag($name) public function hasTag($name)
{ {
/** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */ /** @var DocBlock\Tag $tag */
foreach ($this->getTags() as $tag) { foreach ($this->getTags() as $tag) {
if ($tag->getName() == $name) { if ($tag->getName() == $name) {
return true; return true;
@@ -29,9 +29,6 @@ class Description implements \Reflector
/** @var array The contents, as an array of strings and Tag objects. */ /** @var array The contents, as an array of strings and Tag objects. */
protected $parsedContents = null; protected $parsedContents = null;
/** @var \phpDocumentor\Reflection\DocBlock\Tags[] */
protected $tags = array();
/** @var DocBlock The DocBlock which this description belongs to. */ /** @var DocBlock The DocBlock which this description belongs to. */
protected $docblock = null; protected $docblock = null;
+123 -17
View File
@@ -23,16 +23,27 @@ use phpDocumentor\Reflection\DocBlock;
*/ */
class Tag implements \Reflector class Tag implements \Reflector
{ {
/**
* PCRE regular expression matching a tag name.
*/
const REGEX_TAGNAME = '[\w\-\_\\\\]+';
/** @var string Name of the tag */ /** @var string Name of the tag */
protected $tag = ''; protected $tag = '';
/** @var string Content of the tag */ /**
* @var string|null Content of the tag.
* When set to NULL, it means it needs to be regenerated.
*/
protected $content = ''; protected $content = '';
/** @var string Description of the content of this tag */ /** @var string Description of the content of this tag */
protected $description = ''; protected $description = '';
/** @var array The description, as an array of strings and Tag objects. */ /**
* @var array|null The description, as an array of strings and Tag objects.
* When set to NULL, it means it needs to be regenerated.
*/
protected $parsedDescription = null; protected $parsedDescription = null;
/** @var Location Location of the tag. */ /** @var Location Location of the tag. */
@@ -104,7 +115,7 @@ class Tag implements \Reflector
Location $location = null Location $location = null
) { ) {
if (!preg_match( if (!preg_match(
'/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us', '/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us',
$tag_line, $tag_line,
$matches $matches
)) { )) {
@@ -173,28 +184,28 @@ class Tag implements \Reflector
/** /**
* Parses a tag and populates the member variables. * Parses a tag and populates the member variables.
* *
* @param string $type Name of the tag. * @param string $name Name of the tag.
* @param string $content The contents of the given tag. * @param string $content The contents of the given tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to. * @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag. * @param Location $location Location of the tag.
*/ */
public function __construct( public function __construct(
$type, $name,
$content, $content,
DocBlock $docblock = null, DocBlock $docblock = null,
Location $location = null Location $location = null
) { ) {
$this->tag = $type; $this
$this->content = $content; ->setName($name)
$this->description = trim($content); ->setContent($content)
$this->docblock = $docblock; ->setDocBlock($docblock)
$this->location = $location; ->setLocation($location);
} }
/** /**
* Returns the name of this tag. * Gets the name of this tag.
* *
* @return string * @return string The name of this tag.
*/ */
public function getName() public function getName()
{ {
@@ -202,17 +213,57 @@ class Tag implements \Reflector
} }
/** /**
* Returns the content of this tag. * Sets the name of this tag.
*
* @param string $name The new name of this tag.
*
* @return $this
* @throws \InvalidArgumentException When an invalid tag name is provided.
*/
public function setName($name)
{
if (!preg_match('/^' . self::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException(
'Invalid tag name supplied: ' . $name
);
}
$this->tag = $name;
return $this;
}
/**
* Gets the content of this tag.
* *
* @return string * @return string
*/ */
public function getContent() public function getContent()
{ {
if (null === $this->content) {
$this->content = $this->description;
}
return $this->content; return $this->content;
} }
/** /**
* Returns the description component of this tag. * Sets the content of this tag.
*
* @param string $content The new content of this tag.
*
* @return $this
*/
public function setContent($content)
{
$this->setDescription($content);
$this->content = $content;
return $this;
}
/**
* Gets the description component of this tag.
* *
* @return string * @return string
*/ */
@@ -222,7 +273,23 @@ class Tag implements \Reflector
} }
/** /**
* Returns the parsed text of this description. * Sets the description component of this tag.
*
* @param string $description The new description component of this tag.
*
* @return $this
*/
public function setDescription($description)
{
$this->content = null;
$this->parsedDescription = null;
$this->description = trim($description);
return $this;
}
/**
* Gets the parsed text of this description.
* *
* @return array An array of strings and tag objects, in the order they * @return array An array of strings and tag objects, in the order they
* occur within the description. * occur within the description.
@@ -237,14 +304,53 @@ class Tag implements \Reflector
} }
/** /**
* Get the location of the tag. * Gets the docblock this tag belongs to.
*
* @return DocBlock The docblock this tag belongs to.
*/
public function getDocBlock()
{
return $this->docblock;
}
/**
* Sets the docblock this tag belongs to.
*
* @param DocBlock $docblock The new docblock this tag belongs to. Setting
* NULL removes any association.
*
* @return $this
*/
public function setDocBlock(DocBlock $docblock = null)
{
$this->docblock = $docblock;
return $this;
}
/**
* Gets the location of the tag.
* *
* @return Location Tag's location. * @return Location The tag's location.
*/ */
public function getLocation() public function getLocation()
{ {
return $this->location; return $this->location;
} }
/**
* Sets the location of the tag.
*
* @param Location $location The new location of the tag.
*
* @return $this
*/
public function setLocation(Location $location = null)
{
$this->location = $location;
return $this;
}
/** /**
* Builds a string representation of this object. * Builds a string representation of this object.
@@ -12,7 +12,6 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
/** /**
@@ -25,36 +24,41 @@ use phpDocumentor\Reflection\DocBlock\Tag;
class AuthorTag extends Tag class AuthorTag extends Tag
{ {
/** @var string The name of the author */ /** @var string The name of the author */
protected $name = ''; protected $authorName = '';
/** @var string The email of the author */ /** @var string The email of the author */
protected $email = ''; protected $authorEmail = '';
public function getContent()
{
if (null === $this->content) {
$this->content = $this->authorName;
if ('' != $this->authorEmail) {
$this->content .= "<{$this->authorEmail}>";
}
}
return $this->content;
}
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'author').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function setContent($content)
$type, {
$content, parent::setContent($content);
DocBlock $docblock = null,
Location $location = null
) {
parent::__construct($type, $content, $docblock, $location);
if (preg_match( if (preg_match(
'/^([^\<]*)(\<([^\>]*)\>)?$/', '/^([^\<]*)(\<([^\>]*)\>)?$/u',
$this->description, $this->description,
$matches $matches
)) { )) {
$this->name = trim($matches[1]); $this->authorName = trim($matches[1]);
if (isset($matches[3])) { if (isset($matches[3])) {
$this->email = trim($matches[3]); $this->authorEmail = trim($matches[3]);
} }
} }
return $this;
} }
/** /**
@@ -64,7 +68,22 @@ class AuthorTag extends Tag
*/ */
public function getAuthorName() public function getAuthorName()
{ {
return $this->name; return $this->authorName;
}
/**
* Sets the author's name.
*
* @param string $authorName The new author name.
*
* @return $this
*/
public function setAuthorName($authorName)
{
$this->content = null;
$this->authorName = $authorName;
return $this;
} }
/** /**
@@ -74,6 +93,21 @@ class AuthorTag extends Tag
*/ */
public function getAuthorEmail() public function getAuthorEmail()
{ {
return $this->email; return $this->authorEmail;
}
/**
* Sets the author's email.
*
* @param string $authorEmail The new author email.
*
* @return $this
*/
public function setAuthorEmail($authorEmail)
{
$this->content = null;
$this->authorEmail = $authorEmail;
return $this;
} }
} }
@@ -24,26 +24,32 @@ use phpDocumentor\Reflection\DocBlock\Tag;
*/ */
class ExampleTag extends SourceTag class ExampleTag extends SourceTag
{ {
/** @var string Path to a file to use as an example. Can also be an URI. */ /**
* @var string Path to a file to use as an example.
* May also be an absolute URI.
*/
protected $filePath = ''; protected $filePath = '';
public function getContent()
{
if (null === $this->content) {
$this->content
= (preg_match('/\s/Su', $this->filePath)
? '"' . $this->filePath . '"'
: $this->filePath) . ' ' . $this->getContent();
}
return $this->content;
}
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'example').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function setContent($content)
$type, {
$content, Tag::setContent($content);
DocBlock $docblock = null,
Location $location = null
) {
Tag::__construct($type, $content, $docblock, $location);
if (preg_match( if (preg_match(
'/^ '/^
# File component
(?: (?:
# File path in quotes # File path in quotes
\"([^\"]+)\" \"([^\"]+)\"
@@ -57,35 +63,52 @@ class ExampleTag extends SourceTag
$this->description, $this->description,
$matches $matches
)) { )) {
if ('' !== $matches[1]) { $this->setFilePath('' === $matches[1] ? $matches[2] : $matches[1]);
//Quoted file path.
$this->filePath = trim($matches[1]);
} elseif (false === strpos($matches[2], ':')) {
//Relative URL or a file path with no spaces in it.
$this->filePath = rawurldecode(
str_replace(array('/', '\\'), '%2F', $matches[2])
);
} else {
//Absolute URL or URI.
$this->filePath = $matches[2];
}
if (isset($matches[3])) { if (isset($matches[3])) {
parent::__construct($type, $matches[3]); parent::setContent($matches[3]);
$this->content = $content; $this->content = $content;
} else { } else {
$this->description = ''; $this->description = '';
} }
} }
return $this;
} }
/** /**
* Returns the file path. * Returns the file path.
* *
* @return string Path to a file to use as an example. Can also be an URI. * @return string Path to a file to use as an example.
* May also be an absolute URI.
*/ */
public function getFilePath() public function getFilePath()
{ {
return $this->filePath; return $this->filePath;
} }
/**
* Sets the file path.
*
* @param string $filePath The new file path or URI to use as an example.
*
* @return $this
*/
public function setFilePath($filePath)
{
if (preg_match('/\s/Su', $filePath)) {
//Quoted file path.
$this->filePath = trim($filePath);
} elseif (false === strpos($filePath, ':')) {
//Relative URL or a file path with no spaces in it.
$this->filePath = rawurldecode(
str_replace(array('/', '\\'), '%2F', $filePath)
);
} else {
//Absolute URL or URI.
$this->filePath = $filePath;
}
return $this;
}
} }
@@ -12,7 +12,6 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
/** /**
@@ -28,30 +27,34 @@ class LinkTag extends Tag
protected $link = ''; protected $link = '';
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'link').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function getContent()
$type, {
$content, if (null === $this->content) {
DocBlock $docblock = null, $this->content = "{$this->link} {$this->description}";
Location $location = null }
) {
parent::__construct($type, $content, $docblock, $location);
$content = preg_split('/\s+/u', $this->description, 2);
// any output is considered a type return $this->content;
$this->link = $content[0];
$this->description = isset($content[1]) ? $content[1] : $content[0];
} }
/** /**
* Returns the link * {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
$content = preg_split('/\s+/Su', $this->description, 2);
$this->link = $content[0];
$this->description = isset($content[1]) ? $content[1] : $content[0];
return $this;
}
/**
* Gets the link
* *
* @return string * @return string
*/ */
@@ -65,10 +68,13 @@ class LinkTag extends Tag
* *
* @param string $link The link * @param string $link The link
* *
* @return void * @return $this
*/ */
public function setLink($link) public function setLink($link)
{ {
$this->content = null;
$this->link = $link; $this->link = $link;
return $this;
} }
} }
@@ -12,7 +12,6 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
/** /**
@@ -32,22 +31,25 @@ class MethodTag extends ReturnTag
protected $arguments = ''; protected $arguments = '';
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'method').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function getContent()
$type, {
$content, if (null === $this->content) {
DocBlock $docblock = null, $this->content = $this->type .
Location $location = null " {$this->method_name}({$this->arguments}) " .
) { $this->description;
Tag::__construct($type, $content, $docblock, $location); }
$matches = array(); return $this;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
Tag::setContent($content);
// 1. none or more whitespace // 1. none or more whitespace
// 2. optionally a word with underscores followed by whitespace : as // 2. optionally a word with underscores followed by whitespace : as
// type for the return value // type for the return value
@@ -92,6 +94,8 @@ class MethodTag extends ReturnTag
echo date('c') . ' ERR (3): @method contained invalid contents: ' echo date('c') . ' ERR (3): @method contained invalid contents: '
. $this->content . PHP_EOL; . $this->content . PHP_EOL;
} }
return $this;
} }
/** /**
@@ -99,11 +103,14 @@ class MethodTag extends ReturnTag
* *
* @param string $method_name The name of the method. * @param string $method_name The name of the method.
* *
* @return void * @return $this
*/ */
public function setMethodName($method_name) public function setMethodName($method_name)
{ {
$this->content = null;
$this->method_name = $method_name; $this->method_name = $method_name;
return $this;
} }
/** /**
@@ -125,7 +132,10 @@ class MethodTag extends ReturnTag
*/ */
public function setArguments($arguments) public function setArguments($arguments)
{ {
$this->content = null;
$this->arguments = $arguments; $this->arguments = $arguments;
return $this;
} }
/** /**
@@ -27,25 +27,27 @@ class ParamTag extends ReturnTag
/** /**
* @var string * @var string
*/ */
protected $variableName = null; protected $variableName = '';
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'param').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function getContent()
$type, {
$content, if (null === $this->content) {
DocBlock $docblock = null, $this->content
Location $location = null = "{$this->type} {$this->variableName} {$this->description}";
) { }
Tag::__construct($type, $content, $docblock, $location); return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
Tag::setContent($content);
$content = preg_split( $content = preg_split(
'/(\s+)/u', '/(\s+)/Su',
$this->description, $this->description,
3, 3,
PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_DELIM_CAPTURE
@@ -70,6 +72,8 @@ class ParamTag extends ReturnTag
} }
$this->description = implode('', $content); $this->description = implode('', $content);
return $this;
} }
/** /**
@@ -87,10 +91,13 @@ class ParamTag extends ReturnTag
* *
* @param string $name The new name for this variable. * @param string $name The new name for this variable.
* *
* @return void * @return $this
*/ */
public function setVariableName($name) public function setVariableName($name)
{ {
$this->content = null;
$this->variableName = $name; $this->variableName = $name;
return $this;
} }
} }
@@ -12,7 +12,6 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Type\Collection; use phpDocumentor\Reflection\DocBlock\Type\Collection;
@@ -32,26 +31,32 @@ class ReturnTag extends Tag
protected $types = null; protected $types = null;
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'return').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function getCotnent()
$type, {
$content, if (null === $this->content) {
DocBlock $docblock = null, $this->content = "{$this->type} {$this->description}";
Location $location = null }
) {
parent::__construct($type, $content, $docblock, $location); return $this->cotnent;
$content = preg_split('/\s+/u', $this->description, 2); }
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
$content = preg_split('/\s+/Su', $this->description, 2);
// any output is considered a type // any output is considered a type
$this->type = $content[0]; $this->type = $content[0];
$this->description = isset($content[1]) ? $content[1] : ''; $this->description = isset($content[1]) ? $content[1] : '';
return $this;
} }
/** /**
@@ -28,30 +28,34 @@ class SeeTag extends Tag
protected $refers = null; protected $refers = null;
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'see').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function getContent()
$type, {
$content, if (null === $this->content) {
DocBlock $docblock = null, $this->content = "{$this->refers} {$this->description}";
Location $location = null }
) { return $this->content;
parent::__construct($type, $content, $docblock, $location); }
$content = preg_split('/\s+/u', $this->description, 2);
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
$content = preg_split('/\s+/Su', $this->description, 2);
// any output is considered a type // any output is considered a type
$this->refers = $content[0]; $this->refers = $content[0];
$this->description = isset($content[1]) ? $content[1] : ''; $this->description = isset($content[1]) ? $content[1] : '';
return $this;
} }
/** /**
* Returns the type of the variable. * Gets the structural element this tag refers to.
* *
* @return string * @return string
*/ */
@@ -59,4 +63,19 @@ class SeeTag extends Tag
{ {
return $this->refers; return $this->refers;
} }
/**
* Sets the structural element this tag refers to.
*
* @param string $refers The new type this tag refers to.
*
* @return $this
*/
public function setReference($refers)
{
$this->content = null;
$this->refers = $refers;
return $this;
}
} }
@@ -36,20 +36,24 @@ class SourceTag extends Tag
protected $lineCount = null; protected $lineCount = null;
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'source').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function getContent()
$type, {
$content, if (null === $this->content) {
DocBlock $docblock = null, $this->content
Location $location = null = "{$this->startingLine} {$this->lineCount} {$this->description}";
) { }
parent::__construct($type, $content, $docblock, $location);
return $this->content;
}
/**
* {@inheritdoc}
*/
public function setContent($content)
{
parent::setContent($content);
if (preg_match( if (preg_match(
'/^ '/^
# Starting line # Starting line
@@ -72,10 +76,12 @@ class SourceTag extends Tag
} }
$this->description = $matches[3]; $this->description = $matches[3];
} }
return $this;
} }
/** /**
* Returns the starting line. * Gets the starting line.
* *
* @return int The starting line, relative to the structural element's * @return int The starting line, relative to the structural element's
* location. * location.
@@ -85,6 +91,22 @@ class SourceTag extends Tag
return $this->startingLine; return $this->startingLine;
} }
/**
* Sets the starting line.
*
* @param int $startingLine The new starting line, relative to the
* structural element's location.
*
* @return $this
*/
public function setStartingLine($startingLine)
{
$this->content = null;
$this->startingLine = $startingLine;
return $this;
}
/** /**
* Returns the number of lines. * Returns the number of lines.
* *
@@ -95,4 +117,20 @@ class SourceTag extends Tag
{ {
return $this->lineCount; return $this->lineCount;
} }
/**
* Sets the number of lines.
*
* @param int|null $lineCount The new number of lines, relative to the
* starting line. NULL means "to the end".
*
* @return $this
*/
public function setLineCount($lineCount)
{
$this->content = null;
$this->lineCount = $lineCount;
return $this;
}
} }
@@ -12,9 +12,6 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tag;
/** /**
* Reflection class for a @var tag in a Docblock. * Reflection class for a @var tag in a Docblock.
* *
@@ -24,38 +21,4 @@ use phpDocumentor\Reflection\DocBlock\Tag;
*/ */
class VarTag extends ParamTag class VarTag extends ParamTag
{ {
/**
* Parses a tag and populates the member variables.
*
* @param string $type Tag identifier for this tag (should be 'var').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/
public function __construct(
$type,
$content,
DocBlock $docblock = null,
Location $location = null
) {
Tag::__construct($type, $content, $docblock, $location);
$content = preg_split('/\s+/u', $this->description);
if (count($content) == 0) {
return;
}
// var always starts with the variable name
$this->type = array_shift($content);
// if the next item starts with a $ it must be the variable name
if ((count($content) > 0)
&& (strlen($content[0]) > 0)
&& ($content[0][0] == '$')
) {
$this->variableName = array_shift($content);
}
$this->description = implode(' ', $content);
}
} }
@@ -24,39 +24,45 @@ use phpDocumentor\Reflection\DocBlock\Tag;
*/ */
class VersionTag extends Tag class VersionTag extends Tag
{ {
/**
* PCRE regular expression matching a version vector.
* Assumes the "x" modifier.
*/
const REGEX_VECTOR = '(?:
# Normal release vectors.
\d\S*
|
# VCS version vectors. Per PHPCS, they are expected to
# follow the form of the VCS name, followed by ":", followed
# by the version vector itself.
# By convention, popular VCSes like CVS, SVN and GIT use "$"
# around the actual version vector.
[^\s\:]+\:\s*\$[^\$]+\$
)';
/** @var string The version vector. */ /** @var string The version vector. */
protected $version = ''; protected $version = '';
public function getContent()
{
if (null === $this->content) {
$this->content = "{$this->version} {$this->description}";
}
return $this->content;
}
/** /**
* Parses a tag and populates the member variables. * {@inheritdoc}
*
* @param string $type Tag identifier for this tag (should be 'version').
* @param string $content Contents for this tag.
* @param DocBlock $docblock The DocBlock which this tag belongs to.
* @param Location $location Location of the tag.
*/ */
public function __construct( public function setContent($content)
$type, {
$content, parent::setContent($content);
DocBlock $docblock = null,
Location $location = null
) {
parent::__construct($type, $content, $docblock, $location);
if (preg_match( if (preg_match(
'/^ '/^
# The version vector # The version vector
((?: (' . self::REGEX_VECTOR . ')
# Normal release vectors.
\d\S*
|
# VCS version vectors. Per PHPCS, they are expected to
# follow the form of the VCS name, followed by ":", followed
# by the version vector itself.
# By convention, popular VCSes like CVS, SVN and GIT use "$"
# around the actual version vector.
[^\s\:]+\:\s*\$[^\$]+\$
))
\s* \s*
# The description # The description
(.+)? (.+)?
@@ -67,10 +73,12 @@ class VersionTag extends Tag
$this->version = $matches[1]; $this->version = $matches[1];
$this->description = isset($matches[2]) ? $matches[2] : ''; $this->description = isset($matches[2]) ? $matches[2] : '';
} }
return $this;
} }
/** /**
* Returns the version section of the tag. * Gets the version section of the tag.
* *
* @return string The version section of the tag. * @return string The version section of the tag.
*/ */
@@ -78,4 +86,23 @@ class VersionTag extends Tag
{ {
return $this->version; return $this->version;
} }
/**
* Sets the version section of the tag.
*
* @param string $version The new version section of the tag.
* Invalid version vectors will set the version to an empty string.
*
* @return $this
*/
public function setVersion($version)
{
$this->content = null;
$this->version
= preg_match('/^' . self::REGEX_VECTOR . '$/ux', $version)
? $version
: '';
return $this;
}
} }
@@ -152,7 +152,7 @@ class Collection extends \ArrayObject
} }
if ($this->isTypeAnArray($type)) { if ($this->isTypeAnArray($type)) {
return $this->expand(substr($type, 0, -2)).self::OPERATOR_ARRAY; return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
} }
if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type)) { if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type)) {
@@ -186,7 +186,7 @@ class Collection extends \ArrayObject
*/ */
protected function isTypeAnArray($type) protected function isTypeAnArray($type)
{ {
return (substr($type, -2) == self::OPERATOR_ARRAY); return substr($type, -2) === self::OPERATOR_ARRAY;
} }
/** /**
@@ -199,7 +199,7 @@ class Collection extends \ArrayObject
*/ */
protected function isTypeAKeyword($type) protected function isTypeAKeyword($type)
{ {
return in_array(strtolower($type), $this->keywords); return in_array(strtolower($type), $this->keywords, true);
} }
/** /**
@@ -33,8 +33,7 @@ class ExampleTagTest extends \PHPUnit_Framework_TestCase
* @param string $exLineCount * @param string $exLineCount
* @param string $exFilepath * @param string $exFilepath
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag::getFilePath
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -32,8 +32,7 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
* @param string $exDescription * @param string $exDescription
* @param string $exLink * @param string $exLink
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::getLink
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -34,10 +34,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
* @param string $description The short description mentioned in the * @param string $description The short description mentioned in the
* signature. * signature.
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getMethodName
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getArguments
*
* @dataProvider getTestSignatures * @dataProvider getTestSignatures
* *
* @return void * @return void
@@ -33,9 +33,7 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
* @param string $extractedVarName * @param string $extractedVarName
* @param string $extractedDescription * @param string $extractedDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getVariableName
*
* @dataProvider provideDataForConstructor * @dataProvider provideDataForConstructor
* *
* @return void * @return void
@@ -33,7 +33,6 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase
* @param string $extractedDescription * @param string $extractedDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag
*
* @dataProvider provideDataForConstructor * @dataProvider provideDataForConstructor
* *
* @return void * @return void
@@ -31,8 +31,7 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase
* @param string $exContent * @param string $exContent
* @param string $exReference * @param string $exReference
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::getReference
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -32,9 +32,7 @@ class SourceTagTest extends \PHPUnit_Framework_TestCase
* @param string $exStartingLine * @param string $exStartingLine
* @param string $exLineCount * @param string $exLineCount
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag::getStartingLine
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag::getLineCount
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -33,7 +33,6 @@ class ThrowsTagTest extends \PHPUnit_Framework_TestCase
* @param string $extractedDescription * @param string $extractedDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag * @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag
*
* @dataProvider provideDataForConstructor * @dataProvider provideDataForConstructor
* *
* @return void * @return void
@@ -32,7 +32,7 @@ class VarTagTest extends \PHPUnit_Framework_TestCase
* @param string $exVariable * @param string $exVariable
* @param string $exDescription * @param string $exDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -32,8 +32,7 @@ class VersionTagTest extends \PHPUnit_Framework_TestCase
* @param string $exDescription * @param string $exDescription
* @param string $exVersion * @param string $exVersion
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VersionTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\VersionTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VersionTag::getVersion
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -272,9 +272,7 @@ TAG_HANDLER
* @param string $content * @param string $content
* @param string $exDescription * @param string $exDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag
* @covers \phpDocumentor\Reflection\DocBlock\Tag::getDescription
* @covers \phpDocumentor\Reflection\DocBlock\Tag::getContent
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -309,11 +307,6 @@ TAG_HANDLER
'unknown', 'unknown',
'', '',
'', '',
),
array(
'',
'unknown',
'unknown',
) )
); );
} }