Completed
Push — master ( b48de3...82623c )
by Daniel
04:05
created

RpcRequestCollection::changePriority()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Rpc\Request;
4
5
6
class RpcRequestCollection implements RpcRequestCollectionInterface, \IteratorAggregate, \Countable
7
{
8
    private $priority;
9
    public $requests = [];
10
11
    public function __construct($priority = RpcRequestCollectionInterface::PRIORITY_LOW)
12
    {
13
        $this->priority = $this->changePriority($priority);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->priority is correct as $this->changePriority($priority) (which targets Cmobi\RabbitmqBundle\Rpc...ction::changePriority()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
14
    }
15
16
    public function getIterator()
17
    {
18
        return new \ArrayIterator($this->requests);
19
    }
20
21
    public function count()
22
    {
23
        return count($this->requests);
24
    }
25
26
    public function add(RpcRequestInterface $request)
27
    {
28
        $key = array_search($request, $this->requests, true);
29
30
        if ($key !== false) {
31
            unset($this->requests[$key]);
32
        }
33
        $this->requests[] = $request;
34
    }
35
36
    public function all()
37
    {
38
        return $this->requests;
39
    }
40
41
    public function get($id)
42
    {
43
        if (isset($this->requests[$id])) {
44
            return $this->requests[$id];
45
        }
46
47
        return null;
48
    }
49
50
    /**
51
     * @param RpcRequest $request
52
     * @return string|int|null
53
     */
54
    public function getRequestIndex(RpcRequest $request)
55
    {
56
        return array_search($request, $this->requests);
57
    }
58
59
    /**
60
     * @param $id
61
     */
62
    public function remove($id)
63
    {
64
        unset($this->requests[$id]);
65
    }
66
67
    /**
68
     * @param RpcRequestCollection $collection
69
     */
70
    public function addCollection(RpcRequestCollection $collection)
71
    {
72
        foreach ($collection->all() as $id => $request) {
73
            unset($this->requests[$id]);
74
            $this->requests[$id] = $request;
75
        }
76
    }
77
78
    /**
79
     * @param $priorityNumber
80
     */
81
    public function changePriority($priorityNumber)
82
    {
83
        if (!decoct(octdec($priorityNumber) == $priorityNumber)) {
84
            $priorityNumber = decoct($priorityNumber);
85
        }
86
        $this->priority = $priorityNumber;
87
    }
88
89
    /**
90
     * Return octect priority
91
     *
92
     * @return int
93
     */
94
    public function getPriority()
95
    {
96
        return $this->priority;
97
    }
98
}