Issues

ZF-11389: Zend_CodeGenerator_Php_Docblock_Tag::fromReflection() does not set data type

Description

When building a doc block tag from reflection, {{Zend_CodeGenerator_Php_Docblock_Tag::fromReflection()}} uses the reflection class's accessor method names to determine which setter methods to execute; however {{Zend_CodeGenerator_Php_Docblock_Tag_Return::setType()}} does not exist, it's actually still {{Zend_CodeGenerator_Php_Docblock_Tag_Return::setDatatype()}} at the moment so something like the patch below is needed.

Example input (taken from actual class I have been reflecting):


/**
 * Set createdDate
 *
 * @param datetime $createdDate
 */

Example {{Zend_CodeGenerator_Php_Docblock}} instance built from {{Zend_CodeGenerator_Php_Docblock_Tag::fromReflection()}} - notice how {{Zend_CodeGenerator_Php_Docblock_Tag_Param::_datatype}} is NULL:


object(Zend_CodeGenerator_Php_Docblock)#716 (6) {
      ["_shortDescription":protected]=>
      string(15) "Set createdDate"
      ["_longDescription":protected]=>
      string(0) ""
      ["_tags":protected]=>
      array(1) {
        [0]=>
        object(Zend_CodeGenerator_Php_Docblock_Tag_Param)#717 (7) {
          ["_datatype":protected]=>
          NULL
          ["_paramName":protected]=>
          NULL
          ["_description":protected]=>
          NULL
          ["_name":protected]=>
          string(5) "param"
          ["_isSourceDirty":protected]=>
          bool(true)
          ["_indentation":protected]=>
          string(4) "    "
          ["_sourceContent":protected]=>
          NULL
        }
      }
      ["_indentation":protected]=>
      string(0) ""
      ["_isSourceDirty":protected]=>
      bool(false)
      ["_sourceContent":protected]=>
      string(46) "Set createdDate
    
    @param datetime $createdDate
    "
}

Which results in the following code snippet outputting NULL upon each iteration instead of the actual reflected data type:


foreach ($codeGenerator->getClass()->getMethods() as $method) {
    foreach ($method->getDocblock()->getTags() as $tag) {
        if ($tag instanceof Zend_CodeGenerator_Php_Docblock_Tag_Return) {
            var_dump($tag->getDatatype());
        }
    }
}

Suggested patch:


### Eclipse Workspace Patch 1.0
#P framework
Index: libs/Zend/CodeGenerator/Php/Docblock/Tag.php
===================================================================
--- libs/Zend/CodeGenerator/Php/Docblock/Tag.php    (revision 24037)
+++ libs/Zend/CodeGenerator/Php/Docblock/Tag.php    (working copy)
@@ -78,6 +78,9 @@
                 $propertyName = substr($method->getName(), 3);
                 if (method_exists($codeGenDocblockTag, 'set' . $propertyName)) {
                     $codeGenDocblockTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}());
+                } else if ((0 === strcmp('Type', $propertyName))
+                    && method_exists($codeGenDocblockTag, 'setDatatype')) {
+                    $codeGenDocblockTag->setDatatype($reflectionTag->getType());
                 }
             }
         }

Of course an alternative is to refactor the method name from {{Zend_CodeGenerator_Php_Docblock_Tag_Return::setDatatype()}} to {{Zend_CodeGenerator_Php_Docblock_Tag_Return::setType()}} in which case the above patch would not be required.

The same may apply to {{Zend_CodeGenerator_Php_Docblock_Tag_Param}} but I've not tested this.

Comments

No comments to display