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

BigQueryClientFactory::configureCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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