Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/CircularLinkedList.php 1 location

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

DataStructures/Lists/DoublyLinkedList.php 1 location

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