Completed
Push — master ( cd2604...399c1f )
by Matthieu
03:36
created

SplDoublyLinkedList::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DeepCopy\TypeFilter\Spl;
4
5
use DeepCopy\DeepCopy;
6
use DeepCopy\TypeFilter\TypeFilter;
7
8
class SplDoublyLinkedList implements TypeFilter
9
{
10
    /**
11
     * @var DeepCopy
12
     */
13
    private $deepCopy;
14
15
    public function __construct(DeepCopy $deepCopy)
16
    {
17
        $this->deepCopy = $deepCopy;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function apply($element)
24
    {
25
        $newElement = clone $element;
26
27
        if ($element instanceof \SplDoublyLinkedList) {
28
            // Replace each element in the list with a deep copy of itself
29
            for ($i = 1; $i <= $newElement->count(); $i++) {
30
                $newElement->push($this->deepCopy->copy($newElement->shift()));
31
            }
32
        }
33
34
        return $newElement;
35
36
    }
37
}
38