Code Duplication    Length = 13-13 lines in 5 locations

src/DP/GameServer/GameServerBundle/Socket/Packet.php 5 locations

@@ 139-151 (lines=13) @@
136
     * @return byte 
137
     * @throws EmptyPacketException 
138
     */
139
    public function getByte($delByte = true)
140
    {
141
        $content = $this->getContent();
142
        if (empty($content)) throw new EmptyPacketException();
143
        
144
        // On récupère 1 byte
145
        $data = substr($content, 0, 1);
146
        $data = unpack('cval', $data);
147
        
148
        if ($delByte) $this->setContentFromPos(substr($this->getContent(), 1));
149
        
150
        return $data['val'];
151
    }
152
    
153
    /**
154
     * Get a short from the packet content
@@ 160-172 (lines=13) @@
157
     * @return short
158
     * @throws EmptyPacketException 
159
     */
160
    public function getShort($delShort = true)
161
    {
162
        $content = $this->getContent();
163
        if (empty($content)) throw new EmptyPacketException();
164
        
165
        // On récupère les 2 bytes constituant l'entier court 
166
        $data = substr($content, 0, 2);
167
        $data = unpack('sval', $data);
168
        
169
        if ($delShort) $this->setContentFromPos(substr($this->content, 2));
170
        
171
        return $data['val'];
172
    }
173
    
174
    /**
175
     * Get a long from the packet content
@@ 181-193 (lines=13) @@
178
     * @return long
179
     * @throws EmptyPacketException 
180
     */
181
    public function getLong($delLong = true)
182
    {
183
        $content = $this->getContent();
184
        if (empty($content)) throw new EmptyPacketException();
185
        
186
        // On récupère les 4 bytes constituant l'entier long
187
        $data = substr($content, 0, 4);
188
        $data = unpack('lval', $data);
189
        
190
        if ($delLong) $this->setContentFromPos(substr($this->content, 4));
191
        
192
        return $data['val'];
193
    }
194
    
195
    /**
196
     * Get a integer from the packet content
@@ 202-214 (lines=13) @@
199
     * @return integer
200
     * @throws EmptyPacketException 
201
     */
202
    public function getInt($delInt = true)
203
    {
204
        $content = $this->getContent();
205
        if (empty($content)) throw new EmptyPacketException();
206
        
207
        // On récupère les 4 bytes constituant l'entier
208
        $data = substr($content, 0, 4);
209
        $data = unpack('ival', $data);
210
        
211
        if ($delInt) $this->setContentFromPos(substr($this->content, 4));
212
        
213
        return $data['val'];
214
    }
215
    
216
    /**
217
     * Get a float from the packet content
@@ 223-235 (lines=13) @@
220
     * @return float
221
     * @throws EmptyPacketException 
222
     */
223
    public function getFloat($delFloat = true)
224
    {
225
        $content = $this->getContent();
226
        if (empty($content)) throw new EmptyPacketException();
227
        
228
        // On récupère les 4 bytes constituant l'entier
229
        $data = substr($content, 0, 4);
230
        $data = unpack('fval', $data);
231
        
232
        if ($delFloat) $this->setContentFromPos(substr($this->content, 4));
233
        
234
        return $data['val'];
235
    }
236
    
237
    /**
238
     * Get the first string inside the packet content