Client::checkAuthConfigFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0625
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 20
    public static function create($authConfigFile, $applicationName)
16
    {
17 20
        self::checkAuthConfigFile($authConfigFile);
18
19 20
        $client = new static();
20 20
        $client->setAuthConfig($authConfigFile);
21 20
        $client->setApplicationName($applicationName);
22 20
        $client->setScopes(\Google_Service_Sheets::SPREADSHEETS);
23
24 20
        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 20
    private static function checkAuthConfigFile($authConfigFile)
34
    {
35 20
        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 20
    }
39
}
40