Find the best Rector rule to solve your problem
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;
}
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,
) {
}
}
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;
}
}
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;
}
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;
}
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)];
+ });
}
}