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

Client::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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