Skip to content

Commit

Permalink
Enhancement: Add rector config file for easy migration
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark committed Dec 5, 2022
1 parent 504778e commit c826a9a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Expand Up @@ -57,6 +57,37 @@ for ($i = 0; $i < 3; $i++) {
// 'Orlo Bergstrom'
```

## Automated refactoring

If you already used this library with its properties, they are now deprecated and needs to be replaced by their corresponding methods.

You can use the provided [Rector](https://github.com/rectorphp/rector) config file to automate the work.

Run

```bash
$ composer require --dev rector/rector
```

to install `rector/rector`.

Run

```bash
vendor/bin/rector process src/ --config vendor/fakerphp/faker/rector-migrate.php
```

to run `rector/rector`.

*Note:* do not forget to replace "src/" with the path to your source directory.

Another way is to use it in your `rector.php` file:

```php
$faker = require 'vendor/fakerphp/faker/rector-migrate.php';
$faker($rectorConfig);
```

## License

Faker is released under the MIT License. See [`LICENSE`](LICENSE) for details.
Expand Down
41 changes: 41 additions & 0 deletions rector-migrate.php
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;

// This file configures rector/rector to replace all deprecated property usages with their equivalent functions.
return static function (RectorConfig $rectorConfig): void {
$properties = [
'boolean',
'city',
'dateTime',
'dateTimeThisYear',
'email',
'firstName',
'lastName',
'firstNameFemale',
'name',
'password',
'phoneNumber',
'sentence',
'sha256',
'slug',
'text',
'url',
'word',
'words',
];

$methodCalls = [];
foreach ($properties as $property) {
$methodCalls[] = new PropertyFetchToMethodCall(Generator::class, $property, $property);
}

$rectorConfig->ruleWithConfiguration(
PropertyFetchToMethodCallRector::class,
$methodCalls
);
};

0 comments on commit c826a9a

Please sign in to comment.