Skip to content

Commit a846da0

Browse files
Rework
1 parent 63ad626 commit a846da0

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/Rules/RuleLevelHelper.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,44 @@ private function transformCommonType(Type $type): Type
6262
}
6363

6464
return TypeTraverser::map($type, function (Type $type, callable $traverse) {
65+
if ($type instanceof CallableType) {
66+
if ($type->isCommonCallable()) {
67+
return $type;
68+
}
69+
70+
return new CallableType(
71+
$type->getParameters(),
72+
$traverse($this->transformCommonType($type->getReturnType())),
73+
$type->isVariadic(),
74+
$type->getTemplateTypeMap(),
75+
$type->getResolvedTemplateTypeMap(),
76+
$type->getTemplateTags(),
77+
$type->isPure(),
78+
);
79+
}
80+
81+
if ($type instanceof ClosureType) {
82+
if ($type->isCommonCallable()) {
83+
return $type;
84+
}
85+
86+
return new ClosureType(
87+
$type->getParameters(),
88+
$traverse($this->transformCommonType($type->getReturnType())),
89+
$type->isVariadic(),
90+
$type->getTemplateTypeMap(),
91+
$type->getResolvedTemplateTypeMap(),
92+
$type->getCallSiteVarianceMap(),
93+
$type->getTemplateTags(),
94+
$type->getThrowPoints(),
95+
$type->getImpurePoints(),
96+
$type->getInvalidateExpressions(),
97+
$type->getUsedVariables(),
98+
$type->acceptsNamedArguments(),
99+
$type->mustUseReturnValue(),
100+
);
101+
}
102+
65103
if ($type instanceof TemplateMixedType) {
66104
if ($this->checkExplicitMixed) {
67105
return $type->toStrictMixedType();

src/Type/Generic/TemplateTypeVariance.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,6 @@ public function isValidVariance(TemplateType $templateType, Type $a, Type $b): I
177177

178178
if ($this->invariant()) {
179179
$result = $a->equals($b);
180-
if (
181-
!$result
182-
&& $a instanceof TemplateType
183-
&& $b instanceof TemplateType
184-
&& $a->getScope()->equals($b->getScope())
185-
&& $a->getName() === $b->getName()
186-
) {
187-
$result = true;
188-
}
189180
$reasons = [];
190181
if (!$result) {
191182
if (

0 commit comments

Comments
 (0)