| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type; |
| 4: | |
| 5: | use PHPStan\Turbo\ShadowedByTurboExtension; |
| 6: | |
| 7: | #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/TypeTraverser.cpp')] |
| 8: | final class TypeTraverser |
| 9: | { |
| 10: | |
| 11: | |
| 12: | private $cb; |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | public static function map(Type $type, TypeTraverserCallable|callable $cb): Type |
| 40: | { |
| 41: | $self = new self($cb); |
| 42: | |
| 43: | return $self->mapInternal($type); |
| 44: | } |
| 45: | |
| 46: | |
| 47: | private function __construct(TypeTraverserCallable|callable $cb) |
| 48: | { |
| 49: | if ($cb instanceof TypeTraverserCallable) { |
| 50: | $this->cb = static fn (Type $type, callable $traverse): Type => $cb->traverse($type, $traverse); |
| 51: | } else { |
| 52: | $this->cb = $cb; |
| 53: | } |
| 54: | } |
| 55: | |
| 56: | |
| 57: | public function mapInternal(Type $type): Type |
| 58: | { |
| 59: | return ($this->cb)($type, [$this, 'traverseInternal']); |
| 60: | } |
| 61: | |
| 62: | |
| 63: | public function traverseInternal(Type $type): Type |
| 64: | { |
| 65: | return $type->traverse([$this, 'mapInternal']); |
| 66: | } |
| 67: | |
| 68: | } |
| 69: | |