Find a Rector rule

Find the best Rector rule to solve your problem. Searching through 1011 rules.

Found 8 rules, grouped by set: Clear

Type Declarations 1 match

Add return type to classes that extend Doctrine\ORM\EntityRepository based on return Doctrine method names

 use Doctrine\ORM\EntityRepository;

 /**
  * @extends EntityRepository<SomeType>
  */
 final class SomeRepository extends EntityRepository
 {
-    public function getActiveItem()
+    public function getActiveItem(): ?SomeType
     {
         return $this->findOneBy([
             'something'
         ]);
     }
 }
Not in a set 3 matches

Replaces string sort directions with \SortDirection enum in Doctrine #[ORM\OrderBy] Attributes

 use Doctrine\ORM\Mapping as ORM;

 class SomeClass
 {
-    #[ORM\OrderBy(['createdAt' => 'ASC'])]
+    #[ORM\OrderBy(['createdAt' => \SortDirection::Ascending])]
     protected $messages;
 }

Replaces string sort directions with \SortDirection enum in Doctrine QueryBuilder

-$queryBuilder->orderBy('e.id', 'ASC');
-$queryBuilder->addOrderBy('e.name', 'desc');
+$queryBuilder->orderBy('e.id', \SortDirection::Ascending);
+$queryBuilder->addOrderBy('e.name', \SortDirection::Descending);

Add type to property by added rules, mostly public/property by parent type

 class SomeClass extends ParentClass
 {
-    public $name;
+    public string $name;
 }
doctrine/orm 1 match

Casts Doctrine Expr\x to string where necessary.

 $statements->add(
     $builder->expr()->like(
-        $builder->expr()->lower($column),
-        $builder->expr()->lower($builder->expr()->literal('%'.$like.'%'))
+        (string) $builder->expr()->lower($column),
+        (string) $builder->expr()->lower($builder->expr()->literal('%'.$like.'%'))
     )
 );
symfony/framework-bundle 1 match
EnableValidationAttributesRector symfony/framework-bundle >=6.4

Enable "framework.validation.enable_attributes" config, to load validation rules from attributes

 $container->loadFromExtension('framework', [
     'validation' => [
-        'enable_attributes' => false,
+        'enable_attributes' => true,
     ],
 ]);
doctrine/dbal 1 match

Change $platform->getName() === "postgresql" to $platform instanceof PostgreSQLPlatform, following the DBAL 3.2 deprecation of AbstractPlatform::getName(), see https://github.com/doctrine/dbal/pull/4755

-if ('postgresql' === $this->platform->getName()) {}
+if ($this->platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform) {}
Code Quality 1 match

Convert string validation rules into arrays for Laravel's Validator.

 Validator::make($data, [
-    'field' => 'required|nullable|string|max:255',
+    'field' => ['required', 'nullable', 'string', 'max:255'],
 ]);