-
-
Notifications
You must be signed in to change notification settings - Fork 724
Closed
rectorphp/rector-src
#6895Labels
Description
Bug Report
Subject | Details |
---|---|
Rector version | last dev-main |
Installed as | composer dependency |
Minimal PHP Code Causing Issue
From PHP PoV these two classes are equal - both have a public property name
(https://3v4l.org/lcTgW). But rector thinks that public function __construct(readonly string $name) { }
it is not a constructor with a promoted property, but with a regular parameter.
See https://getrector.com/demo/7f5423c8-123a-4ca0-b2c4-88c3e90ae2c7
<?php
final class SomeClassFoo
{
public function __construct(public readonly string $name) { }
}
final class SomeClassBar
{
public function __construct(readonly string $name) { }
}
$a = new SomeClassFoo('foo');
$b = new SomeClassBar('bar');
var_dump($a, $b);
Responsible rules
-
RemoveEmptyClassMethodRector
-
RemoveUnusedConstructorParamRector
-
ReadOnlyClassRector
Expected Behavior
<?php
-final class SomeClassFoo
+final readonly class SomeClassFoo
{
- public function __construct(public readonly string $name) { }
+ public function __construct(public string $name) { }
}
-final class SomeClassBar
-{
- public function __construct(readonly string $name) { }
+final readonly class SomeClassBar
+{
+ public function __construct(string $name) { }
}
$a = new SomeClassFoo('foo');
$b = new SomeClassBar('bar');
var_dump($a, $b);