Skip to content

Commit

Permalink
Add int(), float() to RecursiveTypeReplacer
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Aug 1, 2024
1 parent ef6d502 commit 1966c8a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Visitor/RecursiveTypeReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
*/
abstract class RecursiveTypeReplacer extends DefaultTypeVisitor
{
public function int(Type $type, Type $minType, Type $maxType): mixed
{
$newMinType = $minType->accept($this);
$newMaxType = $maxType->accept($this);

if ($newMinType === $minType && $newMaxType === $maxType) {
return $type;
}

return types::intRange($newMinType, $newMaxType);
}

public function intMask(Type $type, Type $ofType): mixed
{
$newOfType = $ofType->accept($this);
Expand All @@ -30,6 +42,18 @@ public function intMask(Type $type, Type $ofType): mixed
return types::intMaskOf($newOfType);
}

public function float(Type $type, Type $minType, Type $maxType): mixed
{
$newMinType = $minType->accept($this);
$newMaxType = $maxType->accept($this);

if ($newMinType === $minType && $newMaxType === $maxType) {
return $type;
}

return types::floatRange($newMinType, $newMaxType);
}

public function classString(Type $type, Type $classType): mixed
{
$newClassType = $classType->accept($this);
Expand Down

0 comments on commit 1966c8a

Please sign in to comment.