nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.

Home Page:https://doc.nette.org/php-generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

MaximilianSpeer opened this issue · comments

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.