BigQueryClientFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createForConfig() 0 11 1
A configureCache() 0 8 1
1
<?php
2
3
namespace SchulzeFelix\BigQuery;
4
5
use Google\Cloud\BigQuery\BigQueryClient;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Cache;
8
use Symfony\Component\Cache\Adapter\Psr16Adapter;
9
10
class BigQueryClientFactory
11
{
12
    public static function createForConfig(array $bigQueryConfig): BigQueryClient
13
    {
14
        $clientConfig = array_merge([
15
            'projectId' => $bigQueryConfig['project_id'],
16
            'keyFilePath' => $bigQueryConfig['application_credentials'],
17
            'keyFile' => Arr::get($bigQueryConfig, 'keyFile', null),
18
            'authCache' => self::configureCache($bigQueryConfig['auth_cache_store']),
19
        ], Arr::get($bigQueryConfig, 'client_options', []));
20
21
        return new BigQueryClient($clientConfig);
22
    }
23
24
    protected static function configureCache($cacheStore)
25
    {
26
        $store = Cache::store($cacheStore);
27
28
        $cache = new Psr16Adapter($store);
29
30
        return $cache;
31
    }
32
}
33