Permalink
Browse files

Added getParameterType() method.

  • Loading branch information...
1 parent a2ea32f commit 37c03b12a03cd22bcc8025b6c21ad453596c1a7a Stefan Priebsch committed Oct 11, 2009
Showing with 26 additions and 0 deletions.
  1. +13 −0 DocBlock.php
  2. +13 −0 DocBlockTest.php
View
@@ -246,6 +246,19 @@ public function getParam($index)
return str_replace('@param ', '', $this->paramTags[$index]);
}
+ public function getParamType($index)
+ {
+ $param = $this->getParam($index);
+ $pos = strpos($param, ' ');
+
+ // No spaces, we assume that full string is the type
+ if ($pos === false) {
+ $pos = strlen($param);
+ }
+
+ return substr($param, 0, $pos);
+ }
+
public function getNumberOfParamTags()
{
return sizeof($this->paramTags);
View
@@ -94,6 +94,19 @@ public function testGetParams()
$this->assertEquals('int $bar Number of bars', $this->docBlock->getParam(1));
}
+ public function testGetParamType()
+ {
+ $this->docBlock->parse(file_get_contents(__DIR__ . '/_testdata/docblock'));
+ $this->assertEquals('string', $this->docBlock->getParamType(0));
+ $this->assertEquals('int', $this->docBlock->getParamType(1));
+ }
+
+ public function testGetParamTypeForParameterWithoutDescription()
+ {
+ $this->docBlock->parse(file_get_contents(__DIR__ . '/_testdata/param_without_description'));
+ $this->assertEquals('string', $this->docBlock->getParamType(0));
+ }
+
public function testGetReturn()
{
$this->docBlock->parse(file_get_contents(__DIR__ . '/_testdata/docblock'));

0 comments on commit 37c03b1

Please sign in to comment.