88
99final class Constraint extends BasePHPVisitor implements NodeVisitor
1010{
11+ const VALIDATORS_DOMAIN = 'validators ' ;
12+
1113 const CONSTRAINT_CLASS_NAMES = [
1214 'AbstractComparison ' ,
1315 'All ' ,
@@ -99,12 +101,17 @@ public function enterNode(Node $node): ?Node
99101
100102 $ parts = $ className ->parts ;
101103 $ isConstraintClass = false ;
104+
105+ // we need to check every part since `Assert\NotBlank` would be split in 2 different pieces
102106 foreach ($ parts as $ part ) {
103107 if (\in_array ($ part , self ::CONSTRAINT_CLASS_NAMES )) {
104108 $ isConstraintClass = true ;
109+
110+ break ;
105111 }
106112 }
107113
114+ // unsupported class
108115 if (!$ isConstraintClass ) {
109116 return null ;
110117 }
@@ -132,7 +139,9 @@ public function enterNode(Node $node): ?Node
132139 continue ;
133140 }
134141
135- if ('message ' !== $ item ->key ->value ) {
142+ // there could be false positives but it should catch most of the useful properties
143+ // (e.g. `message`, `minMessage`)
144+ if (false === stripos ($ item ->key ->value , 'message ' )) {
136145 continue ;
137146 }
138147
@@ -149,7 +158,9 @@ public function enterNode(Node $node): ?Node
149158 }
150159
151160 if (!empty ($ message ) && null !== $ messageNode ) {
152- $ this ->addLocation ($ message , $ messageNode ->getAttribute ('startLine ' ), $ messageNode , ['domain ' => 'validators ' ]);
161+ $ this ->addLocation ($ message , $ messageNode ->getAttribute ('startLine ' ), $ messageNode , [
162+ 'domain ' => self ::VALIDATORS_DOMAIN ,
163+ ]);
153164 }
154165
155166 return null ;
0 commit comments