Permalink
Browse files

Fix passing of tags to docblock generator class

  • Loading branch information...
1 parent 0ef37c6 commit e879e8b93e562098bf240d92392bfa8482c23ace @neeckeloo neeckeloo committed Dec 13, 2012
@@ -19,7 +19,9 @@
*/
class Tag extends AbstractGenerator
{
-
+ /**
+ * @var array
+ */
protected static $typeFormats = array(
array(
'param',
@@ -50,18 +52,18 @@ class Tag extends AbstractGenerator
*/
public function __construct(array $options = array())
{
- if (array_key_exists('name', $options)) {
+ if (isset($options['name'])) {
$this->setName($options['name']);
}
- if (array_key_exists('description', $options)) {
+ if (isset($options['description'])) {
$this->setDescription($options['description']);
}
}
/**
- * fromReflection()
+ * Build a Tag generator object from a reflection object
*
- * @param ReflectionDocBlockTag $reflectionTag
+ * @param ReflectionDocBlockTag $reflectionTag
* @return Tag
*/
public static function fromReflection(ReflectionDocBlockTag $reflectionTag)
@@ -86,20 +88,17 @@ public static function fromReflection(ReflectionDocBlockTag $reflectionTag)
}
/**
- * setName()
- *
- * @param string $name
+ * @param string $name
* @return Tag
*/
public function setName($name)
{
$this->name = ltrim($name, '@');
+
return $this;
}
/**
- * getName()
- *
* @return string
*/
public function getName()
@@ -108,20 +107,17 @@ public function getName()
}
/**
- * setDescription()
- *
- * @param string $description
+ * @param string $description
* @return Tag
*/
public function setDescription($description)
{
$this->description = $description;
+
return $this;
}
/**
- * getDescription()
- *
* @return string
*/
public function getDescription()
@@ -130,14 +126,13 @@ public function getDescription()
}
/**
- * generate()
- *
* @return string
*/
public function generate()
{
$output = '@' . $this->name
. (($this->description != null) ? ' ' . $this->description : '');
+
return $output;
}
@@ -39,9 +39,9 @@ class DocBlockGenerator extends AbstractGenerator
protected $indentation = '';
/**
- * fromReflection() - Build a DocBlock generator object from a reflection object
+ * Build a DocBlock generator object from a reflection object
*
- * @param DocBlockReflection $reflectionDocBlock
+ * @param DocBlockReflection $reflectionDocBlock
* @return DocBlockGenerator
*/
public static function fromReflection(DocBlockReflection $reflectionDocBlock)
@@ -61,35 +61,36 @@ public static function fromReflection(DocBlockReflection $reflectionDocBlock)
return $docBlock;
}
+ /**
+ * @param string $shortDescription
+ * @param string $longDescription
+ * @param array $tags
+ */
public function __construct($shortDescription = null, $longDescription = null, array $tags = array())
{
- if ($shortDescription !== null) {
+ if ($shortDescription) {
$this->setShortDescription($shortDescription);
}
- if ($longDescription !== null) {
+ if ($longDescription) {
$this->setLongDescription($longDescription);
}
- if ($this->tags !== array()) {
- $this->setTag($tags);
+ if (is_array($tags) && $tags) {
+ $this->setTags($tags);
}
-
}
/**
- * setShortDescription()
- *
- * @param string $shortDescription
+ * @param string $shortDescription
* @return DocBlockGenerator
*/
public function setShortDescription($shortDescription)
{
$this->shortDescription = $shortDescription;
+
return $this;
}
/**
- * getShortDescription()
- *
* @return string
*/
public function getShortDescription()
@@ -98,20 +99,17 @@ public function getShortDescription()
}
/**
- * setLongDescription()
- *
- * @param string $longDescription
+ * @param string $longDescription
* @return DocBlockGenerator
*/
public function setLongDescription($longDescription)
{
$this->longDescription = $longDescription;
+
return $this;
}
/**
- * getLongDescription()
- *
* @return string
*/
public function getLongDescription()
@@ -120,9 +118,7 @@ public function getLongDescription()
}
/**
- * setTags()
- *
- * @param array $tags
+ * @param array $tags
* @return DocBlockGenerator
*/
public function setTags(array $tags)
@@ -135,9 +131,7 @@ public function setTags(array $tags)
}
/**
- * setTag()
- *
- * @param array|DocBlock\Tag $tag
+ * @param array|DocBlock\Tag $tag
* @throws Exception\InvalidArgumentException
* @return DocBlockGenerator
*/
@@ -158,8 +152,6 @@ public function setTag($tag)
}
/**
- * getTags
- *
* @return DocBlock\Tag[]
*/
public function getTags()
@@ -168,8 +160,6 @@ public function getTags()
}
/**
- * generate()
- *
* @return string
*/
public function generate()
@@ -194,9 +184,7 @@ public function generate()
}
/**
- * docCommentize()
- *
- * @param string $content
+ * @param string $content
* @return string
*/
protected function docCommentize($content)
@@ -213,6 +201,7 @@ protected function docCommentize($content)
$output .= self::LINE_FEED;
}
$output .= $indent . ' */' . self::LINE_FEED;
+
return $output;
}
@@ -23,14 +23,28 @@
*/
class DocBlockGeneratorTest extends \PHPUnit_Framework_TestCase
{
- /** @var DocBlockGenerator */
+ /**
+ * @var DocBlockGenerator
+ */
protected $docBlockGenerator;
protected function setUp()
{
$this->docBlockGenerator = $this->docBlockGenerator = new DocBlockGenerator();
}
+ public function testCanPassTagsToContructor()
+ {
+ $docBlockGenerator = new DocBlockGenerator(null, null, array(
+ array('name' => 'foo')
+ ));
+
+ $tags = $docBlockGenerator->getTags();
+ $this->assertCount(1, $tags);
+
+ $this->assertEquals('foo', $tags[0]->getName());
+ }
+
public function testShortDescriptionGetterAndSetter()
{
$this->docBlockGenerator->setShortDescription('Short Description');

0 comments on commit e879e8b

Please sign in to comment.