Issues

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

Issue Type: Bug Created: 2011-05-19T13:58:23.000+0000 Last Updated: 2011-05-19T13:58:23.000+0000 Status: Open Fix version(s): Reporter: Stephen Lang (skl) Assignee: Ralph Schindler (ralph) Tags: - Zend_CodeGenerator

  • Zend_CodeGenerator_Php_Docblock_Tag

Related issues: Attachments:

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):

<pre class="highlight">
/**
 * 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:

<pre class="highlight">
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:

<pre class="highlight">
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:

<pre class="highlight">
### 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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts