UnicastRoutingTable::routeToEndpoint()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 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