DynamoDbClientService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 23
c 1
b 0
f 0
dl 0
loc 73
ccs 22
cts 25
cp 0.88
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributeFilter() 0 3 1
A getClient() 0 17 3
A __construct() 0 5 1
A getDebugOptions() 0 11 2
A getMarshaler() 0 3 1
1
<?php
2
3
namespace BaoPham\DynamoDb;
4
5
use Aws\DynamoDb\DynamoDbClient;
6
use Aws\DynamoDb\Marshaler;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Facades\Log;
9
10
class DynamoDbClientService implements DynamoDbClientInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $clients;
16
17
    /**
18
     * @var \Aws\DynamoDb\Marshaler
19
     */
20
    protected $marshaler;
21
22
    /**
23
     * @var \BaoPham\DynamoDb\EmptyAttributeFilter
24
     */
25
    protected $attributeFilter;
26
27 145
    public function __construct(Marshaler $marshaler, EmptyAttributeFilter $filter)
28
    {
29 145
        $this->marshaler = $marshaler;
30 145
        $this->attributeFilter = $filter;
31 145
        $this->clients = [];
32 145
    }
33
34
    /**
35
     * @return \Aws\DynamoDb\DynamoDbClient
36
     */
37 132
    public function getClient($connection = null)
38
    {
39 132
        $connection = $connection ?: config('dynamodb.default');
40
41 132
        if (isset($this->clients[$connection])) {
42 120
            return $this->clients[$connection];
43
        }
44
45 132
        $config = config("dynamodb.connections.$connection", []);
46 132
        $config['version'] = '2012-08-10';
47 132
        $config['debug'] = $this->getDebugOptions(Arr::get($config, 'debug'));
48
49 132
        $client = new DynamoDbClient($config);
50
51 132
        $this->clients[$connection] = $client;
52
53 132
        return $client;
54
    }
55
56
    /**
57
     * @return \Aws\DynamoDb\Marshaler
58
     */
59 138
    public function getMarshaler()
60
    {
61 138
        return $this->marshaler;
62
    }
63
64
    /**
65
     * @return \BaoPham\DynamoDb\EmptyAttributeFilter
66
     */
67 131
    public function getAttributeFilter()
68
    {
69 131
        return $this->attributeFilter;
70
    }
71
72 132
    protected function getDebugOptions($debug = false)
73
    {
74 132
        if ($debug === true) {
75
            $logfn = function ($msg) {
76
                Log::info($msg);
77
            };
78
79
            return ['logfn' => $logfn];
80
        }
81
82 132
        return $debug;
83
    }
84
}
85