Skip to content

Commit

Permalink
CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienRAVIA committed Jan 8, 2024
1 parent 6d64b9f commit c799fed
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Changed

Go see the [migration guide](MIGRATION-1.0.md) to see how to migrate from v0 to v1

- [BREAKING] Drop annotations support, replace by PHP8 attributes [#124](https://github.com/mapado/rest-client-sdk/pull/124) by [@JulienRAVIA](https://github.com/JulienRAVIA)
- [BREAKING] Remove support of PHP < 8.1 and Symfony < 4.0 [#121](https://github.com/mapado/rest-client-sdk/pull/121) by [@jdeniau](https://github.com/jdeniau)
- Migrate unit tests from atoum to phpunit [#123](https://github.com/mapado/rest-client-sdk/pull/123) by [@jdeniau](https://github.com/jdeniau)
Expand Down
54 changes: 51 additions & 3 deletions MIGRATION-1.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
## How to migrate from v0 to v1

### Attributes
### Using rector

- Search and replace all occurences of `Mapado\RestClientSdk\Mapping\Annotations` to `Mapado\RestClientSdk\Mapping\Attributes`
- Replace annotations by attributes using a tool like [rector/rector](https://github.com/rectorphp/rector) or manually
The followings rector line configs

1. Install `rector/rector` if not already done (init file by launching `vendor/bin/rector process`) : [see how to install](https://getrector.com/documentation)
2. Edit your `rector.php` file by adding this :
```php
$rectorConfig->ruleWithConfiguration(\Rector\Php80\Rector\Class_\AnnotationToAttributeRector::class, [
new \Rector\Php80\ValueObject\AnnotationToAttribute('Mapado\\RestClientSdk\\Mapping\\Annotations\\Id', 'Mapado\\RestClientSdk\\Mapping\\Attributes\\Id'),
new \Rector\Php80\ValueObject\AnnotationToAttribute('Mapado\\RestClientSdk\\Mapping\\Annotations\\Entity', 'Mapado\\RestClientSdk\\Mapping\\Attributes\\Entity'),
new \Rector\Php80\ValueObject\AnnotationToAttribute('Mapado\\RestClientSdk\\Mapping\\Annotations\\Attribute', 'Mapado\\RestClientSdk\\Mapping\\Attributes\\Attribute'),
new \Rector\Php80\ValueObject\AnnotationToAttribute('Mapado\\RestClientSdk\\Mapping\\Annotations\\ManyToOne', 'Mapado\\RestClientSdk\\Mapping\\Attributes\\ManyToOne'),
new \Rector\Php80\ValueObject\AnnotationToAttribute('Mapado\\RestClientSdk\\Mapping\\Annotations\\OneToMany', 'Mapado\\RestClientSdk\\Mapping\\Attributes\\OneToMany'),
]);

$rectorConfig->rule(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class);

$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
```
3. Launch `vendor/bin/rector`

### Manually

1. Replace namespace
```diff
- use Mapado\RestClientSdk\Mapping\Annotations as Rest;
+ use Mapado\RestClientSdk\Mapping\Attributes as Rest;
```

2. Replace annotations by attributes

Example :
```diff
- /**
- * @Rest\Attribute(name="id", type="string")
- /
+ #[Rest\Attribute(name: 'id', type: 'string')]
private $var;
```

3. Replace repositories class name in `Entity` attribute by class constants

```diff
+ use Mapado\Component\TicketingModel\Model\Repository\ProductRepository;

- #[Rest\Entity(key: 'products', repository:' Mapado\Component\TicketingModel\Model\Repository\ProductRepository')]
+ #[Rest\Entity(key: 'users', repository: ProductRepository::class)]
class Product {

}
```
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ You just have to implements your model and a little configuration and it will hi
composer require mapado/rest-client-sdk
```

## Migration from v0 to v1

Go see the [migration guide](MIGRATION-1.0.md) to see how to migrate from v0 to v1

## Usage

Imagine you have those API endpoints:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"prettier": "^1.18.2"
},
"scripts": {
"stan": "vendor/bin/phpstan analyse src/ -c phpstan.neon",
"phpstan": "vendor/bin/phpstan analyse src/ -c phpstan.neon",
"phpunit": "vendor/bin/phpunit"
},
"husky": {
Expand Down

0 comments on commit c799fed

Please sign in to comment.