Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ perex: |

Do you want to know the answer? Rector has a simple solution for you.

updated_at: '2022-04'
updated_at: '2025-03'
updated_message: |
Since **Rector 0.12** a new `RectorConfig` is available with simpler and easier to use config methods.

since_rector: 0.12
Since **Rector 2.0** a new `withAttributesSets()` configuration method is available.
---

One package that added support for attributes is Doctrine:
Expand All @@ -30,23 +28,22 @@ Now, let's go to upgrade itself. It's effortless.

## Upgrade from Annotations to Attributes in 3 Steps

### 1. Configure `rector.php` to include the packages you use:
### 1. Configure `rector.php` to include all available attributes:

```php
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withAttributesSets();
```

Or limit to specific group - this option is better when you're addin Rector to a new project:

```php
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Symfony\Set\SensiolabsSetList;
use Rector\Nette\Set\NetteSetList;
use Rector\Config\RectorConfig;

return function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
NetteSetList::ANNOTATIONS_TO_ATTRIBUTES,
SensiolabsSetList::FRAMEWORK_EXTRA_61,
]);
};
return RectorConfig::configure()
->withAttributesSets(symfony: true);
```

<br>
Expand Down
35 changes: 35 additions & 0 deletions resources/docs/attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Do you want to migrate your annotations to native PHP 8.0 attributes?

```diff
use Doctrine\ORM\Mapping as ORM;

-/**
- * @ORM\Entity
- */
+#[ORM\Entity]
class SomeEntity
{
}
```

Following method will automatically pick up attribute classes present in your `/vendor`, and upgrade annotations to their attribute equivalent:

```php
<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withAttributesSets();
```

**If you're on a legacy project** and want to take it step by step, use named arguments to limit to specific groups:

```php
<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withAttributesSets(symfony: true, doctrine: true);
```
38 changes: 0 additions & 38 deletions resources/docs/set-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,6 @@ return RectorConfig::configure()

That way you can use all the sets that are needed to upgrade your code to the desired PHP version in single line.

## PHP 8.0 Attributes

Do you want to migrate your annotations to native PHP 8.0 attributes?

```diff
use Doctrine\ORM\Mapping as ORM;

-/**
- * @ORM\Entity
- */
+#[ORM\Entity]
class SomeEntity
{
}
```

Following method will automatically pick up attribute classes present in your `/vendor`, and upgrade annotations to their attribute equivalent:

```php
<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withAttributesSets();
```

**If you're on a legacy project** and want to take it step by step, use named arguments to limit to specific groups:

```php
<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withAttributesSets(symfony: true, doctrine: true);
```

## Community or External Sets

How can I use Rector with community sets or my custom one?
Expand Down
1 change: 1 addition & 0 deletions src/Documentation/DocumentationMenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function create(): array
$this->documentationMenuItemFactory->createSection('define-paths', 'Define Paths'),
$this->documentationMenuItemFactory->createSection('set-lists', 'Set Lists'),
$this->documentationMenuItemFactory->createSection('levels', 'Levels', true),
$this->documentationMenuItemFactory->createSection('attributes', 'PHP 8.0 Attributes', true),
$this->documentationMenuItemFactory->createSection('composer-based-sets', 'Composer-Based Sets', true),
$this->documentationMenuItemFactory->createInternalLink(FindRuleController::class, 'Find Rules'),
$this->documentationMenuItemFactory->createSection(
Expand Down