Code Duplication    Length = 53-54 lines in 2 locations

Rpc/Request/RpcRequestCollection.php 1 location

@@ 6-58 (lines=53) @@
3
namespace Cmobi\RabbitmqBundle\Rpc\Request;
4
5
6
class RpcRequestCollection implements RpcRequestCollectionInterface, \IteratorAggregate, \Countable
7
{
8
    public $requests = [];
9
10
    public function getIterator()
11
    {
12
        return new \ArrayIterator($this->requests);
13
    }
14
15
    public function count()
16
    {
17
        return count($this->requests);
18
    }
19
20
    public function add(RpcRequestInterface $request)
21
    {
22
        $key = array_search($request, $this->requests, true);
23
24
        if ($key !== false) {
25
            unserialize($this->requests[$key]);
26
        }
27
        unset($this->requests[$key]);
28
29
        $this->requests[] = $request;
30
    }
31
32
    public function all()
33
    {
34
        return $this->requests;
35
    }
36
37
    public function get($id)
38
    {
39
        if (isset($this->requests[$id])) {
40
            return $this->requests[$id];
41
        }
42
43
        return null;
44
    }
45
46
    public function remove($id)
47
    {
48
        unset($this->requests[$id]);
49
    }
50
51
    public function addCollection(RpcRequestCollection $collection)
52
    {
53
        foreach ($collection->all() as $id => $request) {
54
            unset($this->requests[$id]);
55
            $this->requests[$id] = $request;
56
        }
57
    }
58
}

Rpc/Response/RpcResponseCollection.php 1 location

@@ 6-59 (lines=54) @@
3
namespace Cmobi\RabbitmqBundle\Rpc\Response;
4
5
6
class RpcResponseCollection implements RpcResponseCollectionInterface, \IteratorAggregate, \Countable
7
{
8
    public $responses = [];
9
10
    public function getIterator()
11
    {
12
        return new \ArrayIterator($this->responses);
13
    }
14
15
    public function count()
16
    {
17
        return count($this->responses);
18
    }
19
20
    public function add(RpcResponseInterface $response)
21
    {
22
        $key = array_search($response, $this->responses, true);
23
24
        if ($key !== false) {
25
            unserialize($this->responses[$key]);
26
        }
27
        unset($this->responses[$key]);
28
29
        $this->responses[] = $response;
30
    }
31
32
    public function all()
33
    {
34
        return $this->responses;
35
    }
36
37
38
    public function get($id)
39
    {
40
        if (isset($this->responses[$id])) {
41
            return $this->responses[$id];
42
        }
43
44
        return null;
45
    }
46
47
    public function remove($id)
48
    {
49
        unset($this->responses[$id]);
50
    }
51
52
    public function addCollection(RpcResponseCollection $collection)
53
    {
54
        foreach ($collection->all() as $id => $response) {
55
            unset($this->responses[$id]);
56
            $this->responses[$id] = $response;
57
        }
58
    }
59
}