Completed
Push — master ( 4a282c...f5ece7 )
by Mariano
03:58 queued 01:18
created

RandomPrioritizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 22
ccs 9
cts 10
cp 0.9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sort() 0 16 3
1
<?php
2
namespace Disque\Connection\Node;
3
4
/**
5
 * This prioritizer advises the Manager to switch nodes randomly
6
 *
7
 * It can be used to test the availability of nodes in a cluster.
8
 */
9
class RandomPrioritizer implements NodePrioritizerInterface
10
{
11
    /**
12
     * @inheritdoc
13
     */
14 1
    public function sort(array $nodes, $currentNodeId)
15
    {
16 1
        if (count($nodes) === 1) {
17
            return $nodes;
18
        }
19
20 1
        $nodeIds = array_keys($nodes);
21 1
        shuffle($nodeIds);
22
23 1
        $shuffledNodes = [];
24 1
        foreach ($nodeIds as $nodeId) {
25 1
            $shuffledNodes[$nodeId] = $nodes[$nodeId];
26 1
        }
27
28 1
        return $shuffledNodes;
29
    }
30
}
31