Created by Abdul Malik Ikhsan / @samsonasik
Contributor.
RectorPHP Maintainer.
Technical Steering Committee.
Core Team.
Test Framework Maintainer.
Before
function () {
return 1;
};
After
fn() => 1;
Ref https://getrector.com/demo/d7709b87-39d2-4e89-91e3-244ad0139ff5
Before
final class MyTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
$this->setExpectedException('InvalidArgumentException', 'some message');
}
}
After
final class MyTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('some message');
}
}
Ref https://getrector.com/demo/1e8fe256-7985-447b-84bd-3cc5d7b50476
Before
function run($parameter)
{
echo floatval($parameter);
}
After
function run($parameter)
{
echo (float) $parameter;
}
Ref https://getrector.com/demo/46c8a393-e970-4e0d-ac59-fe07d55ee1cf
Before
function run($parameter)
{
return $parameter === 1;
}
After
function run($parameter): bool
{
return $parameter === 1;
}
Ref https://getrector.com/demo/720c19a2-81ae-4a90-93fa-a114494227ce
composer create-project laravel/laravel example-app-laravel
cd example-app-laravel && git init && git add . && git commit -m 'First commit' -a
composer require --dev rector/rector
➜ vendor/bin/rector
No "rector.php" config found. Should we generate it for you? [yes]:
> yes
[OK] The config is added now. Re-run command to make Rector do the work!
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/app',
__DIR__ . '/bootstrap',
__DIR__ . '/config',
__DIR__ . '/public',
__DIR__ . '/resources',
__DIR__ . '/routes',
__DIR__ . '/tests',
]);
// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
// define sets of rules
// $rectorConfig->sets([
// LevelSetList::UP_TO_PHP_81
// ]);
};
// rector.php
$rectorConfig->bootstrapFiles([__DIR__ . '/bootstrap/app.php']);
// rector.php
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81
]);
// rector.php
$rectorConfig->skip([
__DIR__ . '/bootstrap/cache',
]);