Code Duplication    Length = 47-47 lines in 2 locations

src/DP/GameServer/MinecraftServerBundle/MinecraftQuery/MinecraftRcon.php 1 location

@@ 187-233 (lines=47) @@
184
     * 
185
     * @return \DP\GameServer\GameServerBundle\Socket\Packet|null
186
     */
187
    private function recv()
188
    {
189
        $packets = new PacketCollection();
190
        
191
        do {
192
            try {
193
                $resp = $this->socket->recv();
194
                $packets->add($resp->rewind());
195
            }
196
            catch (RecvTimeoutException $e) {
197
                $resp = null;
198
            }
199
        } while ($resp != null);
200
        
201
        // Verif que tous les paquets ont bien été reçus
202
        // Si c'est le cas on renvoie les données reçus, sinon on renvoie rien
203
        if ($packets->count() > 0) {
204
            $packetFactory = $this->packetFactory;
205
206
            return $packets->reassemble(function (Packet $bigPacket, Packet $packet) use ($packetFactory) {
207
                if ($bigPacket->isEmpty()) {
208
                    $bigPacket->addContent($packet);
209
                }
210
                else {
211
                    $bigPacket->rewind();
212
213
                    // Ajout de la taille du packet au bigPacket
214
                    $packetSize = $packet->getLong(false);
215
                    $bigPacketSize = $bigPacket->getLong();
216
                    $newSize = $packetSize + $bigPacketSize;
217
218
                    $bigPacket->rewind()->addContent(
219
                        $packetFactory->transformLong($newSize)
220
                    );
221
222
                    // Ajout du contenu au bigPacket                
223
                    $bigPacket->setPos($bigPacket->getLength()-4)->addContent(
224
                        substr($packet->setPos(12)->getString(), 0, -4)
225
                    );
226
                }
227
228
                return $bigPacket;
229
            });
230
        }
231
        
232
        return null;
233
    }
234
}
235

src/DP/GameServer/SteamServerBundle/SteamQuery/SourceRcon.php 1 location

@@ 228-274 (lines=47) @@
225
     * 
226
     * @return \DP\GameServer\GameServerBundle\Socket\Packet|null
227
     */
228
    private function recv()
229
    {
230
        $packets = new PacketCollection();
231
        
232
        do {
233
            try {
234
                $resp = $this->socket->recv();
235
                $packets->add($resp->rewind());
236
            }
237
            catch (RecvTimeoutException $e) {
238
                $resp = null;
239
            }
240
        } while ($resp != null);
241
        
242
        // Verif que tous les paquets ont bien été reçus
243
        // Si c'est le cas on renvoie les données reçus, sinon on renvoie rien
244
        if ($packets->count() > 0 && $this->verifyAllPacketsReceived()) {
245
            $packetFactory = $this->packetFactory;
246
247
            return $packets->reassemble(function (Packet $bigPacket, Packet $packet) use ($packetFactory) {
248
                if ($bigPacket->isEmpty()) {
249
                    $bigPacket->addContent($packet);
250
                }
251
                else {
252
                    $bigPacket->rewind();
253
254
                    // Ajout de la taille du packet au bigPacket
255
                    $packetSize = $packet->getLong(false);
256
                    $bigPacketSize = $bigPacket->getLong();
257
                    $newSize = $packetSize + $bigPacketSize;
258
259
                    $bigPacket->rewind()->addContent(
260
                        $packetFactory->transformLong($newSize)
261
                    );
262
263
                    // Ajout du contenu au bigPacket                
264
                    $bigPacket->setPos($bigPacket->getLength()-4)->addContent(
265
                        substr($packet->setPos(12)->getString(), 0, -4)
266
                    );
267
                }
268
269
                return $bigPacket;
270
            });
271
        }
272
        
273
        return null;
274
    }
275
    
276
    public function verifyAllPacketsReceived()
277
    {