mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Added support for static method declarations at MethodTag and according unit tests.
Fixed MethodTag::getContent() to actually return the content as opposed to $this;
This commit is contained in:
@@ -30,18 +30,25 @@ class MethodTag extends ReturnTag
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
protected $arguments = '';
|
protected $arguments = '';
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
protected $isStatic = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
if (null === $this->content) {
|
if (null === $this->content) {
|
||||||
$this->content = $this->type .
|
$this->content = '';
|
||||||
|
if ($this->isStatic) {
|
||||||
|
$this->content .= 'static ';
|
||||||
|
}
|
||||||
|
$this->content .= $this->type .
|
||||||
" {$this->method_name}({$this->arguments}) " .
|
" {$this->method_name}({$this->arguments}) " .
|
||||||
$this->description;
|
$this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,15 +58,22 @@ class MethodTag extends ReturnTag
|
|||||||
{
|
{
|
||||||
Tag::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 the keyword "static" followed by whitespace
|
||||||
|
// 3. optionally a word with underscores followed by whitespace : as
|
||||||
// type for the return value
|
// type for the return value
|
||||||
// 3. then optionally a word with underscores followed by () and
|
// 4. then optionally a word with underscores followed by () and
|
||||||
// whitespace : as method name as used by phpDocumentor
|
// whitespace : as method name as used by phpDocumentor
|
||||||
// 4. then a word with underscores, followed by ( and any character
|
// 5. then a word with underscores, followed by ( and any character
|
||||||
// until a ) and whitespace : as method name with signature
|
// until a ) and whitespace : as method name with signature
|
||||||
// 5. any remaining text : as description
|
// 6. any remaining text : as description
|
||||||
if (preg_match(
|
if (preg_match(
|
||||||
'/^
|
'/^
|
||||||
|
# Static keyword
|
||||||
|
# Declates a static method ONLY if type is also present
|
||||||
|
(?:
|
||||||
|
(static)
|
||||||
|
\s+
|
||||||
|
)?
|
||||||
# Return type
|
# Return type
|
||||||
(?:
|
(?:
|
||||||
([\w\|_\\\\]+)
|
([\w\|_\\\\]+)
|
||||||
@@ -82,13 +96,22 @@ class MethodTag extends ReturnTag
|
|||||||
)) {
|
)) {
|
||||||
list(
|
list(
|
||||||
,
|
,
|
||||||
|
$static,
|
||||||
$this->type,
|
$this->type,
|
||||||
$this->method_name,
|
$this->method_name,
|
||||||
$this->arguments,
|
$this->arguments,
|
||||||
$this->description
|
$this->description
|
||||||
) = $matches;
|
) = $matches;
|
||||||
if (!$this->type) {
|
if ($static) {
|
||||||
$this->type = 'void';
|
if (!$this->type) {
|
||||||
|
$this->type = 'static';
|
||||||
|
} else {
|
||||||
|
$this->isStatic = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!$this->type) {
|
||||||
|
$this->type = 'void';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->parsedDescription = null;
|
$this->parsedDescription = null;
|
||||||
} else {
|
} else {
|
||||||
@@ -160,4 +183,30 @@ class MethodTag extends ReturnTag
|
|||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the method tag describes a static method or not.
|
||||||
|
*
|
||||||
|
* @return bool TRUE if the method declaration is for a static method, FALSE
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
public function isStatic()
|
||||||
|
{
|
||||||
|
return $this->isStatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new value for whether the method is static or not.
|
||||||
|
*
|
||||||
|
* @param bool $isStatic The new value to set.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setIsStatic($isStatic)
|
||||||
|
{
|
||||||
|
$this->isStatic = $isStatic;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$valid,
|
$valid,
|
||||||
$expected_name,
|
$expected_name,
|
||||||
$expected_return,
|
$expected_return,
|
||||||
|
$expected_isStatic,
|
||||||
$paramCount,
|
$paramCount,
|
||||||
$description
|
$description
|
||||||
) {
|
) {
|
||||||
@@ -64,6 +65,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected_name, $tag->getMethodName());
|
$this->assertEquals($expected_name, $tag->getMethodName());
|
||||||
$this->assertEquals($expected_return, $tag->getType());
|
$this->assertEquals($expected_return, $tag->getType());
|
||||||
$this->assertEquals($description, $tag->getDescription());
|
$this->assertEquals($description, $tag->getDescription());
|
||||||
|
$this->assertEquals($expected_isStatic, $tag->isStatic());
|
||||||
$this->assertCount($paramCount, $tag->getArguments());
|
$this->assertCount($paramCount, $tag->getArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,56 +74,72 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'foo',
|
'foo',
|
||||||
false, 'foo', '', 0, ''
|
false, 'foo', '', false, 0, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'foo()',
|
'foo()',
|
||||||
true, 'foo', 'void', 0, ''
|
true, 'foo', 'void', false, 0, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'foo() description',
|
'foo() description',
|
||||||
true, 'foo', 'void', 0, 'description'
|
true, 'foo', 'void', false, 0, 'description'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo()',
|
'int foo()',
|
||||||
true, 'foo', 'int', 0, ''
|
true, 'foo', 'int', false, 0, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo() description',
|
'int foo() description',
|
||||||
true, 'foo', 'int', 0, 'description'
|
true, 'foo', 'int', false, 0, 'description'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo($a, $b)',
|
'int foo($a, $b)',
|
||||||
true, 'foo', 'int', 2, ''
|
true, 'foo', 'int', false, 2, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo() foo(int $a, int $b)',
|
'int foo() foo(int $a, int $b)',
|
||||||
true, 'foo', 'int', 2, ''
|
true, 'foo', 'int', false, 2, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo(int $a, int $b)',
|
'int foo(int $a, int $b)',
|
||||||
true, 'foo', 'int', 2, ''
|
true, 'foo', 'int', false, 2, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'null|int foo(int $a, int $b)',
|
'null|int foo(int $a, int $b)',
|
||||||
true, 'foo', 'null|int', 2, ''
|
true, 'foo', 'null|int', false, 2, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo(null|int $a, int $b)',
|
'int foo(null|int $a, int $b)',
|
||||||
true, 'foo', 'int', 2, ''
|
true, 'foo', 'int', false, 2, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'\Exception foo() foo(Exception $a, Exception $b)',
|
'\Exception foo() foo(Exception $a, Exception $b)',
|
||||||
true, 'foo', '\Exception', 2, ''
|
true, 'foo', '\Exception', false, 2, ''
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo() foo(Exception $a, Exception $b) description',
|
'int foo() foo(Exception $a, Exception $b) description',
|
||||||
true, 'foo', 'int', 2, 'description'
|
true, 'foo', 'int', false, 2, 'description'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'int foo() foo(\Exception $a, \Exception $b) description',
|
'int foo() foo(\Exception $a, \Exception $b) description',
|
||||||
true, 'foo', 'int', 2, 'description'
|
true, 'foo', 'int', false, 2, 'description'
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'void()',
|
||||||
|
true, 'void', 'void', false, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'static foo()',
|
||||||
|
true, 'foo', 'static', false, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'static void foo()',
|
||||||
|
true, 'foo', 'void', true, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'static static foo()',
|
||||||
|
true, 'foo', 'static', true, 0, ''
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user