|
10 | 10 | use PHPStan\Rules\Rule;
|
11 | 11 | use PHPStan\Rules\RuleErrorBuilder;
|
12 | 12 | use PHPStan\Type\Generic\TemplateType;
|
13 |
| -use PHPStan\Type\ParserNodeTypeToPHPStanType; |
14 | 13 | use PHPStan\Type\VerbosityLevel;
|
15 | 14 | use function array_merge;
|
16 | 15 | use function sprintf;
|
@@ -62,33 +61,35 @@ public function processNode(Node $node, Scope $scope): array
|
62 | 61 | ))->identifier('property.unresolvableType')->build();
|
63 | 62 | }
|
64 | 63 |
|
65 |
| - $nativeType = ParserNodeTypeToPHPStanType::resolve($node->getNativeType(), $classReflection); |
66 |
| - $isSuperType = $nativeType->isSuperTypeOf($phpDocType); |
67 |
| - if ($isSuperType->no()) { |
68 |
| - $messages[] = RuleErrorBuilder::message(sprintf( |
69 |
| - '%s for property %s::$%s with type %s is incompatible with native type %s.', |
70 |
| - $description, |
71 |
| - $classReflection->getDisplayName(), |
72 |
| - $propertyName, |
73 |
| - $phpDocType->describe(VerbosityLevel::typeOnly()), |
74 |
| - $nativeType->describe(VerbosityLevel::typeOnly()), |
75 |
| - ))->identifier('property.phpDocType')->build(); |
76 |
| - |
77 |
| - } elseif ($isSuperType->maybe()) { |
78 |
| - $errorBuilder = RuleErrorBuilder::message(sprintf( |
79 |
| - '%s for property %s::$%s with type %s is not subtype of native type %s.', |
80 |
| - $description, |
81 |
| - $classReflection->getDisplayName(), |
82 |
| - $propertyName, |
83 |
| - $phpDocType->describe(VerbosityLevel::typeOnly()), |
84 |
| - $nativeType->describe(VerbosityLevel::typeOnly()), |
85 |
| - ))->identifier('property.phpDocType'); |
86 |
| - |
87 |
| - if ($phpDocType instanceof TemplateType) { |
88 |
| - $errorBuilder->tip(sprintf('Write @template %s of %s to fix this.', $phpDocType->getName(), $nativeType->describe(VerbosityLevel::typeOnly()))); |
| 64 | + $nativeType = $node->getNativeType(); |
| 65 | + if ($nativeType !== null) { |
| 66 | + $isSuperType = $nativeType->isSuperTypeOf($phpDocType); |
| 67 | + if ($isSuperType->no()) { |
| 68 | + $messages[] = RuleErrorBuilder::message(sprintf( |
| 69 | + '%s for property %s::$%s with type %s is incompatible with native type %s.', |
| 70 | + $description, |
| 71 | + $classReflection->getDisplayName(), |
| 72 | + $propertyName, |
| 73 | + $phpDocType->describe(VerbosityLevel::typeOnly()), |
| 74 | + $nativeType->describe(VerbosityLevel::typeOnly()), |
| 75 | + ))->identifier('property.phpDocType')->build(); |
| 76 | + |
| 77 | + } elseif ($isSuperType->maybe()) { |
| 78 | + $errorBuilder = RuleErrorBuilder::message(sprintf( |
| 79 | + '%s for property %s::$%s with type %s is not subtype of native type %s.', |
| 80 | + $description, |
| 81 | + $classReflection->getDisplayName(), |
| 82 | + $propertyName, |
| 83 | + $phpDocType->describe(VerbosityLevel::typeOnly()), |
| 84 | + $nativeType->describe(VerbosityLevel::typeOnly()), |
| 85 | + ))->identifier('property.phpDocType'); |
| 86 | + |
| 87 | + if ($phpDocType instanceof TemplateType) { |
| 88 | + $errorBuilder->tip(sprintf('Write @template %s of %s to fix this.', $phpDocType->getName(), $nativeType->describe(VerbosityLevel::typeOnly()))); |
| 89 | + } |
| 90 | + |
| 91 | + $messages[] = $errorBuilder->build(); |
89 | 92 | }
|
90 |
| - |
91 |
| - $messages[] = $errorBuilder->build(); |
92 | 93 | }
|
93 | 94 |
|
94 | 95 | $className = SprintfHelper::escapeFormatString($classReflection->getDisplayName());
|
|
0 commit comments