Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/DoublyLinkedList.php 1 location

@@ 362-388 (lines=27) @@
359
     * @throws OutOfBoundsException if index is negative
360
     *  or is greater than the size of the list.
361
     */
362
    public function delete($index) {
363
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
364
            throw new OutOfBoundsException();
365
        }
366
367
        // if the list is empty
368
        if($this->head === null) {
369
            return null;
370
        }
371
        
372
        // if only there is an element
373
        if($this->head->next === $this->head) {
374
            $temp = $this->head;
375
            $this->head = null;
376
            $this->size--;
377
378
            return $temp->data;
379
        }
380
381
        if($index === 0) {
382
            return $this->deleteBeginning();
383
        } else if($index === $this->size - 1) {
384
            return $this->deleteEnd();
385
        } else {
386
            return $this->deleteAt($index);
387
        }
388
    }
389
390
    /**
391
     * Deletes at the beginnig of the list and returns the data stored.

DataStructures/Lists/CircularLinkedList.php 1 location

@@ 341-367 (lines=27) @@
338
     * @throws OutOfBoundsException if index is negative
339
     *  or is greater than the size of the list.
340
     */
341
    public function delete($index) {
342
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
343
            throw new OutOfBoundsException();
344
        }
345
346
        // if the list is empty
347
        if($this->head === null) {
348
            return null;
349
        }
350
        
351
        // if only there is an element
352
        if($this->head->next === $this->head) {
353
            $temp = $this->head;
354
            $this->head = null;
355
            $this->size--;
356
357
            return $temp->data;
358
        }
359
360
        if($index === 0) {
361
            return $this->deleteBeginning();
362
        } else if($index === $this->size - 1) {
363
            return $this->deleteEnd();
364
        } else {
365
            return $this->deleteAt($index);
366
        }
367
    }
368
369
    /**
370
     * Deletes at the beginnig of the list and returns the data stored.