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

PropertyGenerator::setDefaultValue incorrectly handles ValueGenerator instances #97

Open
adamlundrigan opened this issue Oct 2, 2016 · 1 comment
Labels

Comments

@adamlundrigan
Copy link
Contributor

Related to #96, PropertyGenerator behaves incorrectly when the default value passed into it is a ValueGenerator instead of a PropertyValueGenerator.

Example (lifted from #96):

<?php
<<<CONFIG
packages:
    - "zendframework/zend-code: ^3.0"
CONFIG;

$classGenerator    = new \Zend\Code\Generator\ClassGenerator();
$propertyGenerator = new \Zend\Code\Generator\PropertyGenerator();
$value             = new \Zend\Code\Generator\ValueGenerator();
$value->setValue('DefaultString');
$value->setType(\Zend\Code\Generator\ValueGenerator::TYPE_STRING);
$propertyGenerator->setName("foo");
$propertyGenerator->setDefaultValue($value->generate());

$classGenerator->addPropertyFromGenerator($propertyGenerator);

print $classGenerator->generate();

Will print this:

class 
{

    public $foo = '\'DefaultString\'';


}

PropertyGenerator::setDefaultValue wraps everything that isn't a PropertyValueGenerator instance in a new instance of that class. IMO setDefaultValue should not accept ValueGenerator instances or at least convert to a PropertyValueGenerator, vs composing one into the other as is presently the case. This change does break BC, however.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-code; a new issue has been opened at laminas/laminas-code#16.

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

No branches or pull requests

2 participants