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

Promoted Parameters don't have "readonly" when using Factory #158

Closed
WalterWoshid opened this issue May 10, 2024 · 1 comment
Closed

Promoted Parameters don't have "readonly" when using Factory #158

WalterWoshid opened this issue May 10, 2024 · 1 comment

Comments

@WalterWoshid
Copy link

WalterWoshid commented May 10, 2024

Version: 6.36.0

Bug Description

When using $method = (new Factory)->fromMethodReflection($refMethod); and printing the code with $method->__toString(); the readonly keyword is missing.

Steps To Reproduce

class Number
{
    public function __construct(public readonly int $value) {}
}

$reflectionClass = new \ReflectionClass(Number::class);
$reflectionMethod = $reflectionClass->getMethod('__construct');
$method = (new Factory)->fromMethodReflection($reflectionMethod);
$result = (string)$method;

Expected Behavior

Should include readonly

Possible Solution

Factory::fromParameterReflection():

public function fromParameterReflection(...): Parameter
{
    // ...
    
    if ($from->isPromoted()
        && PHP_VERSION_ID >= 80100
        && ($declaringClass = $from->getDeclaringClass())
        && $declaringClass->hasProperty($from->name)
        && ($property = $declaringClass->getProperty($from->name))
        && $property->isPromoted()
        && !(PHP_VERSION_ID >= 80200 && $from->getDeclaringClass()->isReadOnly())
    ) {
        $param->setReadOnly($property->isReadOnly());
    }

    // ...
}
@WalterWoshid WalterWoshid changed the title Promoted Parameters don't have "readonly" Promoted Parameters don't have "readonly" when using Factory May 11, 2024
@dg dg closed this as completed in a004aff May 12, 2024
@WalterWoshid
Copy link
Author

@dg Thank you!

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

1 participant