Try Rector
Docs
Hire Team
Find Rule
Blog
Contact
AST
Try Rector
Docs
Hire Team
Find Rule
Blog
Contact
AST
Run Rector on your code to see what it can do for you:
// no change
PHP snippet to change
<?php declare(strict_types=1); namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture; use PDO; class A { public function __construct( private int $id ) { } public function prepare(): void { $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; $dbh = new PDO($dsn, $user, $password); $sth = $dbh->prepare('SELECT * FROM users WHERE id = :id'); if (! $sth instanceof \PDOStatement) { return; } $sth->bindParam('id', $this->id, PDO::PARAM_INT); $sth->execute(); } }
Config
rector.php
<?php use Rector\Config\RectorConfig; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; return RectorConfig::configure() ->withRules([ \Rector\Php81\Rector\Property\ReadOnlyPropertyRector::class ]);
Run Rector
Rector version:
a099fd
- released at 2025-05-27 18:30