Skip to content

Commit

Permalink
Better StaticType::traverse()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 12, 2022
1 parent 034df3d commit 0e25706
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Type/StaticType.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ public function toBoolean(): BooleanType

public function traverse(callable $cb): Type
{
$subtractedType = $this->subtractedType !== null ? $cb($this->subtractedType) : null;

if ($subtractedType !== $this->subtractedType) {
return new self(
$this->classReflection,
$subtractedType,
);
}

return $this;
}

Expand Down
14 changes: 14 additions & 0 deletions src/Type/ThisType.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public function changeSubtractedType(?Type $subtractedType): Type
return $type;
}

public function traverse(callable $cb): Type
{
$subtractedType = $this->getSubtractedType() !== null ? $cb($this->getSubtractedType()) : null;

if ($subtractedType !== $this->getSubtractedType()) {
return new self(
$this->getClassReflection(),
$subtractedType,
);
}

return $this;
}

/**
* @param mixed[] $properties
*/
Expand Down

0 comments on commit 0e25706

Please sign in to comment.