Passed
Push — master ( 443842...86f0b2 )
by Joshua
05:55 queued 01:59
created

ClientFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 6 1
A build() 0 19 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SeamsCMS\Delivery;
5
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
class ClientFactory
9
{
10 1
    public function build(string $apiKey, string $workspace, $options = array()): Client
11
    {
12 1
        $resolver = new OptionsResolver();
13 1
        $this->configureOptions($resolver);
14 1
        $resolvedOptions = $resolver->resolve($options);
15
16
        // Merge guzzle options and override with our own
17 1
        $options = $resolvedOptions['guzzle_options'];
18 1
        $options = array_merge($options, [
19 1
            'base_uri' => $resolvedOptions['host'],
20 1
            'debug' => $resolvedOptions['debug'],
21
            'headers' => [
22 1
                'Authorization' => "Bearer " . $apiKey,
23
            ],
24
        ]);
25
26 1
        $guzzleClient = new \GuzzleHttp\Client($options);
27
28 1
        return new Client($guzzleClient, $workspace);
29
    }
30
31 1
    public function configureOptions(OptionsResolver $resolver)
32
    {
33 1
        $resolver->setDefaults([
34 1
            'host' => 'https://delivery.seams-api.com/',
35
            'debug' => false,
36
            'guzzle_options' => [],
37
        ]);
38 1
    }
39
}
40