Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix passing of tags to constructor of docblock generator class #3214

Closed
wants to merge 2 commits into from

2 participants

Nicolas Eeckeloo Matthew Weier O'Phinney
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
29 library/Zend/Code/Generator/DocBlock/Tag.php
View
@@ -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;
}
49 library/Zend/Code/Generator/DocBlockGenerator.php
View
@@ -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;
}
16 tests/ZendTest/Code/Generator/DocBlockGeneratorTest.php
View
@@ -23,7 +23,9 @@
*/
class DocBlockGeneratorTest extends \PHPUnit_Framework_TestCase
{
- /** @var DocBlockGenerator */
+ /**
+ * @var DocBlockGenerator
+ */
protected $docBlockGenerator;
protected function setUp()
@@ -31,6 +33,18 @@ protected function setUp()
$this->docBlockGenerator = $this->docBlockGenerator = new DocBlockGenerator();
}
+ public function testCanPassTagsToConstructor()
+ {
+ $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');
Something went wrong with that request. Please try again.