Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline comment of constant lost #129

Closed
SyuTingSong opened this issue Mar 23, 2023 · 1 comment
Closed

Inline comment of constant lost #129

SyuTingSong opened this issue Mar 23, 2023 · 1 comment

Comments

@SyuTingSong
Copy link

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;
    }
}
@dg
Copy link
Member

dg commented Mar 23, 2023

Single line comments (outside of method bodies) are ignored because they cannot be added using the API. I will add it to the documentation.

@dg dg closed this as completed in 34aaf23 Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants