Api   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getClient() 0 25 2
1
<?php
2
/**
3
 * @link      https://dukt.net/analytics/
4
 * @copyright Copyright (c) 2022, Dukt
5
 * @license   https://github.com/dukt/analytics/blob/master/LICENSE.md
6
 */
7
8
namespace dukt\analytics\base;
9
10
use craft\base\Component;
11
use Google_Client;
12
use dukt\analytics\Plugin as Analytics;
13
14
abstract class Api extends Component
15
{
16
    /**
17
     * Returns a Google client.
18
     *
19
     * @return Google_Client
20
     * @throws \yii\base\InvalidConfigException
21
     */
22
    protected function getClient()
23
    {
24
        $token = Analytics::$plugin->getOauth()->getToken();
25
26
        if ($token) {
27
            // make token compatible with Google Client
28
29
            $arrayToken = json_encode([
30
                'created' => 0,
31
                'access_token' => $token->getToken(),
32
                'expires_in' => $token->getExpires(),
33
            ]);
34
35
            // client
36
            $client = new Google_Client();
37
            $client->setApplicationName('Google+ PHP Starter Application');
38
            $client->setClientId('clientId');
39
            $client->setClientSecret('clientSecret');
40
            $client->setRedirectUri('redirectUri');
41
            $client->setAccessToken($arrayToken);
42
43
            return $client;
44
        }
45
46
        return null;
47
    }
48
}
49