UnicastRoutingTable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A routeToEndpoint() 0 12 3
A getEndpointNamesFor() 0 11 3
1
<?php
2
namespace PSB\Core\Routing;
3
4
5
class UnicastRoutingTable
6
{
7
    /**
8
     * @var array
9
     */
10
    private $staticRules = [];
11
12
    /**
13
     * @param string $messageFqcn
14
     * @param string $endpointName
15
     */
16 4
    public function routeToEndpoint($messageFqcn, $endpointName)
17
    {
18 4
        if (!isset($this->staticRules[$messageFqcn])) {
19 4
            $this->staticRules[$messageFqcn] = [];
20
        }
21
22 4
        if (in_array($endpointName, $this->staticRules[$messageFqcn])) {
23 1
            return;
24
        }
25
26 4
        $this->staticRules[$messageFqcn][] = $endpointName;
27 4
    }
28
29
    /**
30
     * @param string[] $messageTypes
31
     *
32
     * @return string[]
33
     */
34 4
    public function getEndpointNamesFor(array $messageTypes)
35
    {
36 4
        $endpoints = [];
37 4
        foreach ($messageTypes as $messageType) {
38 4
            if (isset($this->staticRules[$messageType])) {
39 4
                $endpoints = array_merge($endpoints, $this->staticRules[$messageType]);
40
            }
41
        }
42
43 4
        return array_unique($endpoints);
44
    }
45
}
46