Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/CircularLinkedList.php 1 location

@@ 236-262 (lines=27) @@
233
     * @throws OutOfBoundsException if index is negative
234
     *  or is greater than the size of the list.
235
     */
236
    public function delete($index) {
237
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
238
            throw new OutOfBoundsException();
239
        }
240
241
        // if the list is empty
242
        if($this->head === null) {
243
            return null;
244
        }
245
        
246
        // if only there is an element
247
        if($this->head->next === $this->head) {
248
            $temp = $this->head;
249
            $this->head = null;
250
            $this->size--;
251
252
            return $temp->data;
253
        }
254
255
        if($index === 0) {
256
            return $this->deleteBeginning();
257
        } else if($index === $this->size - 1) {
258
            return $this->deleteEnd();
259
        } else {
260
            return $this->deleteAt($index);
261
        }
262
    }
263
264
    /**
265
     * Deletes at the beginnig of the list and returns the data stored.

DataStructures/Lists/DoublyLinkedList.php 1 location

@@ 260-286 (lines=27) @@
257
     * @throws OutOfBoundsException if index is negative
258
     *  or is greater than the size of the list.
259
     */
260
    public function delete($index) {
261
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
262
            throw new OutOfBoundsException();
263
        }
264
265
        // if the list is empty
266
        if($this->head === null) {
267
            return null;
268
        }
269
        
270
        // if only there is an element
271
        if($this->head->next === $this->head) {
272
            $temp = $this->head;
273
            $this->head = null;
274
            $this->size--;
275
276
            return $temp->data;
277
        }
278
279
        if($index === 0) {
280
            return $this->deleteBeginning();
281
        } else if($index === $this->size - 1) {
282
            return $this->deleteEnd();
283
        } else {
284
            return $this->deleteAt($index);
285
        }
286
    }
287
288
    /**
289
     * Deletes at the beginnig of the list and returns the data stored.