CouchDbConnector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 35
ccs 0
cts 8
cp 0
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A connect() 0 31 6
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/couchdb-adapter project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\CouchDb\Connector;
10
11
use Daikon\Dbal\Connector\ConnectorInterface;
12
use Daikon\Dbal\Connector\ProvidesConnector;
13
use GuzzleHttp\Client;
14
15
final class CouchDbConnector implements ConnectorInterface
16
{
17
    use ProvidesConnector;
18
19
    protected function connect(): Client
20
    {
21
        $clientOptions = [
22
            'base_uri' => sprintf(
23
                '%s://%s:%s',
24
                $this->settings['scheme'],
25
                $this->settings['host'],
26
                $this->settings['port']
27
            )
28
        ];
29
30
        if (isset($this->settings['debug'])) {
31
            $clientOptions['debug'] = $this->settings['debug'] === true;
32
        }
33
34
        if (isset($this->settings['user']) && !empty($this->settings['user'])
35
            && isset($this->settings['password']) && !empty($this->settings['password'])
36
        ) {
37
            $clientOptions['auth'] = [
38
                $this->settings['user'],
39
                $this->settings['password'],
40
                $this->settings['authentication'] ?? 'basic'
41
            ];
42
        }
43
44
        $clientOptions['headers'] = [
45
            'Accept' => 'application/json',
46
            'Content-Type' => 'application/json'
47
        ];
48
49
        return new Client($clientOptions);
50
    }
51
}
52