Skip to content

Commit eb0c034

Browse files
authored
Handle Doctrine constraints in ConstraintOptionsToNamedArgumentsRector (#882)
* handle Doctrine constraints in ConstraintOptionsToNamedArgumentsRector * rename fixture test class
1 parent 40e67e0 commit eb0c034

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\ConstraintOptionsToNamedArgumentsRector\Fixture;
4+
5+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
6+
7+
final class UniqueEntityDoctrineBridge
8+
{
9+
public function __construct()
10+
{
11+
new UniqueEntity(['fields' => 'email', 'message' => 'Duplicate email.']);
12+
}
13+
}
14+
?>
15+
-----
16+
<?php
17+
18+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\ConstraintOptionsToNamedArgumentsRector\Fixture;
19+
20+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
21+
22+
final class UniqueEntityDoctrineBridge
23+
{
24+
public function __construct()
25+
{
26+
new UniqueEntity(fields: 'email', message: 'Duplicate email.');
27+
}
28+
}
29+
?>

rules/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public function refactor(Node $node): ?Node
7575
return null;
7676
}
7777

78-
if (! str_starts_with($className, 'Symfony\Component\Validator\Constraints\\')) {
78+
if (
79+
! str_starts_with($className, 'Symfony\Component\Validator\Constraints\\')
80+
&& ! str_starts_with($className, 'Symfony\Bridge\Doctrine\Validator\Constraints\\')
81+
) {
7982
return null;
8083
}
8184

0 commit comments

Comments
 (0)