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:


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) {
      string(15) "Set createdDate"
      string(0) ""
      array(1) {
        object(Zend_CodeGenerator_Php_Docblock_Tag_Param)#717 (7) {
          string(5) "param"
          string(4) "    "
      string(0) ""
      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) {

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.


No comments to display

Have you found an issue?

See the Overview section for more details.


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

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