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

Attributes are not loaded correctly #98

Closed alanpoulain closed 2 years ago

alanpoulain commented 2 years ago

Version: 3.6.4

Bug Description

When loading from the code (PhpFile::fromCode($content)), attribute arguments are not loaded as expected: arguments are "duplicated". For instance, with this attribute:

#[AnAttribute(foo: 'bar')]

The loaded arguments will be:

$args = ['foo' => new Literal("foo: 'bar'")];

Expected Behavior

The loaded arguments should be:

$args = ['foo' => new Literal("'bar'")];

Possible Solution

The issue comes from the call to getReformattedContents which gets everything inside the attribute as raw. It shouldn't be the case when loading content.

alanpoulain commented 2 years ago

Thanks!

dg commented 2 years ago

You're welcome