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
177 changes: 175 additions & 2 deletions docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 97 Rules Overview
# 106 Rules Overview

## AbortIfRector

Expand Down Expand Up @@ -469,6 +469,25 @@ Avoid negated conditionals in `filter()` by using `reject()`, or vice versa.

<br>

## BackoffPropertyToBackoffAttributeRector

Changes the backoff property to use the Backoff attribute

- class: [`RectorLaravel\Rector\Class_\BackoffPropertyToBackoffAttributeRector`](../src/Rector/Class_/BackoffPropertyToBackoffAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\Backoff;

+#[Backoff(3)]
final class ProcessPodcast implements ShouldQueue
{
- public $backoff = 3;
}
```

<br>

## CallOnAppArrayAccessToStandaloneAssignRector

Replace magical call on `$this->app["something"]` to standalone type assign variable
Expand Down Expand Up @@ -920,6 +939,25 @@ Use the static factory method instead of global factory function.

<br>

## FailOnTimeoutPropertyToFailOnTimeoutAttributeRector

Changes the failOnTimeout property to use the FailOnTimeout attribute

- class: [`RectorLaravel\Rector\Class_\FailOnTimeoutPropertyToFailOnTimeoutAttributeRector`](../src/Rector/Class_/FailOnTimeoutPropertyToFailOnTimeoutAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\FailOnTimeout;

+#[FailOnTimeout(true)]
final class ProcessPodcast implements ShouldQueue
{
- public $failOnTimeout = true;
}
```

<br>

## FillablePropertyToFillableAttributeRector

Changes model fillable property to use the fillable attribute
Expand Down Expand Up @@ -1003,6 +1041,25 @@ Changes model hidden property to use the hidden attribute

<br>

## JobConnectionPropertyToJobConnectionAttributeRector

Changes the connection property to use the Connection attribute on queue jobs

- class: [`RectorLaravel\Rector\Class_\JobConnectionPropertyToJobConnectionAttributeRector`](../src/Rector/Class_/JobConnectionPropertyToJobConnectionAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\Connection;

+#[Connection('redis')]
final class ProcessPodcast implements ShouldQueue
{
- public $connection = 'redis';
}
```

<br>

## JsonCallToExplicitJsonCallRector

Change method calls from `$this->json` to `$this->postJson,` `$this->putJson,` etc.
Expand Down Expand Up @@ -1117,6 +1174,25 @@ Makes Model attributes and scopes protected

<br>

## MaxExceptionsPropertyToMaxExceptionsAttributeRector

Changes the maxExceptions property to use the MaxExceptions attribute

- class: [`RectorLaravel\Rector\Class_\MaxExceptionsPropertyToMaxExceptionsAttributeRector`](../src/Rector/Class_/MaxExceptionsPropertyToMaxExceptionsAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\MaxExceptions;

+#[MaxExceptions(3)]
final class ProcessPodcast implements ShouldQueue
{
- public $maxExceptions = 3;
}
```

<br>

## MigrateToSimplifiedAttributeRector

Migrate to the new Model attributes syntax
Expand Down Expand Up @@ -1262,6 +1338,25 @@ Change deprecated `$defer` = true; to `Illuminate\Contracts\Support\DeferrablePr

<br>

## QueuePropertyToQueueAttributeRector

Changes the queue property to use the Queue attribute

- class: [`RectorLaravel\Rector\Class_\QueuePropertyToQueueAttributeRector`](../src/Rector/Class_/QueuePropertyToQueueAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\Queue;

+#[Queue('podcasts')]
final class ProcessPodcast implements ShouldQueue
{
- public $queue = 'podcasts';
}
```

<br>

## Redirect301ToPermanentRedirectRector

Change "redirect" call with 301 to "permanentRedirect"
Expand Down Expand Up @@ -1498,6 +1593,27 @@ Replace deprecated faker property fetch with method call

<br>

## ReplaceQueueTraitsWithQueueableRector

Replace Dispatchable, InteractsWithQueue, Queueable, and SerializesModels traits with the Queueable trait

- class: [`RectorLaravel\Rector\Class_\ReplaceQueueTraitsWithQueueableRector`](../src/Rector/Class_/ReplaceQueueTraitsWithQueueableRector.php)

```diff
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SomeJob
{
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+ use \Illuminate\Foundation\Queue\Queueable;
}
```

<br>

## ReplaceServiceContainerCallArgRector

Changes the string or class const used for a service container make call
Expand Down Expand Up @@ -1755,7 +1871,7 @@ Changes model table-related properties to use the Table attribute
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Attributes\Table;

+#[Table(table: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
+#[Table(name: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
class User extends Model
{
- protected $table = 'users';
Expand Down Expand Up @@ -1802,6 +1918,25 @@ Change if throw to throw_if

<br>

## TimeoutPropertyToTimeoutAttributeRector

Changes the timeout property to use the Timeout attribute

- class: [`RectorLaravel\Rector\Class_\TimeoutPropertyToTimeoutAttributeRector`](../src/Rector/Class_/TimeoutPropertyToTimeoutAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\Timeout;

+#[Timeout(120)]
final class ProcessPodcast implements ShouldQueue
{
- public $timeout = 120;
}
```

<br>

## TouchesPropertyToTouchesAttributeRector

Changes model touches property to use the touches attribute
Expand All @@ -1823,6 +1958,25 @@ Changes model touches property to use the touches attribute

<br>

## TriesPropertyToTriesAttributeRector

Changes the tries property to use the Tries attribute

- class: [`RectorLaravel\Rector\Class_\TriesPropertyToTriesAttributeRector`](../src/Rector/Class_/TriesPropertyToTriesAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\Tries;

+#[Tries(3)]
final class ProcessPodcast implements ShouldQueue
{
- public $tries = 3;
}
```

<br>

## TypeHintTappableCallRector

Automatically type hints your tappable closures
Expand Down Expand Up @@ -1883,6 +2037,25 @@ Unify Model `$dates` property with `$casts`

<br>

## UniqueForPropertyToUniqueForAttributeRector

Changes the uniqueFor property to use the UniqueFor attribute

- class: [`RectorLaravel\Rector\Class_\UniqueForPropertyToUniqueForAttributeRector`](../src/Rector/Class_/UniqueForPropertyToUniqueForAttributeRector.php)

```diff
use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\UniqueFor;

+#[UniqueFor(1800)]
final class ProcessPodcast implements ShouldQueue
{
- public $uniqueFor = 1800;
}
```

<br>

## UseComponentPropertyWithinCommandsRector

Use `$this->components` property within commands
Expand Down
2 changes: 1 addition & 1 deletion src/NodeFactory/TableAttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public function create(Expr $table, array $options): AttributeGroup
{
$args = [new Arg($table, false, false, [], new Identifier('table'))];
$args = [new Arg($table, false, false, [], new Identifier('name'))];

foreach ($options as $name => $expr) {
$args[] = new Arg($expr, false, false, [], new Identifier($name));
Expand Down
4 changes: 2 additions & 2 deletions src/Rector/Class_/TablePropertyToTableAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class User extends Model
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Attributes\Table;

#[Table(table: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
#[Table(name: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
class User extends Model
{
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function refactor(Node $node): ?Node
}

if (! $tableValue instanceof String_ && $hasExistingAttribute) {
$tableValue = $this->getExistingAttributeArg($node, $tableAttributeClass, 'table');
$tableValue = $this->getExistingAttributeArg($node, $tableAttributeClass, 'name');
if (! $tableValue instanceof String_) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users')]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users')]
class CombineExistingAttribute extends Model
{
protected $primaryKey = 'user_id';
Expand All @@ -18,7 +18,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users', key: 'user_id')]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users', key: 'user_id')]
class CombineExistingAttribute extends Model
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users')]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users')]
class DoNotRemoveInvalidProperties extends Model
{
public $primaryKey = 'user_id';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
class User extends Model
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users')]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users')]
class UserOnlyTable extends Model
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'customers')]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'customers')]
class ReplaceExistingAttribute extends Model
{
protected $table = 'users';
Expand All @@ -20,7 +20,7 @@ namespace RectorLaravel\Tests\Rector\Class_\TablePropertyToTableAttributeRector\

use Illuminate\Database\Eloquent\Model;

#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users', key: 'user_id')]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users', key: 'user_id')]
class ReplaceExistingAttribute extends Model
{
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/Laravel130/Fixture/laravel130.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use Illuminate\Database\Eloquent\Model;
#[\Illuminate\Database\Eloquent\Attributes\Hidden([
'password',
])]
#[\Illuminate\Database\Eloquent\Attributes\Table(table: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
#[\Illuminate\Database\Eloquent\Attributes\Table(name: 'users', key: 'user_id', keyType: 'string', incrementing: false)]
#[\Illuminate\Database\Eloquent\Attributes\Touches([
'posts',
])]
Expand Down
Loading