Skip to content

Commit

Permalink
More readable bleeding edge handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 22, 2024
1 parent 0bf864d commit f4b1b48
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions src/Rules/RuleLevelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ private function transformCommonType(Type $type): Type
}

return TypeTraverser::map($type, function (Type $type, callable $traverse) {
if ($type instanceof TemplateMixedType && ($this->checkExplicitMixed || !$this->newRuleLevelHelper)) {
return $type->toStrictMixedType();
if ($type instanceof TemplateMixedType) {
if (!$this->newRuleLevelHelper) {
return $type->toStrictMixedType();
}

if ($this->checkExplicitMixed) {
return $type->toStrictMixedType();
}
}
if (
$type instanceof MixedType
Expand Down Expand Up @@ -301,20 +307,39 @@ public function findTypeToCheck(
$type = TypeCombinator::removeNull($type);
}

if (
($this->checkExplicitMixed || $this->checkImplicitMixed)
&& $type instanceof MixedType
&& ($type->isExplicitMixed() ? $this->checkExplicitMixed : $this->checkImplicitMixed)
&& ($this->newRuleLevelHelper || !$type instanceof TemplateMixedType)
) {
return new FoundTypeResult(
$type instanceof TemplateMixedType
? $type->toStrictMixedType()
: new StrictMixedType(),
[],
[],
null,
);
if ($this->newRuleLevelHelper) {
if (
($this->checkExplicitMixed || $this->checkImplicitMixed)
&& $type instanceof MixedType
&& ($type->isExplicitMixed() ? $this->checkExplicitMixed : $this->checkImplicitMixed)
) {
return new FoundTypeResult(
$type instanceof TemplateMixedType
? $type->toStrictMixedType()
: new StrictMixedType(),
[],
[],
null,
);
}
} else {
if (
$this->checkExplicitMixed
&& $type instanceof MixedType
&& !$type instanceof TemplateMixedType
&& $type->isExplicitMixed()
) {
return new FoundTypeResult(new StrictMixedType(), [], [], null);
}

if (
$this->checkImplicitMixed
&& $type instanceof MixedType
&& !$type instanceof TemplateMixedType
&& !$type->isExplicitMixed()
) {
return new FoundTypeResult(new StrictMixedType(), [], [], null);
}
}

if ($type instanceof MixedType || $type instanceof NeverType) {
Expand Down

0 comments on commit f4b1b48

Please sign in to comment.