Find the best Rector rule to solve your problem. Searching through 669 rules.
Found 6 rules:
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'
]);
}
}
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.'%'))
)
);
Improve @var, @param and @return types for Doctrine collections to make them useful both for PHPStan and PHPStorm
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class SomeClass
{
/**
* @ORM\OneToMany(targetEntity=Trainer::class, mappedBy="trainer")
- * @var Collection|Trainer[]
+ * @var Collection<int, Trainer>
*/
private $trainings = [];
+ /**
+ * @param Collection<int, Trainer> $trainings
+ */
public function setTrainings($trainings)
{
$this->trainings = $trainings;
}
}
Converts YAML Doctrine Entity mapping to particular annotation mapping
+use Doctrine\ORM\Mapping as ORM;
+
+#[ORM\Entity]
class SomeEntity
{
+ #[ORM\Id]
+ #[ORM\GeneratedValue]
+ #[ORM\Column(type: 'integer')]
private $id;
+ #[ORM\Column(type: 'string')]
private $name;
}
Add type to property by added rules, mostly public/property by parent type
class SomeClass extends ParentClass
{
- public $name;
+ public string $name;
}
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'],
]);