Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/CircularLinkedList.php 1 location

@@ 299-325 (lines=27) @@
296
     * @throws OutOfBoundsException if index is negative
297
     *  or is greater than the size of the list.
298
     */
299
    public function delete($index) {
300
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
301
            throw new OutOfBoundsException();
302
        }
303
304
        // if the list is empty
305
        if($this->head === null) {
306
            return null;
307
        }
308
        
309
        // if only there is an element
310
        if($this->head->next === $this->head) {
311
            $temp = $this->head;
312
            $this->head = null;
313
            $this->size--;
314
315
            return $temp->data;
316
        }
317
318
        if($index === 0) {
319
            return $this->deleteBeginning();
320
        } else if($index === $this->size - 1) {
321
            return $this->deleteEnd();
322
        } else {
323
            return $this->deleteAt($index);
324
        }
325
    }
326
327
    /**
328
     * Deletes at the beginnig of the list and returns the data stored.

DataStructures/Lists/DoublyLinkedList.php 1 location

@@ 300-326 (lines=27) @@
297
     * @throws OutOfBoundsException if index is negative
298
     *  or is greater than the size of the list.
299
     */
300
    public function delete($index) {
301
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
302
            throw new OutOfBoundsException();
303
        }
304
305
        // if the list is empty
306
        if($this->head === null) {
307
            return null;
308
        }
309
        
310
        // if only there is an element
311
        if($this->head->next === $this->head) {
312
            $temp = $this->head;
313
            $this->head = null;
314
            $this->size--;
315
316
            return $temp->data;
317
        }
318
319
        if($index === 0) {
320
            return $this->deleteBeginning();
321
        } else if($index === $this->size - 1) {
322
            return $this->deleteEnd();
323
        } else {
324
            return $this->deleteAt($index);
325
        }
326
    }
327
328
    /**
329
     * Deletes at the beginnig of the list and returns the data stored.