Find the best Rector rule to solve your problem
Change annotations with value to attribute
use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\Ticket;
-/**
- * @ticket 123
- */
+#[Ticket('123')]
final class SomeTest extends TestCase
{
}
Change covers annotations with value to attribute
use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\CoversFunction;
-/**
- * @covers SomeClass
- */
+#[CoversClass(SomeClass::class)]
+#[CoversFunction('someFunction')]
final class SomeTest extends TestCase
{
- /**
- * @covers ::someFunction()
- */
public function test()
{
}
}
Change annotations with value to attribute
use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\BackupGlobals;
-/**
- * @backupGlobals enabled
- */
+#[BackupGlobals(true)]
final class SomeTest extends TestCase
{
}
Change depends annotations with value to attribute
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function testOne() {}
- /**
- * @depends testOne
- */
+ #[\PHPUnit\Framework\Attributes\Depends('testOne')]
public function testThree(): void
{
}
}
Change @testWith() annotation to #[TestWith] attribute
use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\TestWith;
final class SomeFixture extends TestCase
{
- /**
- * @testWith ["foo"]
- * ["bar"]
- */
+ #[TestWith(['foo'])]
+ #[TestWith(['bar'])]
public function test(): void
{
}
}
Change dataProvider annotations to attribute
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
- /**
- * @dataProvider someMethod()
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('someMethod')]
public function test(): void
{
}
}
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;
}