Completed
Push — master ( 7696c0...144c46 )
by Felix
04:21
created

BigQueryClientFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

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