zendframework / zend-code

BSD 3-Clause "New" or "Revised" License
1.68k stars 78 forks source link

ValueGenerator recursive setIndentation #163

Closed hxss closed 6 years ago

hxss commented 6 years ago

On 363 line ValueGenerator creates childs but dont pass to them self indentation. So when I create new ValueGenerator and use setIndentation method I can set only first level childs indentation.

Ocramius commented 6 years ago

Ref:

https://github.com/zendframework/zend-code/blob/4a7f6785ef0567423a4d68d76986673eb297fac4/src/Generator/ValueGenerator.php#L363

Ocramius commented 6 years ago

@hxss you mean that multiline-dumped values are not aligned? Doesn't sound like a big deal to me...

hxss commented 6 years ago

@Ocramius please see this example:

$generator = new Zend\Code\Generator\ValueGenerator([
    'a' => [
        'b' => [
            'c' => 'd',
        ]
    ],
]);
$generator->setIndentation("\t");

echo $generator->generate();

output:

array(
    'a' => array(
        'b' => array(
            'c' => 'd',
        ),
    ),
)

We have 1 tab before 'a' and 4 spaces as indentation on other levels of tree.

Ocramius commented 6 years ago

Yeah, this is not fixable, unless we touch the var_export() output, which we shouldn't do.

This is too much risk (really, it's not that trivial) for a problem in alignment, so I'm going to close it as "won't fix", sorry.

hxss commented 6 years ago

after 363 line need to append $curValue->setIndentation($this->indentation); https://github.com/zendframework/zend-code/blob/4a7f6785ef0567423a4d68d76986673eb297fac4/src/Generator/ValueGenerator.php#L363

hxss commented 6 years ago

@Ocramius in my test $curValue->setIndentation($this->indentation); solve the problem.

Ocramius commented 6 years ago

@hxss send a patch then: re-opening (also: didn't know the value generator could already do that, thanks for checking!)

Ocramius commented 6 years ago

Please remember to add a test case, if yo do

Ocramius commented 6 years ago

Handled in #164