Skip to content

Commit 0e25706

Browse files
committed
Better StaticType::traverse()
1 parent 034df3d commit 0e25706

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Type/StaticType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ public function toBoolean(): BooleanType
399399

400400
public function traverse(callable $cb): Type
401401
{
402+
$subtractedType = $this->subtractedType !== null ? $cb($this->subtractedType) : null;
403+
404+
if ($subtractedType !== $this->subtractedType) {
405+
return new self(
406+
$this->classReflection,
407+
$subtractedType,
408+
);
409+
}
410+
402411
return $this;
403412
}
404413

src/Type/ThisType.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public function changeSubtractedType(?Type $subtractedType): Type
5757
return $type;
5858
}
5959

60+
public function traverse(callable $cb): Type
61+
{
62+
$subtractedType = $this->getSubtractedType() !== null ? $cb($this->getSubtractedType()) : null;
63+
64+
if ($subtractedType !== $this->getSubtractedType()) {
65+
return new self(
66+
$this->getClassReflection(),
67+
$subtractedType,
68+
);
69+
}
70+
71+
return $this;
72+
}
73+
6074
/**
6175
* @param mixed[] $properties
6276
*/

0 commit comments

Comments
 (0)