Total Complexity | 8 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | class Reconciled |
||
14 | { |
||
15 | /** |
||
16 | * @var Packet[] |
||
17 | */ |
||
18 | private $packets = []; |
||
19 | |||
20 | /** |
||
21 | * @param int $seq |
||
22 | * @return Packet |
||
23 | */ |
||
24 | public function wait(int $seq) : Packet |
||
25 | { |
||
26 | return $this->packets[$seq] = new Packet($seq, $this); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param int $seq |
||
31 | * @param string $message |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function done(int $seq, string $message) : bool |
||
35 | { |
||
36 | if ($packet = $this->packets[$seq] ?? null) { |
||
37 | unset($this->packets[$seq]); |
||
38 | return $packet->received($message); |
||
39 | } |
||
40 | return false; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param int $seq |
||
45 | * @param Throwable $e |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function fail(int $seq, Throwable $e = null) : bool |
||
49 | { |
||
50 | if ($packet = $this->packets[$seq] ?? null) { |
||
51 | unset($this->packets[$seq]); |
||
52 | return $packet->failure($e); |
||
53 | } |
||
54 | return false; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param int $seq |
||
59 | */ |
||
60 | public function free(int $seq) : void |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param Throwable $e |
||
67 | */ |
||
68 | public function shutdown(Throwable $e = null) : void |
||
75 |