Passed
Branch 4 (f3d551)
by Simon
03:46
created

GoogleClientService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getClient() 0 3 1
A setClient() 0 3 1
A __construct() 0 11 2
1
<?php
2
namespace Firesphere\GoogleAPI\Services;
3
4
use Google_Client;
5
use Google_Exception;
6
use Google_Service_Analytics;
7
use LogicException;
8
use SilverStripe\Control\Director;
9
10
class GoogleClientService
11
{
12
    /**
13
     * @var Google_Client
14
     */
15
    protected $client;
16
17
    /**
18
     * GoogleClientService constructor.
19
     * @throws LogicException
20
     * @throws Google_Exception
21
     */
22
    public function __construct()
23
    {
24
        if (!getenv('SS_ANALYTICS_KEY')) {
25
            throw new LogicException('No analytics API set up');
26
        }
27
28
        $client = new Google_Client();
29
        $client->setAuthConfig(Director::baseFolder() . DIRECTORY_SEPARATOR . getenv('SS_ANALYTICS_KEY'));
30
        $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
31
32
        $this->setClient($client);
33
    }
34
35
    /**
36
     * @return Google_Client
37
     */
38
    public function getClient()
39
    {
40
        return $this->client;
41
    }
42
43
    /**
44
     * @param Google_Client $client
45
     */
46
    public function setClient($client)
47
    {
48
        $this->client = $client;
49
    }
50
}
51