7
7
use PHPStan \Node \ClassPropertyNode ;
8
8
use PHPStan \Reflection \ReflectionProvider ;
9
9
use PHPStan \Rules \Rule ;
10
+ use PHPStan \Rules \RuleErrorBuilder ;
10
11
use PHPStan \Type \ArrayType ;
11
12
use PHPStan \Type \Doctrine \DescriptorNotRegisteredException ;
12
13
use PHPStan \Type \Doctrine \DescriptorRegistry ;
@@ -100,12 +101,14 @@ public function processNode(Node $node, Scope $scope): array
100
101
try {
101
102
$ descriptor = $ this ->descriptorRegistry ->get ($ fieldMapping ['type ' ]);
102
103
} catch (DescriptorNotRegisteredException $ e ) {
103
- return $ this ->reportUnknownTypes ? [sprintf (
104
- 'Property %s::$%s: Doctrine type "%s" does not have any registered descriptor. ' ,
105
- $ className ,
106
- $ propertyName ,
107
- $ fieldMapping ['type ' ]
108
- )] : [];
104
+ return $ this ->reportUnknownTypes ? [
105
+ RuleErrorBuilder::message (sprintf (
106
+ 'Property %s::$%s: Doctrine type "%s" does not have any registered descriptor. ' ,
107
+ $ className ,
108
+ $ propertyName ,
109
+ $ fieldMapping ['type ' ]
110
+ ))->build (),
111
+ ] : [];
109
112
}
110
113
111
114
$ writableToPropertyType = $ descriptor ->getWritableToPropertyType ();
@@ -118,14 +121,14 @@ public function processNode(Node $node, Scope $scope): array
118
121
$ backedEnumType = $ enumReflection ->getBackedEnumType ();
119
122
if ($ backedEnumType !== null ) {
120
123
if (!$ backedEnumType ->equals ($ writableToDatabaseType ) || !$ backedEnumType ->equals ($ writableToPropertyType )) {
121
- $ errors [] = sprintf (
124
+ $ errors [] = RuleErrorBuilder:: message ( sprintf (
122
125
'Property %s::$%s type mapping mismatch: backing type %s of enum %s does not match database type %s. ' ,
123
126
$ className ,
124
127
$ propertyName ,
125
128
$ backedEnumType ->describe (VerbosityLevel::typeOnly ()),
126
129
$ enumReflection ->getDisplayName (),
127
130
$ writableToDatabaseType ->describe (VerbosityLevel::typeOnly ())
128
- );
131
+ ))-> build () ;
129
132
}
130
133
}
131
134
}
@@ -170,13 +173,13 @@ public function processNode(Node $node, Scope $scope): array
170
173
}) : $ propertyType ;
171
174
172
175
if (!$ propertyTransformedType ->isSuperTypeOf ($ writableToPropertyType )->yes ()) {
173
- $ errors [] = sprintf (
176
+ $ errors [] = RuleErrorBuilder:: message ( sprintf (
174
177
'Property %s::$%s type mapping mismatch: database can contain %s but property expects %s. ' ,
175
178
$ className ,
176
179
$ propertyName ,
177
180
$ writableToPropertyType ->describe (VerbosityLevel::getRecommendedLevelByType ($ propertyTransformedType , $ writableToPropertyType )),
178
181
$ propertyType ->describe (VerbosityLevel::getRecommendedLevelByType ($ propertyTransformedType , $ writableToPropertyType ))
179
- );
182
+ ))-> build () ;
180
183
}
181
184
182
185
if (
@@ -186,13 +189,13 @@ public function processNode(Node $node, Scope $scope): array
186
189
: $ propertyType
187
190
)->yes ()
188
191
) {
189
- $ errors [] = sprintf (
192
+ $ errors [] = RuleErrorBuilder:: message ( sprintf (
190
193
'Property %s::$%s type mapping mismatch: property can contain %s but database expects %s. ' ,
191
194
$ className ,
192
195
$ propertyName ,
193
196
$ propertyTransformedType ->describe (VerbosityLevel::getRecommendedLevelByType ($ writableToDatabaseType , $ propertyType )),
194
197
$ writableToDatabaseType ->describe (VerbosityLevel::getRecommendedLevelByType ($ writableToDatabaseType , $ propertyType ))
195
- );
198
+ ))-> build () ;
196
199
}
197
200
return $ errors ;
198
201
}
0 commit comments