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

Zend code doesn't generate heredoc correctly #6253

Closed
Danack opened this issue May 12, 2014 · 6 comments
Closed

Zend code doesn't generate heredoc correctly #6253

Danack opened this issue May 12, 2014 · 6 comments
Assignees
Milestone

Comments

@Danack
Copy link

Danack commented May 12, 2014

require_once('../vendor/autoload.php');

}

Hi,

When code includes a heredoc block, the code generator doesn't respect the fact that the end of the heredoc needs to be at the start of a line. e.g.

use Weaver\ExtendWeaveInfo;
use Weaver\MethodBinding;
use Weaver\ImplementsWeaveInfo;

use Zend\Code\Reflection\ClassReflection;
use Zend\Code\Generator\ClassGenerator;

use Zend\Code\Generator\MethodGenerator;

class SomeClass {

    function someFunction() {

        $output = <<< END

        Fix it, fix it!
        Fix it, fix it!
        Fix it, fix it!
END;

    }
}

$reflector = new ClassReflection('SomeClass');
$classGenerator = new ClassGenerator();
$methods = $reflector->getMethods();
$classGenerator->setName("OutputClass");

foreach ($methods as $method) {
    $methodGenerator = MethodGenerator::fromReflection($method);

    $classGenerator->addMethodFromGenerator($methodGenerator);
}

$text = $classGenerator->generate();

echo $text;

generates:

class OutputClass
{

    public function someFunction()
    {
        $output = <<< END

                Fix it, fix it!
                Fix it, fix it!
                Fix it, fix it!
        END;
    }


}

The generated heredoc block is not valid, as it needs to be at the start of the line.

@Ocramius Ocramius added this to the 2.3.2 milestone May 12, 2014
@Ocramius
Copy link
Member

Seems like it also broke the string indentation...

@steverhoades
Copy link
Contributor

See pull request #6283 for a fix.

@steverhoades
Copy link
Contributor

@Ocramius can you be more specific as to the string indentation break? I'm happy to look at it.

@Ocramius
Copy link
Member

See the diff:

        $output = <<< END

        Fix it, fix it!
        Fix it, fix it!
        Fix it, fix it!
END;

vs

        $output = <<< END

                Fix it, fix it!
                Fix it, fix it!
                Fix it, fix it!
        END;

@Danack
Copy link
Author

Danack commented May 15, 2014

Just to confirm, I tested this against head, and it does appear to be valid issue.

@Ocramius Ocramius self-assigned this Jul 28, 2014
Ocramius added a commit that referenced this issue Jul 28, 2014
@Ocramius
Copy link
Member

Handled in #6283

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants