ClientFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 15
dl 0
loc 33
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createClient() 0 16 3
1
<?php
2
3
namespace DMT\WebservicesNl\Client\Factory;
4
5
use DMT\WebservicesNl\Client\Client;
6
use Doctrine\Common\Annotations\AnnotationException;
7
8
/**
9
 * Class ClientFactory
10
 *
11
 * @package DMT\WebservicesNl\Client
12
 */
13
class ClientFactory
14
{
15
    /**
16
     * @static array
17
     */
18
    const ENDPOINTS = [
19
        'soap' => 'https://ws1.webservices.nl/soap/',
20
        'soap_doclit' => 'https://ws1.webservices.nl/soap_doclit/',
21
    ];
22
23
    /**
24
     * @param string $type
25
     * @param array $credentials
26
     *
27
     * @return Client
28
     * @throws AnnotationException
29
     */
30 4
    public static function createClient(string $type, array $credentials)
31
    {
32
        switch ($type) {
33 4
            case 'soap': // fall through
34 2
            case 'soap_doclit':
35 3
                $builder = SoapClientBuilder::create('soap');
36 3
                break;
37
38
            default:
39 1
                throw new \InvalidArgumentException('Unsupported client type');
40
        }
41
42
        return $builder
43 3
            ->setAuthentication($credentials)
44 2
            ->setServiceEndpoint(static::ENDPOINTS[$type])
45 2
            ->build();
46
    }
47
}
48