mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
Imported DocBlock Reflection and transformed into a PHP 5.3 module
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.idea
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "phpdocumentor/reflection-docblock",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Mike van Riel", "email": "[email protected]"}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {"phpDocumentor/Reflection": "src/phpDocumentor"}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<phpunit colors="true" strict="true">
|
||||
<testsuites>
|
||||
<testsuite name="phpDocumentor\Reflection\DocBlock">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Parses the DocBlock for any structure.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class DocBlock implements \Reflector
|
||||
{
|
||||
/** @var string The opening line for this docblock. */
|
||||
protected $short_description = '';
|
||||
|
||||
/**
|
||||
* @var \phpDocumentor\Reflection\DocBlock\LongDescription The actual description
|
||||
* for this docblock.
|
||||
*/
|
||||
protected $long_description = null;
|
||||
|
||||
/**
|
||||
* @var \phpDocumentor\Reflection\DocBlock\Tags[] An array containing all the tags
|
||||
* in this docblock; except inline.
|
||||
*/
|
||||
protected $tags = array();
|
||||
|
||||
/**
|
||||
* Parses the given docblock and populates the member fields.
|
||||
*
|
||||
* @param string|\Reflector $docblock A docblock comment (including asterisks)
|
||||
* or reflector supporting the getDocComment method.
|
||||
*/
|
||||
public function __construct($docblock)
|
||||
{
|
||||
if (is_object($docblock)) {
|
||||
if (!method_exists($docblock, 'getDocComment')) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Invalid object passed; the given reflector must support '
|
||||
. 'the getDocComment method'
|
||||
);
|
||||
}
|
||||
|
||||
$docblock = $docblock->getDocComment();
|
||||
}
|
||||
|
||||
$docblock = $this->cleanInput($docblock);
|
||||
|
||||
list($short, $long, $tags) = $this->splitDocBlock($docblock);
|
||||
$this->short_description = $short;
|
||||
$this->long_description = new DocBlock\LongDescription($long);
|
||||
$this->parseTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the asterisks from the DocBlock comment.
|
||||
*
|
||||
* @param string $comment String containing the comment text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function cleanInput($comment)
|
||||
{
|
||||
$comment = trim(
|
||||
preg_replace(
|
||||
'#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#', '$1', $comment
|
||||
)
|
||||
);
|
||||
|
||||
// reg ex above is not able to remove */ from a single line docblock
|
||||
if (substr($comment, -2) == '*/') {
|
||||
$comment = trim(substr($comment, 0, -2));
|
||||
}
|
||||
|
||||
// normalize strings
|
||||
$comment = str_replace(array("\r\n", "\r"), "\n", $comment);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the DocBlock into a short description, long description and
|
||||
* block of tags.
|
||||
*
|
||||
* @param string $comment Comment to split into the sub-parts.
|
||||
*
|
||||
* @author RichardJ Special thanks to RichardJ for the regex responsible
|
||||
* for the split/
|
||||
*
|
||||
* @return string[] containing the short-, long description and an element
|
||||
* containing the tags.
|
||||
*/
|
||||
protected function splitDocBlock($comment)
|
||||
{
|
||||
if (strpos($comment, '@') === 0) {
|
||||
$matches = array('', '', $comment);
|
||||
} else {
|
||||
// clears all extra horizontal whitespace from the line endings
|
||||
// to prevent parsing issues
|
||||
$comment = preg_replace('~(?m)\h*$~', '', $comment);
|
||||
|
||||
/*
|
||||
* Splits the docblock into a short description, long description and
|
||||
* tags section
|
||||
* - The short description is started from the first character until
|
||||
* a dot is encountered followed by a whitespace OR
|
||||
* two consecutive newlines (horizontal whitespace is taken into
|
||||
* account to consider spacing errors)
|
||||
* - The long description, any character until a new line is
|
||||
* encountered followed by an @ and word characters (a tag).
|
||||
* This is optional.
|
||||
* - Tags; the remaining characters
|
||||
*
|
||||
* Big thanks to RichardJ for contributing this Regular Expression
|
||||
*/
|
||||
preg_match(
|
||||
'/(?x)
|
||||
\A (
|
||||
[^\n]+
|
||||
(?:
|
||||
(?! (?<=\.) \n | \n{2} ) # disallow the first seperator here
|
||||
\n (?! [ \t]* @\pL ) # disallow second seperator
|
||||
[^\n]+
|
||||
)*
|
||||
\.?
|
||||
)
|
||||
(?:
|
||||
\s* # first seperator (actually newlines but it\'s all whitespace)
|
||||
(?! @\pL ) # disallow the rest, to make sure this one doesn\'t match,
|
||||
#if it doesn\'t exist
|
||||
(
|
||||
[^\n]+
|
||||
(?: \n+
|
||||
(?! [ \t]* @\pL ) # disallow second seperator (@param)
|
||||
[^\n]+
|
||||
)*
|
||||
)
|
||||
)?
|
||||
(\s+ [\s\S]*)? # everything that follows
|
||||
/', $comment, $matches
|
||||
);
|
||||
array_shift($matches);
|
||||
}
|
||||
|
||||
while (count($matches) < 3) {
|
||||
$matches[] = '';
|
||||
}
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the tag objects.
|
||||
*
|
||||
* @param string $tags Tag block to parse.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function parseTags($tags)
|
||||
{
|
||||
$result = array();
|
||||
foreach (explode("\n", trim($tags)) as $tag_line) {
|
||||
if (trim($tag_line) === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tag_line = ltrim($tag_line);
|
||||
|
||||
if (isset($tag_line[0]) && ($tag_line[0] === '@')) {
|
||||
$result[] = $tag_line;
|
||||
} else {
|
||||
if (count($result) == 0) {
|
||||
throw new \LogicException(
|
||||
'A tag block started with text instead of an actual tag,'
|
||||
. ' this makes the tag block invalid: ' . $tags
|
||||
);
|
||||
}
|
||||
|
||||
$result[count($result) - 1] .= PHP_EOL . $tag_line;
|
||||
}
|
||||
}
|
||||
|
||||
// create proper Tag objects
|
||||
foreach ($result as $key => $tag_line) {
|
||||
$result[$key] = DocBlock\Tag::createInstance($tag_line);
|
||||
}
|
||||
|
||||
$this->tags = $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the opening line or also known as short description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortDescription()
|
||||
{
|
||||
return $this->short_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full description or also known as long description.
|
||||
*
|
||||
* @return \phpDocumentor\Reflection\DocBlock\LongDescription
|
||||
*/
|
||||
public function getLongDescription()
|
||||
{
|
||||
return $this->long_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tags for this DocBlock.
|
||||
*
|
||||
* @return \phpDocumentor\Reflection\DocBlock\Tag[]
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of tags matching the given name; if no tags are found
|
||||
* an empty array is returned.
|
||||
*
|
||||
* @param string $name String to search by.
|
||||
*
|
||||
* @return \phpDocumentor\Reflection\DocBlock_Tag[]
|
||||
*/
|
||||
public function getTagsByName($name)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
/** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */
|
||||
foreach ($this->getTags() as $tag) {
|
||||
if ($tag->getName() != $name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = $tag;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a tag of a certain type is present in this DocBlock.
|
||||
*
|
||||
* @param string $name Tag name to check for.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTag($name)
|
||||
{
|
||||
/** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */
|
||||
foreach ($this->getTags() as $tag) {
|
||||
if ($tag->getName() == $name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a string representation of this object.
|
||||
*
|
||||
* @todo determine the exact format as used by PHP Reflection and
|
||||
* implement it.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function export()
|
||||
{
|
||||
throw new \Exception('Not yet implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported information (we should use the export static method
|
||||
* BUT this throws an exception at this point).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return 'Not yet implemented';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Parses a Long Description of a DocBlock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class LongDescription implements \Reflector
|
||||
{
|
||||
/** @var string */
|
||||
protected $contents = '';
|
||||
|
||||
/** @var \phpDocumentor\Reflection\DocBlock\Tags[] */
|
||||
protected $tags = array();
|
||||
|
||||
/**
|
||||
* Parses the string for inline tags and if the Markdown class is included;
|
||||
* format the found text.
|
||||
*
|
||||
* @param string $content the DocBlock contents without asterisks.
|
||||
*/
|
||||
public function __construct($content)
|
||||
{
|
||||
if (preg_match('/\{\@(.+?)\}/', $content, $matches)) {
|
||||
array_shift($matches);
|
||||
foreach ($matches as $tag) {
|
||||
$this->tags[] = Tag::createInstance('@' . $tag);
|
||||
}
|
||||
}
|
||||
|
||||
$this->contents = trim($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text of this description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
return $this->contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formatted variant of the Long Description using MarkDown.
|
||||
*
|
||||
* @todo this should become a more intelligent piece of code where the
|
||||
* configuration contains a setting what format long descriptions are.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedContents()
|
||||
{
|
||||
$result = $this->contents;
|
||||
|
||||
// if the long description contains a plain HTML <code> element, surround
|
||||
// it with a pre element. Please note that we explicitly used str_replace
|
||||
// and not preg_replace to gain performance
|
||||
if (strpos($result, '<code>') !== false) {
|
||||
$result = str_replace(
|
||||
array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'),
|
||||
array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'),
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
if (class_exists('\dflydev\markdown\MarkdownExtraParser()')) {
|
||||
$md = new \dflydev\markdown\MarkdownExtraParser();
|
||||
$result = $md->transformMarkdown($result);
|
||||
}
|
||||
|
||||
return trim($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of tags mentioned in the text.
|
||||
*
|
||||
* @return \phpDocumentor\Reflection\DocBlock\Tags[]
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a string representation of this object.
|
||||
*
|
||||
* @todo determine the exact format as used by PHP Reflection and implement it.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function export()
|
||||
{
|
||||
throw new \Exception('Not yet implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported information (we should use the export static method
|
||||
* BUT this throws an exception at this point).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return 'Not yet implemented';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Parses a tag definition for a DocBlock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class Tag implements \Reflector
|
||||
{
|
||||
/** @var string Name of the tag */
|
||||
protected $tag = '';
|
||||
|
||||
/** @var string content of the tag */
|
||||
protected $content = '';
|
||||
|
||||
/** @var string description of the content of this tag */
|
||||
protected $description = '';
|
||||
|
||||
/** @var int line number of the tag */
|
||||
protected $line_number = 0;
|
||||
|
||||
/** @var object docblock class */
|
||||
protected $docblock;
|
||||
|
||||
/**
|
||||
* Factory method responsible for instantiating the correct sub type.
|
||||
*
|
||||
* @param string $tag_line The text for this tag, including description.
|
||||
*
|
||||
* @throws \InvalidArgumentException if an invalid tag line was presented.
|
||||
*
|
||||
* @return \phpDocumentor\Reflection\DocBlock\Tag
|
||||
*/
|
||||
public static function createInstance($tag_line)
|
||||
{
|
||||
if (!preg_match(
|
||||
'/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us', $tag_line, $matches
|
||||
)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Invalid tag_line detected: ' . $tag_line
|
||||
);
|
||||
}
|
||||
|
||||
// support hypphen separated tag names
|
||||
$tag_name = str_replace(
|
||||
' ', '', ucwords(str_replace('-', ' ', $matches[1]))
|
||||
).'Tag';
|
||||
$class_name = '\\phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name;
|
||||
|
||||
return (@class_exists($class_name))
|
||||
? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '')
|
||||
: new self($matches[1], isset($matches[2]) ? $matches[2] : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Name of the tag.
|
||||
* @param string $content The contents of the given tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$this->content = $content;
|
||||
$this->description = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description component of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tag line number
|
||||
*
|
||||
* @param int $number the line number of the tag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setLineNumber($number)
|
||||
{
|
||||
$this->line_number = (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number of the tag
|
||||
*
|
||||
* @return int tag line number
|
||||
*/
|
||||
public function getLineNumber()
|
||||
{
|
||||
return $this->line_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the docblock class
|
||||
*
|
||||
* This exposes some common functionality contained in the docblock abstract.
|
||||
*
|
||||
* @param object $docblock Object containing the DocBlock.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDocBlock($docblock)
|
||||
{
|
||||
$this->docblock = $docblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a string representation of this object.
|
||||
*
|
||||
* @todo determine the exact format as used by PHP Reflection and implement it.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function export()
|
||||
{
|
||||
throw new \Exception('Not yet implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported information (we should use the export static method
|
||||
* BUT this throws an exception at this point).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return 'Not yet implemented';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a @covers tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class CoversTag extends SeeTag
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Ben Selby <[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;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
/**
|
||||
* Reflection class for a @link tag in a Docblock.
|
||||
*
|
||||
* @author Ben Selby <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class LinkTag extends Tag
|
||||
{
|
||||
/** @var string */
|
||||
protected $link = '';
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Tag type
|
||||
* @param string $content Content of the tag
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$pieces = explode(' ', $content);
|
||||
|
||||
if (count($pieces) > 1) {
|
||||
$this->link = array_shift($pieces);
|
||||
$this->description = implode(' ', $pieces);
|
||||
} else {
|
||||
$this->link = $content;
|
||||
$this->description = $content;
|
||||
}
|
||||
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLink()
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the link
|
||||
*
|
||||
* @param string $link The link
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setLink($link)
|
||||
{
|
||||
$this->link = $link;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@method} in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class MethodTag extends ParamTag
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
protected $method_name = '';
|
||||
|
||||
/** @var string */
|
||||
protected $arguments = '';
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Tag identifier for this tag (should be 'return')
|
||||
* @param string $content Contents for this tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$this->content = $content;
|
||||
|
||||
$matches = array();
|
||||
// 1. none or more whitespace
|
||||
// 2. optionally a word with underscores followed by whitespace : as
|
||||
// type for the return value
|
||||
// 3. then optionally a word with underscores followed by () and
|
||||
// whitespace : as method name as used by phpDocumentor
|
||||
// 4. then a word with underscores, followed by ( and any character
|
||||
// until a ) and whitespace : as method name with signature
|
||||
// 5. any remaining text : as description
|
||||
if (preg_match(
|
||||
'/^[\s]*(?:([\w\|_\\\\]+)[\s]+)?(?:[\w_]+\(\)[\s]+)?([\w\|_\\\\]+)\(([^\)]*)\)'
|
||||
.'[\s]*(.*)/u',
|
||||
$content,
|
||||
$matches
|
||||
)) {
|
||||
list(
|
||||
,
|
||||
$this->type,
|
||||
$this->method_name,
|
||||
$this->arguments,
|
||||
$this->description
|
||||
) = $matches;
|
||||
if (!$this->type)
|
||||
{
|
||||
$this->type = 'void';
|
||||
}
|
||||
} else {
|
||||
echo date('c') . ' ERR (3): @method contained invalid contents: '
|
||||
. $this->content . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this method.
|
||||
*
|
||||
* @param string $method_name The name of the method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMethodName($method_name)
|
||||
{
|
||||
$this->method_name = $method_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the method name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethodName()
|
||||
{
|
||||
return $this->method_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the arguments for this method.
|
||||
*
|
||||
* @param string $arguments A comma-separated arguments line.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setArguments($arguments)
|
||||
{
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing each argument as array of type and name.
|
||||
*
|
||||
* Please note that the argument sub-array may only contain 1 element if no
|
||||
* type was specified.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
if (empty($this->arguments)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$arguments = explode(',', $this->arguments);
|
||||
foreach ($arguments as $key => $value) {
|
||||
$arguments[$key] = explode(' ', trim($value));
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@param} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class ParamTag extends Tag
|
||||
{
|
||||
/** @var string */
|
||||
protected $type = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $variableName = null;
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Tag identifier for this tag (should be 'return')
|
||||
* @param string $content Contents for this tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$this->content = $content;
|
||||
$content = preg_split('/\s+/u', $content);
|
||||
|
||||
// if there is only 1, it is either a piece of content or a variable name
|
||||
if (count($content) > 1) {
|
||||
$this->type = array_shift($content);
|
||||
}
|
||||
|
||||
// if the next item starts with a $ it must be the variable name
|
||||
if ((strlen($content[0]) > 0) && ($content[0][0] == '$')) {
|
||||
$this->variableName = array_shift($content);
|
||||
}
|
||||
|
||||
$this->description = implode(' ', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique types of the variable.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTypes()
|
||||
{
|
||||
$types = explode('|', $this->type);
|
||||
array_walk($types, 'trim');
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type section of the variable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable's name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVariableName()
|
||||
{
|
||||
return $this->variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the variable's name.
|
||||
*
|
||||
* @param string $name The new name for this variable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setVariableName($name)
|
||||
{
|
||||
$this->variableName = $name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@property} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class PropertyReadTag extends PropertyTag
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@property} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class PropertyTag extends ParamTag
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@property} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class PropertyWriteTag extends PropertyTag
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@return} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class ReturnTag extends ParamTag
|
||||
{
|
||||
/** @var string */
|
||||
protected $type = null;
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Tag identifier for this tag (should be 'return')
|
||||
* @param string $content Contents for this tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$this->content = $content;
|
||||
$content = preg_split('/\s+/u', $content);
|
||||
|
||||
// any output is considered a type
|
||||
$this->type = array_shift($content);
|
||||
|
||||
$this->description = implode(' ', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the variable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTypes()
|
||||
{
|
||||
$types = explode('|', $this->type);
|
||||
array_walk($types, 'trim');
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the variable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@see} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class SeeTag extends Tag
|
||||
{
|
||||
/** @var string */
|
||||
protected $refers = null;
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Tag identifier for this tag (should be 'return')
|
||||
* @param string $content Contents for this tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$this->content = $content;
|
||||
$content = preg_split('/\s+/u', $content);
|
||||
|
||||
// any output is considered a type
|
||||
$this->refers = array_shift($content);
|
||||
|
||||
$this->description = implode(' ', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the variable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReference()
|
||||
{
|
||||
return $this->refers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a mistyped @throws tag called @throw in a Docblock.
|
||||
*
|
||||
* This is a very common error, so @throw is aliased to be @throws
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class ThrowTag extends ThrowsTag
|
||||
{
|
||||
/**
|
||||
* Sets the type to {@throws} and lets parent parse the tag and populates the
|
||||
* member variables.
|
||||
*
|
||||
* @param string $type Tag identifier for this tag (should be 'return')
|
||||
* @param string $content Contents for this tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
if ('throw' !== $type) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Internal error, ' . __CLASS__ . ' was called with ' . $type
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct('throws', $content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@throws} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class ThrowsTag extends ReturnTag
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@uses} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class UsesTag extends SeeTag
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[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;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@var} tag in a Docblock.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class VarTag extends ParamTag
|
||||
{
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
*
|
||||
* @param string $type Tag identifier for this tag (should be 'return')
|
||||
* @param string $content Contents for this tag.
|
||||
*/
|
||||
public function __construct($type, $content)
|
||||
{
|
||||
$this->tag = $type;
|
||||
$this->content = $content;
|
||||
$content = preg_split('/\s+/u', $content);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Covers Tag Test
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag.php';
|
||||
require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php';
|
||||
require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Covers
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class CoversTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\Covers can create a link
|
||||
* for the covers doc block
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $exName
|
||||
* @param string $exContent
|
||||
* @param string $exReference
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\Covers::__construct
|
||||
* @dataProvider provideDataForConstuctor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParesInputsIntoCorrectFields(
|
||||
$type, $content, $exName, $exContent, $exDescription, $exReference
|
||||
)
|
||||
{
|
||||
$tag = new CoversTag($type, $content);
|
||||
|
||||
$actualName = $tag->getName();
|
||||
$actualContent = $tag->getContent();
|
||||
$actualDescription = $tag->getDescription();
|
||||
$actualReference = $tag->getReference();
|
||||
|
||||
$this->assertEquals($exName, $actualName);
|
||||
$this->assertEquals($exContent, $actualContent);
|
||||
$this->assertEquals($exDescription, $actualDescription);
|
||||
$this->assertEquals($exReference, $actualReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstuctor()
|
||||
{
|
||||
// $type, $content, $exName, $exContent, $exDescription, $exReference
|
||||
return array(
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar()',
|
||||
'uses',
|
||||
'Foo::bar()',
|
||||
'',
|
||||
'Foo::bar()'
|
||||
),
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar() Testing',
|
||||
'uses',
|
||||
'Foo::bar() Testing',
|
||||
'Testing',
|
||||
'Foo::bar()',
|
||||
),
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar() Testing comments',
|
||||
'uses',
|
||||
'Foo::bar() Testing comments',
|
||||
'Testing comments',
|
||||
'Foo::bar()',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Link Tag Test
|
||||
*
|
||||
* @author Ben Selby <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php';
|
||||
|
||||
/**
|
||||
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
|
||||
*
|
||||
* @author Ben Selby <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class LinkTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
|
||||
* a link for the @link doc block
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $exName
|
||||
* @param string $exContent
|
||||
* @param string $exDescription
|
||||
* @param string $exLink
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct
|
||||
* @dataProvider provideDataForConstuctor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParesInputsIntoCorrectFields(
|
||||
$type, $content, $exName, $exContent, $exDescription, $exLink
|
||||
)
|
||||
{
|
||||
$tag = new LinkTag($type, $content);
|
||||
|
||||
$actualName = $tag->getName();
|
||||
$actualContent = $tag->getContent();
|
||||
$actualDescription = $tag->getDescription();
|
||||
$actualLink = $tag->getLink();
|
||||
|
||||
$this->assertEquals($exName, $actualName);
|
||||
$this->assertEquals($exContent, $actualContent);
|
||||
$this->assertEquals($exDescription, $actualDescription);
|
||||
$this->assertEquals($exLink, $actualLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstuctor()
|
||||
{
|
||||
// $type, $content, $exName, $exContent, $exDescription, $exLink
|
||||
return array(
|
||||
array(
|
||||
'link',
|
||||
'http://www.phpdoc.org/',
|
||||
'link',
|
||||
'http://www.phpdoc.org/',
|
||||
'http://www.phpdoc.org/',
|
||||
'http://www.phpdoc.org/'
|
||||
),
|
||||
array(
|
||||
'link',
|
||||
'http://www.phpdoc.org/ Testing',
|
||||
'link',
|
||||
'http://www.phpdoc.org/ Testing',
|
||||
'Testing',
|
||||
'http://www.phpdoc.org/'
|
||||
),
|
||||
array(
|
||||
'link',
|
||||
'http://www.phpdoc.org/ Testing comments',
|
||||
'link',
|
||||
'http://www.phpdoc.org/ Testing comments',
|
||||
'Testing comments',
|
||||
'http://www.phpdoc.org/'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Method Tag Test
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php';
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php';
|
||||
|
||||
/**
|
||||
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class MethodTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTestSignatures
|
||||
*
|
||||
* @param string $signature The signature to test
|
||||
* @param bool $valid Whether the given signature is expected to
|
||||
* be valid.
|
||||
* @param string $expected_name The method name that is expected from this
|
||||
* signature
|
||||
* @param string $expected_return The return type that is expected from this
|
||||
* signature
|
||||
* @param bool $has_params whether this signature features parameters.
|
||||
* @param string $description The short description mentioned in the
|
||||
* signature.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstruct($signature, $valid, $expected_name,
|
||||
$expected_return, $has_params, $description)
|
||||
{
|
||||
ob_start();
|
||||
$tag = new MethodTag('method', $signature);
|
||||
$stdout = ob_get_clean();
|
||||
|
||||
$this->assertSame(
|
||||
$valid, empty($stdout),
|
||||
'No error should have been output if the signature is valid'
|
||||
);
|
||||
|
||||
if (!$valid) return;
|
||||
|
||||
$this->assertEquals($expected_name, $tag->getMethodName());
|
||||
$this->assertEquals($expected_return, $tag->getType());
|
||||
$this->assertEquals($description, $tag->getDescription());
|
||||
$this->assertSame(
|
||||
$has_params, (bool)(count($tag->getArguments()) > 0),
|
||||
'Number of found arguments should exceed 0'
|
||||
);
|
||||
}
|
||||
|
||||
public function getTestSignatures()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'foo',
|
||||
false, 'foo', '', false, ''
|
||||
),
|
||||
array(
|
||||
'foo()',
|
||||
true, 'foo', 'void', false, ''
|
||||
),
|
||||
array(
|
||||
'foo() description',
|
||||
true, 'foo', 'void', false, 'description'
|
||||
),
|
||||
array(
|
||||
'int foo()',
|
||||
true, 'foo', 'int', false, ''
|
||||
),
|
||||
array(
|
||||
'int foo() description',
|
||||
true, 'foo', 'int', false, 'description'
|
||||
),
|
||||
array(
|
||||
'int foo($a, $b)',
|
||||
true, 'foo', 'int', true, ''
|
||||
),
|
||||
array(
|
||||
'int foo() foo(int $a, int $b)',
|
||||
true, 'foo', 'int', true, ''
|
||||
),
|
||||
array(
|
||||
'int foo(int $a, int $b)',
|
||||
true, 'foo', 'int', true, ''
|
||||
),
|
||||
array(
|
||||
'null|int foo(int $a, int $b)',
|
||||
true, 'foo', 'null|int', true, ''
|
||||
),
|
||||
array(
|
||||
'int foo(null|int $a, int $b)',
|
||||
true, 'foo', 'int', true, ''
|
||||
),
|
||||
array(
|
||||
'\Exception foo() foo(Exception $a, Exception $b)',
|
||||
true, 'foo', '\Exception', true, ''
|
||||
),
|
||||
array(
|
||||
'int foo() foo(Exception $a, Exception $b) description',
|
||||
true, 'foo', 'int', true, 'description'
|
||||
),
|
||||
array(
|
||||
'int foo() foo(\Exception $a, \Exception $b) description',
|
||||
true, 'foo', 'int', true, 'description'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor See Tag Test
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_See
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class SeeTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
|
||||
* for the @see doc block
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $exName
|
||||
* @param string $exContent
|
||||
* @param string $exReference
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct
|
||||
* @dataProvider provideDataForConstuctor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParesInputsIntoCorrectFields(
|
||||
$type, $content, $exName, $exContent, $exDescription, $exReference
|
||||
)
|
||||
{
|
||||
$tag = new SeeTag($type, $content);
|
||||
|
||||
$actualName = $tag->getName();
|
||||
$actualContent = $tag->getContent();
|
||||
$actualDescription = $tag->getDescription();
|
||||
$actualReference = $tag->getReference();
|
||||
|
||||
$this->assertEquals($exName, $actualName);
|
||||
$this->assertEquals($exContent, $actualContent);
|
||||
$this->assertEquals($exDescription, $actualDescription);
|
||||
$this->assertEquals($exReference, $actualReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstuctor()
|
||||
{
|
||||
// $type, $content, $exName, $exContent, $exDescription, $exReference
|
||||
return array(
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar()',
|
||||
'uses',
|
||||
'Foo::bar()',
|
||||
'',
|
||||
'Foo::bar()'
|
||||
),
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar() Testing',
|
||||
'uses',
|
||||
'Foo::bar() Testing',
|
||||
'Testing',
|
||||
'Foo::bar()',
|
||||
),
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar() Testing comments',
|
||||
'uses',
|
||||
'Foo::bar() Testing comments',
|
||||
'Testing comments',
|
||||
'Foo::bar()',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Uses Tag Test
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Uses
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class UsesTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\UsesTag can create
|
||||
* a link for the @uses doc block
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $exName
|
||||
* @param string $exContent
|
||||
* @param string $exReference
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct
|
||||
* @dataProvider provideDataForConstuctor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParesInputsIntoCorrectFields(
|
||||
$type, $content, $exName, $exContent, $exDescription, $exReference
|
||||
)
|
||||
{
|
||||
$tag = new UsesTag($type, $content);
|
||||
|
||||
$actualName = $tag->getName();
|
||||
$actualContent = $tag->getContent();
|
||||
$actualDescription = $tag->getDescription();
|
||||
$actualReference = $tag->getReference();
|
||||
|
||||
$this->assertEquals($exName, $actualName);
|
||||
$this->assertEquals($exContent, $actualContent);
|
||||
$this->assertEquals($exDescription, $actualDescription);
|
||||
$this->assertEquals($exReference, $actualReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstuctor()
|
||||
{
|
||||
// $type, $content, $exName, $exContent, $exDescription, $exReference
|
||||
return array(
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar()',
|
||||
'uses',
|
||||
'Foo::bar()',
|
||||
'',
|
||||
'Foo::bar()'
|
||||
),
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar() Testing',
|
||||
'uses',
|
||||
'Foo::bar() Testing',
|
||||
'Testing',
|
||||
'Foo::bar()',
|
||||
),
|
||||
array(
|
||||
'uses',
|
||||
'Foo::bar() Testing comments',
|
||||
'uses',
|
||||
'Foo::bar() Testing comments',
|
||||
'Testing comments',
|
||||
'Foo::bar()',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Var Tag Test
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Link
|
||||
*
|
||||
* @author Daniel O'Connor <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class VarTagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can understand
|
||||
* the @var doc block
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $exType
|
||||
* @param string $exVariable
|
||||
* @param string $exDescription
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag::__construct
|
||||
* @dataProvider provideDataForConstuctor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParesInputsIntoCorrectFields(
|
||||
$type, $content, $exType, $exVariable, $exDescription
|
||||
)
|
||||
{
|
||||
$tag = new VarTag($type, $content);
|
||||
|
||||
$this->assertEquals($exType, $tag->getType());
|
||||
$this->assertEquals($exVariable, $tag->getVariableName());
|
||||
$this->assertEquals($exDescription, $tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstuctor()
|
||||
{
|
||||
// $type, $content
|
||||
return array(
|
||||
array(
|
||||
'var',
|
||||
'int',
|
||||
'int',
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'var',
|
||||
'int $bob',
|
||||
'int',
|
||||
'$bob',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'var',
|
||||
'int $bob Number of bobs',
|
||||
'int',
|
||||
'$bob',
|
||||
'Number of bobs'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor DocBlock Test
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection;
|
||||
|
||||
require_once __DIR__.'/../../../src/phpDocumentor/Reflection/DocBlock.php';
|
||||
require_once __DIR__.'/../../../src/phpDocumentor/Reflection/DocBlock/LongDescription.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
*/
|
||||
class DocBlockTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$fixture = <<<DOCBLOCK
|
||||
/**
|
||||
* This is a short description.
|
||||
*
|
||||
* This is a long description.
|
||||
*
|
||||
* @see \MyClass
|
||||
* @return void
|
||||
*/
|
||||
DOCBLOCK;
|
||||
$object = new DocBlock($fixture);
|
||||
$this->assertEquals(
|
||||
'This is a short description.', $object->getShortDescription()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'This is a long description.', $object->getLongDescription()->getContents()
|
||||
);
|
||||
$this->assertEquals(2, count($object->getTags()));
|
||||
$this->assertTrue($object->hasTag('see'));
|
||||
$this->assertTrue($object->hasTag('return'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user