NullPrioritizer::sort()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
crap 6
1
<?php
2
namespace Disque\Connection\Node;
3
4
/**
5
 * This prioritizer always advises to stay on the current node
6
 */
7
class NullPrioritizer implements NodePrioritizerInterface
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function sort(array $nodes, $currentNodeId)
13
    {
14
        if (current($nodes) === $nodes[$currentNodeId]) {
15
            return $nodes;
16
        }
17
18
        // Move the current node to the first place
19
        $currentNode = $nodes[$currentNodeId];
20
        unset($nodes[$currentNodeId]);
21
        array_unshift($nodes, $currentNode);
22
23
        return $nodes;
24
    }
25
}
26