RandomPrioritizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 22
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

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
    public function sort(array $nodes, $currentNodeId)
15
    {
16
        if (count($nodes) === 1) {
17
            return $nodes;
18
        }
19
20
        $nodeIds = array_keys($nodes);
21
        shuffle($nodeIds);
22
23
        $shuffledNodes = [];
24
        foreach ($nodeIds as $nodeId) {
25
            $shuffledNodes[$nodeId] = $nodes[$nodeId];
26
        }
27
28
        return $shuffledNodes;
29
    }
30
}
31