Inline comment of constant lost
SyuTingSong opened this issue · comments
Version: 4.0.6
Bug Description
The inline comment declared begin with //
besides constants get lost after fromCode
and printFile
Steps To Reproduce
$file = \Nette\PhpGenerator\PhpFile::fromCode(<<<'PHP'
<?php
class A {
public const HELLO = 'hello'; // some comment
public function say(string $to): string {
// just combine hello and $to
return static::HELLO . ' ' . $to;
}
}
PHP
);
echo (new \Nette\PhpGenerator\PsrPrinter())->printFile($file);
Actual Result
<?php
class A
{
public const HELLO = 'hello';
public function say(string $to): string
{
// just combine hello and $to
return static::HELLO . ' ' . $to;
}
}
Expected Behavior
Keep the inline comment as well.
<?php
class A
{
public const HELLO = 'hello'; // some comment
public function say(string $to): string
{
// just combine hello and $to
return static::HELLO . ' ' . $to;
}
}
Single line comments (outside of method bodies) are ignored because they cannot be added using the API. I will add it to the documentation.