1313use PHPStan \Type \VerbosityLevel ;
1414use function is_string ;
1515use function sprintf ;
16+ use function str_starts_with ;
1617
1718/**
1819 * @phpstan-type ErrorIdentifier = 'empty'|'isset'|'nullCoalesce'
@@ -149,7 +150,6 @@ public function check(Expr $expr, Scope $scope, string $operatorDescription, str
149150 && $ expr ->name instanceof Node \Identifier
150151 && $ expr ->var instanceof Expr \Variable
151152 && $ expr ->var ->name === 'this '
152- && $ propertyReflection ->getNativeType ()->isNull ()->no ()
153153 && $ scope ->hasExpressionType (new PropertyInitializationExpr ($ propertyReflection ->getName ()))->yes ()
154154 ) {
155155 return $ this ->generateError (
@@ -159,9 +159,20 @@ public function check(Expr $expr, Scope $scope, string $operatorDescription, str
159159 $ this ->propertyDescriptor ->describeProperty ($ propertyReflection , $ scope , $ expr ),
160160 $ operatorDescription ,
161161 ),
162- $ typeMessageCallback ,
162+ static function (Type $ type ) use ($ typeMessageCallback ): ?string {
163+ $ originalMessage = $ typeMessageCallback ($ type );
164+ if ($ originalMessage === null ) {
165+ return null ;
166+ }
167+
168+ if (str_starts_with ($ originalMessage , 'is not ' )) {
169+ return sprintf ('%s nor uninitialized ' , $ originalMessage );
170+ }
171+
172+ return sprintf ('%s and initialized ' , $ originalMessage );
173+ },
163174 $ identifier ,
164- 'propertyNeverNullOrUninitialized ' ,
175+ 'initializedProperty ' ,
165176 );
166177 }
167178
@@ -302,7 +313,7 @@ private function checkUndefined(Expr $expr, Scope $scope, string $operatorDescri
302313 /**
303314 * @param callable(Type): ?string $typeMessageCallback
304315 * @param ErrorIdentifier $identifier
305- * @param 'variable'|'offset'|'property'|'expr'|'propertyNeverNullOrUninitialized ' $identifierSecondPart
316+ * @param 'variable'|'offset'|'property'|'expr'|'initializedProperty ' $identifierSecondPart
306317 */
307318 private function generateError (Type $ type , string $ message , callable $ typeMessageCallback , string $ identifier , string $ identifierSecondPart ): ?IdentifierRuleError
308319 {
0 commit comments