Completed
Push — master ( 3be072...ba2d3a )
by Marco
231:32 queued 209:55
created

BaseAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 48
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Factory\RemoteObject\Adapter;
6
7
use ProxyManager\Factory\RemoteObject\AdapterInterface;
8
use Zend\Server\Client;
9
use function array_key_exists;
10
11
/**
12
 * Remote Object base adapter
13
 */
14
abstract class BaseAdapter implements AdapterInterface
15
{
16
    protected Client $client;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
18
    /**
19
     * Service name mapping
20
     *
21
     * @var string[]
22
     */
23
    protected array $map = [];
24
25
    /**
26
     * Constructor
27
     *
28
     * @param string[] $map map of service names to their aliases
29
     */
30
    public function __construct(Client $client, array $map = [])
31
    {
32
        $this->client = $client;
33
        $this->map    = $map;
34
    }
35
36 5
    /**
37
     * {@inheritDoc}
38 5
     *
39 5
     * @param mixed[] $params
40 5
     */
41
    public function call(string $wrappedClass, string $method, array $params = [])
42
    {
43
        $serviceName = $this->getServiceName($wrappedClass, $method);
44
45
        if (array_key_exists($serviceName, $this->map)) {
46
            $serviceName = $this->map[$serviceName];
47 2
        }
48
49 2
        return $this->client->call($serviceName, $params);
50
    }
51 2
52 1
    /**
53
     * Get the service name will be used by the adapter
54
     */
55 2
    abstract protected function getServiceName(string $wrappedClass, string $method) : string;
56
}
57