Code Duplication    Length = 59-60 lines in 2 locations

Rpc/Request/JsonRpcRequestCollection.php 1 location

@@ 6-65 (lines=60) @@
3
namespace Cmobi\RabbitmqBundle\Rpc\Request;
4
5
6
class JsonRpcRequestCollection 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($id, RpcRequestInterface $request)
21
    {
22
        unset($this->requests[$id]);
23
24
        $this->requests[$id] = $request;
25
    }
26
27
    public function all()
28
    {
29
        return $this->requests;
30
    }
31
32
    public function get($id)
33
    {
34
        if (isset($this->requests[$id])) {
35
            return $this->requests[$id];
36
        }
37
38
        return null;
39
    }
40
41
    public function remove($id)
42
    {
43
        unset($this->requests[$id]);
44
    }
45
46
    public function addCollection(JsonRpcRequestCollection $collection)
47
    {
48
        foreach ($collection->all() as $id => $request) {
49
            unset($this->requests[$id]);
50
            $this->requests[$id] = $request;
51
        }
52
    }
53
54
    public function __toString()
55
    {
56
        $requests = [];
57
58
        foreach ($this->requests as $request) {
59
            $request = json_decode($request, true);
60
            $requests[] = $request;
61
        }
62
63
        return json_encode($requests);
64
    }
65
}

Rpc/Response/JsonRpcResponseCollection.php 1 location

@@ 6-64 (lines=59) @@
3
namespace Cmobi\RabbitmqBundle\Rpc\Response;
4
5
6
class JsonRpcResponseCollection 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($id = null, RpcResponseInterface $response)
21
    {
22
        unset($this->responses[$id]);
23
24
        $this->responses[$id] = $response;
25
    }
26
    public function all()
27
    {
28
        return $this->responses;
29
    }
30
31
32
    public function get($id)
33
    {
34
        if (isset($this->responses[$id])) {
35
            return $this->responses[$id];
36
        }
37
38
        return null;
39
    }
40
41
    public function remove($id)
42
    {
43
        unset($this->responses[$id]);
44
    }
45
46
    public function addCollection(JsonRpcResponseCollection $collection)
47
    {
48
        foreach ($collection->all() as $id => $response) {
49
            unset($this->responses[$id]);
50
            $this->responses[$id] = $response;
51
        }
52
    }
53
54
    public function __toString()
55
    {
56
        $response = [];
57
        foreach ($this->responses as $response) {
58
            $response = json_decode($response, true);
59
            $response[] = $response;
60
        }
61
62
        return json_encode($response);
63
    }
64
}