Completed
Push — master ( b6aec9...26ec5a )
by Nassif
03:18
created

Client   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 1
A checkAuthConfigFile() 0 6 2
1
<?php
2
3
namespace Nikaia\TranslationSheet\Client;
4
5
class Client extends \Google_Client
6
{
7
    /**
8
     * Return configured google api client.
9
     *
10
     * @param $authConfigFile
11
     * @param $applicationName
12
     *
13
     * @return Client
14
     */
15
    public static function create($authConfigFile, $applicationName)
16
    {
17
        self::checkAuthConfigFile($authConfigFile);
18
19
        $client = new static();
20
        $client->setAuthConfigFile($authConfigFile);
21
        $client->setApplicationName($applicationName);
22
        $client->setScopes(\Google_Service_Sheets::SPREADSHEETS);
23
24
        return $client;
25
    }
26
27
    /**
28
     * Throw an exception if google service config file is not found.
29
     *
30
     * @param $authConfigFile
31
     * @throws \Exception
32
     */
33
    private static function checkAuthConfigFile($authConfigFile)
34
    {
35
        if (!file_exists($authConfigFile)) {
36
            throw new \Exception('You must specify a valid google service authentication file. Given file ['.$authConfigFile.'] does not exists');
37
        }
38
    }
39
}
40