ClientFactory::createClient()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.9
cc 3
nc 3
nop 2
crap 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