| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type; |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | final class SimultaneousTypeTraverser |
| 9: | { |
| 10: | |
| 11: | |
| 12: | private $cb; |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | public static function map(Type $left, Type $right, callable $cb): Type |
| 18: | { |
| 19: | $self = new self($cb); |
| 20: | |
| 21: | return $self->mapInternal($left, $right); |
| 22: | } |
| 23: | |
| 24: | |
| 25: | private function __construct(callable $cb) |
| 26: | { |
| 27: | $this->cb = $cb; |
| 28: | } |
| 29: | |
| 30: | |
| 31: | public function mapInternal(Type $left, Type $right): Type |
| 32: | { |
| 33: | return ($this->cb)($left, $right, [$this, 'traverseInternal']); |
| 34: | } |
| 35: | |
| 36: | |
| 37: | public function traverseInternal(Type $left, Type $right): Type |
| 38: | { |
| 39: | return $left->traverseSimultaneously($right, [$this, 'mapInternal']); |
| 40: | } |
| 41: | |
| 42: | } |
| 43: | |