Code Duplication    Length = 67-67 lines in 2 locations

src/Queue.php 1 location

@@ 11-77 (lines=67) @@
8
/**
9
 * Represents a first-in, first-out collection of objects.
10
 */
11
class Queue extends SplQueue implements QueueInterface, \JsonSerializable
12
{
13
    /**
14
     * Adds multiples objects to the end of the Queue.
15
     * @param CollectionInterface|array $items The objects to add to the Queue. The value can be null.
16
     * @return $this|Queue
17
     */
18
    public function enqueueMultiple($items)
19
    {
20
        foreach ($items as $item) {
21
            $this->enqueue($item);
22
        }
23
24
        return $this;
25
    }
26
27
    public static function fromArray(array $arr)
28
    {
29
        $collection = new Queue();
30
        foreach ($arr as $v) {
31
            if (is_array($v)) {
32
                $collection->enqueue(static::fromArray($v));
33
            } else {
34
                $collection->enqueue($v);
35
            }
36
        }
37
38
        return $collection;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function toArray()
45
    {
46
        $array = array();
47
        foreach ($this as $key => $value) {
48
            if ($value instanceof Enumerable) {
49
                $array[$key] = $value->toArray();
50
            } else {
51
                $array[$key] = $value;
52
            }
53
        }
54
55
        return $array;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function __toString()
62
    {
63
        return get_class($this);
64
    }
65
66
    /**
67
     * (PHP 5 &gt;= 5.4.0)<br/>
68
     * Specify data which should be serialized to JSON
69
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
70
     * @return mixed data which can be serialized by <b>json_encode</b>,
71
     * which is a value of any type other than a resource.
72
     */
73
    public function jsonSerialize()
74
    {
75
        return $this->toArray();
76
    }
77
}
78

src/Stack.php 1 location

@@ 11-77 (lines=67) @@
8
/**
9
 * Represents a simple last-in-first-out (LIFO) non-generic collection of objects.
10
 */
11
class Stack extends SplStack implements StackInterface, \JsonSerializable
12
{
13
    /**
14
     * Inserts multiples objects at the top of the Stack.
15
     * @param array $items The Objects to push onto the Stack. The value <b>can</b> be null.
16
     * @return $this|Stack
17
     */
18
    public function pushMultiple($items)
19
    {
20
        foreach ($items as $item) {
21
            $this->push($item);
22
        }
23
24
        return $this;
25
    }
26
27
    public static function fromArray(array $arr)
28
    {
29
        $collection = new Stack();
30
        foreach ($arr as $v) {
31
            if (is_array($v)) {
32
                $collection->push(static::fromArray($v));
33
            } else {
34
                $collection->push($v);
35
            }
36
        }
37
38
        return $collection;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function toArray()
45
    {
46
        $array = array();
47
        foreach ($this as $key => $value) {
48
            if ($value instanceof Enumerable) {
49
                $array[$key] = $value->toArray();
50
            } else {
51
                $array[$key] = $value;
52
            }
53
        }
54
55
        return $array;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function __toString()
62
    {
63
        return get_class($this);
64
    }
65
66
    /**
67
     * (PHP 5 &gt;= 5.4.0)<br/>
68
     * Specify data which should be serialized to JSON
69
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
70
     * @return mixed data which can be serialized by <b>json_encode</b>,
71
     * which is a value of any type other than a resource.
72
     */
73
    public function jsonSerialize()
74
    {
75
        return $this->toArray();
76
    }
77
}
78