Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/CircularLinkedList.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.

DataStructures/Lists/DoublyLinkedList.php 1 location

@@ 326-352 (lines=27) @@
323
     * @throws OutOfBoundsException if index is negative
324
     *  or is greater than the size of the list.
325
     */
326
    public function delete($index) {
327
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
328
            throw new OutOfBoundsException();
329
        }
330
331
        // if the list is empty
332
        if($this->head === null) {
333
            return null;
334
        }
335
        
336
        // if only there is an element
337
        if($this->head->next === $this->head) {
338
            $temp = $this->head;
339
            $this->head = null;
340
            $this->size--;
341
342
            return $temp->data;
343
        }
344
345
        if($index === 0) {
346
            return $this->deleteBeginning();
347
        } else if($index === $this->size - 1) {
348
            return $this->deleteEnd();
349
        } else {
350
            return $this->deleteAt($index);
351
        }
352
    }
353
354
    /**
355
     * Deletes at the beginnig of the list and returns the data stored.