RemoteAdapterFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
wmc 7
lcom 0
cbo 6
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C getAdapter() 0 23 7
1
<?php
2
namespace DICIT\Activators;
3
4
use DICIT\Activators\Remote\RestAdapter;
5
6
class RemoteAdapterFactory
7
{
8
9
    /**
10
     *
11
     * @param string $serviceName
12
     * @param array $serviceConfig
13
     * @throws \BadMethodCallException
14
     * @return \ProxyManager\Factory\RemoteObject\AdapterInterface
15
     */
16
    public function getAdapter($serviceName, array $serviceConfig)
17
    {
18
        if (! isset($serviceConfig['protocol']) || ! isset($serviceConfig['endpoint'])) {
19
            throw new \InvalidArgumentException(
20
                sprintf("Protocol and endpoint are required for remote object '%s'", $serviceName));
21
        }
22
23
        $protocol = $serviceConfig['protocol'];
24
        $endpoint = $serviceConfig['endpoint'];
25
26
        switch ($protocol) {
27
            case 'xml-rpc':
28
                return new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc(new \Zend\XmlRpc\Client($endpoint));
29
            case 'json-rpc':
30
                return new \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc(new \Zend\Json\Server\Client($endpoint));
31
            case 'soap':
32
                return new \ProxyManager\Factory\RemoteObject\Adapter\Soap(new \Zend\Soap\Client($endpoint));
33
            case 'rest':
34
                return new RestAdapter(new \Guzzle\Http\Client($endpoint));
35
            default:
36
                throw new UnknownProtocolException(sprintf("Protocol '%s' is not supported ", $protocol));
37
        }
38
    }
39
}
40