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

When a file is loaded from existing PHP code, any readonly keyword in a promoted parameter is ignored #110

Closed Coffelius closed 2 years ago

Coffelius commented 2 years ago

Version: 4.0.1

Bug Description

The readonly keyword in a promoted parameter is not taken into account by the extractor.

Steps To Reproduce

This piece of code:

$file = PhpFile::fromCode(<<<XX
    <?php
    class Test {
        public function __construct(private readonly string \$foo)
        {
        }
    }
    XX);
$printer = new PsrPrinter();
echo $printer->printFile($file);

Prints:

<?php

class Test
{
    public function __construct(private string $foo)
    {
    }
}

The readonly keyword disappeared.

Expected Behavior

The expected result is:

<?php

class Test
{
    public function __construct(private readonly string $foo)
    {
    }
}

The readonly keyword has been passed thru the extractor as expected.

Possible Solution

I have ready a solution in a PR