Client   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setScope() 0 10 4
A __construct() 0 6 1
A getGoogleServiceSheets() 0 3 1
1
<?php
2
3
namespace REverse\GSheets;
4
5
class Client
6
{
7
    const DRIVE = \Google_Service_Sheets::DRIVE;
8
    const DRIVE_FILE = \Google_Service_Sheets::DRIVE_FILE;
9
    const DRIVE_READONLY = \Google_Service_Sheets::DRIVE_READONLY;
10
    const SPREADSHEETS = \Google_Service_Sheets::SPREADSHEETS;
11
    const SPREADSHEETS_READONLY = \Google_Service_Sheets::SPREADSHEETS_READONLY;
12
    const DEFAULT_SCOPES = [
13
        self::DRIVE,
14
        self::DRIVE_FILE,
15
        self::DRIVE_READONLY,
16
        self::SPREADSHEETS,
17
        self::SPREADSHEETS_READONLY,
18
    ];
19
20
    /**
21
     * @var \Google_Client
22
     */
23
    private $googleClient;
24
25
    /**
26
     * @var \Google_Service_Sheets
27
     */
28
    private $googleServiceSheets;
29
30
    /**
31
     * @param \Google_Client $googleClient
32
     * @param string $scope
33
     */
34
    public function __construct(\Google_Client $googleClient, $scope = null)
35
    {
36
        $this->googleClient = $googleClient;
37
        $this->setScope($scope);
38
39
        $this->googleServiceSheets = new \Google_Service_Sheets($this->googleClient);
40
    }
41
42
    private function setScope($scope)
43
    {
44
        if ($scope !== null && ! in_array($scope, self::DEFAULT_SCOPES)) {
45
            throw new \InvalidArgumentException(sprintf("%s is not a valid scope", $scope));
46
        }
47
48
        if ($scope === null) {
49
            $this->googleClient->setScopes(self::DEFAULT_SCOPES);
50
        } else {
51
            $this->googleClient->addScope($scope);
52
        }
53
    }
54
55
    /**
56
     * @return \Google_Service_Sheets
57
     */
58
    public function getGoogleServiceSheets()
59
    {
60
        return $this->googleServiceSheets;
61
    }
62
}
63