|
10 | 10 | use PHPStan\Rules\Properties\PropertyReflectionFinder;
|
11 | 11 | use PHPStan\Type\NeverType;
|
12 | 12 | use PHPStan\Type\Type;
|
13 |
| -use PHPStan\Type\TypeCombinator; |
14 | 13 | use PHPStan\Type\VerbosityLevel;
|
15 | 14 | use function is_string;
|
16 | 15 | use function sprintf;
|
@@ -150,16 +149,20 @@ public function check(Expr $expr, Scope $scope, string $operatorDescription, str
|
150 | 149 | && $expr->name instanceof Node\Identifier
|
151 | 150 | && $expr->var instanceof Expr\Variable
|
152 | 151 | && $expr->var->name === 'this'
|
153 |
| - && !TypeCombinator::containsNull($propertyReflection->getNativeType()) |
| 152 | + && $propertyReflection->getNativeType()->isNull()->no() |
154 | 153 | && $scope->hasExpressionType(new PropertyInitializationExpr($propertyReflection->getName()))->yes()
|
155 | 154 | ) {
|
156 |
| - return RuleErrorBuilder::message( |
| 155 | + return $this->generateError( |
| 156 | + $propertyReflection->getNativeType(), |
157 | 157 | sprintf(
|
158 |
| - '%s cannot be null or uninitialized %s.', |
| 158 | + '%s %s', |
159 | 159 | $this->propertyDescriptor->describeProperty($propertyReflection, $scope, $expr),
|
160 | 160 | $operatorDescription,
|
161 | 161 | ),
|
162 |
| - )->identifier(sprintf('%s.neverNullOrUninitialized', $identifier))->build(); |
| 162 | + $typeMessageCallback, |
| 163 | + $identifier, |
| 164 | + 'propertyNeverNullOrUninitialized', |
| 165 | + ); |
163 | 166 | }
|
164 | 167 |
|
165 | 168 | if (!$scope->hasExpressionType($expr)->yes()) {
|
@@ -299,7 +302,7 @@ private function checkUndefined(Expr $expr, Scope $scope, string $operatorDescri
|
299 | 302 | /**
|
300 | 303 | * @param callable(Type): ?string $typeMessageCallback
|
301 | 304 | * @param ErrorIdentifier $identifier
|
302 |
| - * @param 'variable'|'offset'|'property'|'expr' $identifierSecondPart |
| 305 | + * @param 'variable'|'offset'|'property'|'expr'|'propertyNeverNullOrUninitialized' $identifierSecondPart |
303 | 306 | */
|
304 | 307 | private function generateError(Type $type, string $message, callable $typeMessageCallback, string $identifier, string $identifierSecondPart): ?IdentifierRuleError
|
305 | 308 | {
|
|
0 commit comments