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

First comment in Method is ignored when using PhpFile::fromCode() #119

Closed MaximilianSpeer closed 2 years ago

MaximilianSpeer commented 2 years ago

Version: 3.6.7

Bug Description

The PhpParser ignores a comment if it's in the first line of a method. This occurses when using PhpFile::fromCode()

Steps To Reproduce

`$code = "<?php

    class TestClass
    {
        function aFunction()
        {
            // a Comment
            \$foo = 'bar';
            // another Comment
        }
    }";

$file = PhpFile::fromCode($code); $newCode = (string) $file; echo $newCode; return;`

Expected Behavior

The first comment should get extracted from the code and stored in the PhpFile object.