Find the best Rector rule to solve your problem. Searching through 728 rules.
Found 6 rules:
Add @extends ServiceEntityRepository
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+/**
+ * @extends ServiceEntityRepository<\SomeEntity>
+ */
final class SomeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SomeEntity::class);
}
}
Change default value types to match Doctrine annotation type
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class User
{
/**
* @ORM\Column(name="is_old", type="boolean")
*/
- private $isOld = '0';
+ private $isOld = false;
}
Complete @var annotations or types based on @ORM\Column
use Doctrine\ORM\Mapping as ORM;
class SimpleColumn
{
/**
* @ORM\Column(type="string")
*/
- private $name;
+ private string|null $name = null;
}
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;
}
Move default value for entity property to constructor, the safest place
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class User
{
/**
* @var DateTimeInterface
*
- * @ORM\Column(type="datetime", nullable=false, options={"default"="now()"})
+ * @ORM\Column(type="datetime", nullable=false)
*/
- private $when = 'now()';
+ private $when;
+
+ public function __construct()
+ {
+ $this->when = new \DateTime();
+ }
}
Remove empty Table attribute on entities because it's useless
<?php
namespace RectorPrefix202507;
use RectorPrefix202507\Doctrine\ORM\Mapping as ORM;
-#[ORM\Table]
#[ORM\Entity]
class Product
{
}
\class_alias('Product', 'Product', \false);