Skip to content

Commit 47cc3a2

Browse files
committed
simplify property variance check by only supporting native properties
1 parent f44336f commit 47cc3a2

1 file changed

Lines changed: 7 additions & 27 deletions

File tree

‎src/Rules/Generics/VarianceCheck.php‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPStan\Rules\Generics;
44

55
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
6-
use PHPStan\Reflection\PropertyReflection;
6+
use PHPStan\Reflection\Php\PhpPropertyReflection;
77
use PHPStan\Rules\RuleError;
88
use PHPStan\Rules\RuleErrorBuilder;
99
use PHPStan\Type\Generic\TemplateType;
@@ -90,37 +90,17 @@ public function checkParametersAcceptor(
9090

9191
/** @return RuleError[] */
9292
public function checkProperty(
93-
PropertyReflection $propertyReflection,
93+
PhpPropertyReflection $propertyReflection,
9494
string $message,
9595
bool $isReadOnly,
9696
): array
9797
{
98-
$readableType = $propertyReflection->getReadableType();
99-
$writableType = $propertyReflection->getWritableType();
98+
$type = $propertyReflection->getReadableType();
99+
$variance = $isReadOnly
100+
? TemplateTypeVariance::createCovariant()
101+
: TemplateTypeVariance::createInvariant();
100102

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);
124104
}
125105

126106
/** @return RuleError[] */

0 commit comments

Comments
 (0)