Run Rector on your code to see what it can do for you:
<?php final class DemoFile { - private Bar $foo; - - public function __construct(?Bar $foo = null) { - $this->foo = $foo ?? new Bar(); - } + public function __construct(private readonly ?Bar $foo = new Bar()) + { + } public function work(): string {
Applied Rules:
Not a change you expect?
rector.php