Forced   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A classify() 0 4 2
A picked() 0 3 1
A release() 0 3 1
1
<?php
2
/**
3
 * Forced routers (local debugging)
4
 * User: moyo
5
 * Date: 2018/4/20
6
 * Time: 11:51 AM
7
 */
8
9
namespace Carno\Cluster\Routing\Types;
10
11
use Carno\Cluster\Routing\Typed;
12
use Carno\Net\Endpoint;
13
14
class Forced implements Typed
15
{
16
    /**
17
     * local dev flag
18
     */
19
    private const TAG = 'LOCAL_DEV';
20
21
    /**
22
     * @var Endpoint[]
23
     */
24
    private $nodes = [];
25
26
    /**
27
     * @param string ...$tags
28
     * @return Endpoint[]
29
     */
30
    public function picked(string ...$tags) : array
31
    {
32
        return $this->nodes;
33
    }
34
35
    /**
36
     * @param string $tag
37
     * @param Endpoint $node
38
     */
39
    public function classify(string $tag, Endpoint $node) : void
40
    {
41
        if ($tag === self::TAG) {
42
            $this->nodes[$node->id()] = $node;
43
        }
44
    }
45
46
    /**
47
     * @param Endpoint $node
48
     */
49
    public function release(Endpoint $node) : void
50
    {
51
        unset($this->nodes[$node->id()]);
52
    }
53
}
54