77use PHPStan \Node \ClassPropertyNode ;
88use PHPStan \Reflection \ReflectionProvider ;
99use PHPStan \Rules \Rule ;
10+ use PHPStan \Rules \RuleErrorBuilder ;
1011use PHPStan \Type \ArrayType ;
1112use PHPStan \Type \Doctrine \DescriptorNotRegisteredException ;
1213use PHPStan \Type \Doctrine \DescriptorRegistry ;
@@ -100,12 +101,14 @@ public function processNode(Node $node, Scope $scope): array
100101 try {
101102 $ descriptor = $ this ->descriptorRegistry ->get ($ fieldMapping ['type ' ]);
102103 } 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+ ] : [];
109112 }
110113
111114 $ writableToPropertyType = $ descriptor ->getWritableToPropertyType ();
@@ -118,14 +121,14 @@ public function processNode(Node $node, Scope $scope): array
118121 $ backedEnumType = $ enumReflection ->getBackedEnumType ();
119122 if ($ backedEnumType !== null ) {
120123 if (!$ backedEnumType ->equals ($ writableToDatabaseType ) || !$ backedEnumType ->equals ($ writableToPropertyType )) {
121- $ errors [] = sprintf (
124+ $ errors [] = RuleErrorBuilder:: message ( sprintf (
122125 'Property %s::$%s type mapping mismatch: backing type %s of enum %s does not match database type %s. ' ,
123126 $ className ,
124127 $ propertyName ,
125128 $ backedEnumType ->describe (VerbosityLevel::typeOnly ()),
126129 $ enumReflection ->getDisplayName (),
127130 $ writableToDatabaseType ->describe (VerbosityLevel::typeOnly ())
128- );
131+ ))-> build () ;
129132 }
130133 }
131134 }
@@ -170,13 +173,13 @@ public function processNode(Node $node, Scope $scope): array
170173 }) : $ propertyType ;
171174
172175 if (!$ propertyTransformedType ->isSuperTypeOf ($ writableToPropertyType )->yes ()) {
173- $ errors [] = sprintf (
176+ $ errors [] = RuleErrorBuilder:: message ( sprintf (
174177 'Property %s::$%s type mapping mismatch: database can contain %s but property expects %s. ' ,
175178 $ className ,
176179 $ propertyName ,
177180 $ writableToPropertyType ->describe (VerbosityLevel::getRecommendedLevelByType ($ propertyTransformedType , $ writableToPropertyType )),
178181 $ propertyType ->describe (VerbosityLevel::getRecommendedLevelByType ($ propertyTransformedType , $ writableToPropertyType ))
179- );
182+ ))-> build () ;
180183 }
181184
182185 if (
@@ -186,13 +189,13 @@ public function processNode(Node $node, Scope $scope): array
186189 : $ propertyType
187190 )->yes ()
188191 ) {
189- $ errors [] = sprintf (
192+ $ errors [] = RuleErrorBuilder:: message ( sprintf (
190193 'Property %s::$%s type mapping mismatch: property can contain %s but database expects %s. ' ,
191194 $ className ,
192195 $ propertyName ,
193196 $ propertyTransformedType ->describe (VerbosityLevel::getRecommendedLevelByType ($ writableToDatabaseType , $ propertyType )),
194197 $ writableToDatabaseType ->describe (VerbosityLevel::getRecommendedLevelByType ($ writableToDatabaseType , $ propertyType ))
195- );
198+ ))-> build () ;
196199 }
197200 return $ errors ;
198201 }
0 commit comments