Find the best Rector rule to solve your problem


Configurable

NestedAnnotationToAttributeRector

Changed nested annotations to attributes

 use Doctrine\ORM\Mapping as ORM;

 class SomeEntity
 {
-    /**
-     * @ORM\JoinTable(name="join_table_name",
-     *     joinColumns={@ORM\JoinColumn(name="origin_id")},
-     *     inverseJoinColumns={@ORM\JoinColumn(name="target_id")}
-     * )
-     */
+    #[ORM\JoinTable(name: 'join_table_name')]
+    #[ORM\JoinColumn(name: 'origin_id')]
+    #[ORM\InverseJoinColumn(name: 'target_id')]
     private $collection;
 }

Configurable

AutowireAttributeRector

Change explicit configuration parameter pass into #[Autowire] attributes

+use Symfony\Component\DependencyInjection\Attribute\Autowire;
+
 final class SomeClass
 {
     public function __construct(
+        #[Autowire(param: 'timeout')]
         private int $timeout,
+        #[Autowire(env: 'APP_SECRET')]
         private string $secret,
     )  {
     }
 }

ParameterBagToAutowireAttributeRector

Change explicit configuration parameter pass into #[Autowire] attributes

-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
+use Symfony\Component\DependencyInjection\Attribute\Autowire;

 final class CertificateFactory
 {
     private ?string $certName;

     public function __construct(
-        ParameterBagInterface $parameterBag
+        #[Autowire(param: 'certificate_name')]
+        $certName,
     ) {
-        $this->certName = $parameterBag->get('certificate_name');
+        $this->certName = $certName;
     }
 }

Configurable

TypedPropertyFromToOneRelationTypeRector

Complete @var annotations or types based on @ORM\*toOne annotations or attributes

 use Doctrine\ORM\Mapping as ORM;

 class SimpleColumn
 {
     /**
      * @ORM\OneToOne(targetEntity="App\Company\Entity\Company")
      * @ORM\JoinColumn(nullable=false)
      */
-    private $company;
+    private ?\App\Company\Entity\Company $company = null;
 }
SETS:  Code Quality

TypedPropertyFromToManyRelationTypeRector

Complete @var annotations or types based on @ORM\*toMany annotations or attributes

 use Doctrine\ORM\Mapping as ORM;

 class SimpleColumn
 {
     /**
      * @ORM\OneToMany(targetEntity="App\Product")
+     * @var \Doctrine\Common\Collections\Collection<int, \App\Product>
      */
-    private $products;
+    private \Doctrine\Common\Collections\Collection $products;
 }

MigrateToSimplifiedAttributeRector

Migrate to the new Model attributes syntax

 use Illuminate\Database\Eloquent\Model;

 class User extends Model
 {
-    public function getFirstNameAttribute($value)
+    protected function firstName(): \Illuminate\Database\Eloquent\Casts\Attribute
     {
-        return ucfirst($value);
-    }
-
-    public function setFirstNameAttribute($value)
-    {
-        $this->attributes['first_name'] = strtolower($value);
-        $this->attributes['first_name_upper'] = strtoupper($value);
+        return \Illuminate\Database\Eloquent\Casts\Attribute::make(get: function ($value) {
+            return ucfirst($value);
+        }, set: function ($value) {
+            return ['first_name' => strtolower($value), 'first_name_upper' => strtoupper($value)];
+        });
     }
 }