Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3214'
Browse files Browse the repository at this point in the history
Close #3214
  • Loading branch information
weierophinney committed Dec 13, 2012
2 parents c9eea75 + 6965b0a commit 09bac30
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
29 changes: 12 additions & 17 deletions library/Zend/Code/Generator/DocBlock/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
class Tag extends AbstractGenerator
{

/**
* @var array
*/
protected static $typeFormats = array(
array(
'param',
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -130,14 +126,13 @@ public function getDescription()
}

/**
* generate()
*
* @return string
*/
public function generate()
{
$output = '@' . $this->name
. (($this->description != null) ? ' ' . $this->description : '');

return $output;
}

Expand Down
10 changes: 5 additions & 5 deletions library/Zend/Code/Generator/DocBlockGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public static function fromArray(array $array)
*/
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);
}
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public function setTag($tag)
}

/**
* @return array
* @return DocBlock\Tag[]
*/
public function getTags()
{
Expand Down
12 changes: 12 additions & 0 deletions tests/ZendTest/Code/Generator/DocBlockGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,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');
Expand Down

0 comments on commit 09bac30

Please sign in to comment.