1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: /**
6: * @api
7: */
8: final class SimultaneousTypeTraverser
9: {
10:
11: /** @var callable(Type $left, Type $right, callable(Type, Type): Type $traverse): Type */
12: private $cb;
13:
14: /**
15: * @param callable(Type $left, Type $right, callable(Type, Type): Type $traverse): Type $cb
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: /** @param callable(Type $left, Type $right, callable(Type, Type): Type $traverse): Type $cb */
25: private function __construct(callable $cb)
26: {
27: $this->cb = $cb;
28: }
29:
30: /** @internal */
31: public function mapInternal(Type $left, Type $right): Type
32: {
33: return ($this->cb)($left, $right, [$this, 'traverseInternal']);
34: }
35:
36: /** @internal */
37: public function traverseInternal(Type $left, Type $right): Type
38: {
39: return $left->traverseSimultaneously($right, [$this, 'mapInternal']);
40: }
41:
42: }
43: