1 | <?php |
||
34 | final class Connection |
||
35 | { |
||
36 | private $transport; |
||
37 | private $authority; |
||
38 | private $vhost; |
||
39 | private $protocol; |
||
40 | private $socket; |
||
41 | private $timeout; |
||
42 | private $select; |
||
43 | private $read; |
||
44 | private $opened = false; |
||
45 | private $maxChannels; |
||
46 | private $maxFrameSize; |
||
47 | private $heartbeat; |
||
48 | |||
49 | 7 | public function __construct( |
|
50 | Transport $transport, |
||
51 | UrlInterface $server, |
||
52 | Protocol $protocol, |
||
53 | ElapsedPeriod $timeout |
||
54 | ) { |
||
55 | 7 | $this->transport = $transport; |
|
56 | 7 | $this->authority = $server->authority(); |
|
57 | 7 | $this->vhost = $server->path(); |
|
58 | 7 | $this->protocol = $protocol; |
|
59 | 7 | $this->timeout = $timeout; |
|
60 | 7 | $this->buildSocket(); |
|
61 | 7 | $this->read = new FrameReader; |
|
62 | 7 | $this->maxChannels = new MaxChannels(0); |
|
63 | 7 | $this->maxFrameSize = new MaxFrameSize(0); |
|
64 | 7 | $this->heartbeat = $timeout; |
|
65 | |||
66 | 7 | $this->open(); |
|
67 | 7 | } |
|
68 | |||
69 | 5 | public function protocol(): Protocol |
|
73 | |||
74 | 7 | public function send(Frame $frame): self |
|
96 | |||
97 | 7 | public function wait(string ...$names): Frame |
|
113 | |||
114 | 7 | public function close(): void |
|
115 | { |
||
116 | 7 | if (!$this->opened()) { |
|
117 | 1 | return; |
|
118 | } |
||
119 | |||
120 | $this |
||
121 | 7 | ->send($this->protocol->connection()->close(new Close)) |
|
122 | 7 | ->wait('connection.close-ok'); |
|
123 | 7 | $this->socket->close(); |
|
124 | 7 | $this->opened = false; |
|
125 | 7 | } |
|
126 | |||
127 | 7 | public function opened(): bool |
|
128 | { |
||
129 | 7 | return $this->opened && !$this->socket->closed(); |
|
130 | } |
||
131 | |||
132 | 4 | public function __destruct() |
|
133 | { |
||
134 | 4 | $this->close(); |
|
135 | 4 | } |
|
136 | |||
137 | 7 | private function buildSocket(): void |
|
138 | { |
||
139 | 7 | $this->socket = new Socket( |
|
140 | 7 | $this->transport, |
|
141 | 7 | $this->authority->withUserInformation(new NullUserInformation) |
|
142 | ); |
||
143 | 7 | $this->select = (new Select($this->timeout))->forRead($this->socket); |
|
144 | 7 | } |
|
145 | |||
146 | 7 | private function open(): void |
|
147 | { |
||
148 | 7 | if ($this->opened()) { |
|
149 | return; |
||
150 | } |
||
151 | |||
152 | 7 | $this->start(); |
|
153 | 7 | $this->handshake(); |
|
154 | 7 | $this->openVHost(); |
|
155 | |||
156 | 7 | $this->opened = true; |
|
157 | 7 | } |
|
158 | |||
159 | 7 | private function start(): void |
|
201 | |||
202 | 7 | private function handshake(): void |
|
234 | |||
235 | 7 | private function openVHost(): void |
|
243 | } |
||
244 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.