nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

Dumping an array variable does not use the Printer's overridden indentation #41

Closed Jeroeny closed 5 years ago

Jeroeny commented 5 years ago

php version: 7.3.0 nette/php-generator version: 3.2.1

Bug Description

When adding a constant to a class as below

$map = [
    'foo' => 'bar',
    'example' => 'value',
];

$class
    ->addConstant('MAP', $map)
    ->setVisibility(ClassType::VISIBILITY_PROTECTED);

it results in:

    protected const MAP = [
    'foo' => 'bar',
    'example' => 'value',
    ];

When printing with Nette\PhpGenerator\PsrPrinter.

Expected Behavior

The constant printed with PsrPrinter's 4 spaces indentation instead of tabs.

Possible Solution

The tab is hardcoded at https://github.com/nette/php-generator/blob/master/src/PhpGenerator/Helpers.php#L74. Could we change it so that we can pass the indentation to the helper?

zeleznypa commented 5 years ago

I also have this issue.

Jeroeny commented 5 years ago

@zeleznypa I've worked around this with:

Nette\PhpGenerator\Helpers::tabsToSpaces($contents);