Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/CircularLinkedList.php 1 location

@@ 271-297 (lines=27) @@
268
     * @throws OutOfBoundsException if index is negative
269
     *  or is greater than the size of the list.
270
     */
271
    public function delete($index) {
272
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
273
            throw new OutOfBoundsException();
274
        }
275
276
        // if the list is empty
277
        if($this->head === null) {
278
            return null;
279
        }
280
        
281
        // if only there is an element
282
        if($this->head->next === $this->head) {
283
            $temp = $this->head;
284
            $this->head = null;
285
            $this->size--;
286
287
            return $temp->data;
288
        }
289
290
        if($index === 0) {
291
            return $this->deleteBeginning();
292
        } else if($index === $this->size - 1) {
293
            return $this->deleteEnd();
294
        } else {
295
            return $this->deleteAt($index);
296
        }
297
    }
298
299
    /**
300
     * Deletes at the beginnig of the list and returns the data stored.

DataStructures/Lists/DoublyLinkedList.php 1 location

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