| Total Complexity | 9 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class Packet |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var int |
||
| 19 | */ |
||
| 20 | private $seq = null; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Reconciled |
||
| 24 | */ |
||
| 25 | private $from = null; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Promised |
||
| 29 | */ |
||
| 30 | private $wait = null; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Packet constructor. |
||
| 34 | * @param int $seq |
||
| 35 | * @param Reconciled $from |
||
| 36 | */ |
||
| 37 | public function __construct(int $seq, Reconciled $from) |
||
| 38 | { |
||
| 39 | $this->seq = $seq; |
||
| 40 | $this->from = $from; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param string $message |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | public function received(string $message) : bool |
||
| 48 | { |
||
| 49 | if ($this->wait && $this->wait->pended()) { |
||
| 50 | $this->wait->resolve($message); |
||
| 51 | $this->from = null; |
||
| 52 | return true; |
||
| 53 | } |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param Throwable $e |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | public function failure(Throwable $e = null) : bool |
||
| 62 | { |
||
| 63 | if ($this->wait && $this->wait->pended()) { |
||
| 64 | $this->wait->reject($e); |
||
| 65 | $this->from = null; |
||
| 66 | return true; |
||
| 67 | } |
||
| 68 | return false; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return Promised |
||
| 73 | */ |
||
| 74 | public function message() : Promised |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return Promised |
||
| 81 | */ |
||
| 82 | private function cleanup() : Promised |
||
| 90 |