|
3 | 3 | namespace PHPStan\Rules\Generics; |
4 | 4 |
|
5 | 5 | use PHPStan\Reflection\ParametersAcceptorWithPhpDocs; |
6 | | -use PHPStan\Reflection\PropertyReflection; |
| 6 | +use PHPStan\Reflection\Php\PhpPropertyReflection; |
7 | 7 | use PHPStan\Rules\RuleError; |
8 | 8 | use PHPStan\Rules\RuleErrorBuilder; |
9 | 9 | use PHPStan\Type\Generic\TemplateType; |
@@ -90,37 +90,17 @@ public function checkParametersAcceptor( |
90 | 90 |
|
91 | 91 | /** @return RuleError[] */ |
92 | 92 | public function checkProperty( |
93 | | - PropertyReflection $propertyReflection, |
| 93 | + PhpPropertyReflection $propertyReflection, |
94 | 94 | string $message, |
95 | 95 | bool $isReadOnly, |
96 | 96 | ): array |
97 | 97 | { |
98 | | - $readableType = $propertyReflection->getReadableType(); |
99 | | - $writableType = $propertyReflection->getWritableType(); |
| 98 | + $type = $propertyReflection->getReadableType(); |
| 99 | + $variance = $isReadOnly |
| 100 | + ? TemplateTypeVariance::createCovariant() |
| 101 | + : TemplateTypeVariance::createInvariant(); |
100 | 102 |
|
101 | | - if ($readableType->equals($writableType)) { |
102 | | - $variance = $isReadOnly |
103 | | - ? TemplateTypeVariance::createCovariant() |
104 | | - : TemplateTypeVariance::createInvariant(); |
105 | | - |
106 | | - return $this->check($variance, $readableType, $message); |
107 | | - } |
108 | | - |
109 | | - $errors = []; |
110 | | - |
111 | | - if ($propertyReflection->isReadable()) { |
112 | | - foreach ($this->check(TemplateTypeVariance::createCovariant(), $readableType, $message) as $error) { |
113 | | - $errors[] = $error; |
114 | | - } |
115 | | - } |
116 | | - |
117 | | - if ($propertyReflection->isWritable()) { |
118 | | - foreach ($this->check(TemplateTypeVariance::createContravariant(), $writableType, $message) as $error) { |
119 | | - $errors[] = $error; |
120 | | - } |
121 | | - } |
122 | | - |
123 | | - return $errors; |
| 103 | + return $this->check($variance, $type, $message); |
124 | 104 | } |
125 | 105 |
|
126 | 106 | /** @return RuleError[] */ |
|
0 commit comments