Completed
Pull Request — dev (#25)
by nonanerz
14:03
created

GoogleClientFactory::aclRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
namespace AppBundle\Services;
4
5
class GoogleClientFactory
6
{
7
    private $path;
8
9
    public function createCalendar($scopeType, $role)
10
    {
11
        $calendar = new \Google_Service_Calendar($this->createClient());
12
13
        $calendar->acl->insert('primary', $this->aclRule($scopeType, $role));
14
15
        return $calendar;
16
    }
17
18
    private function createClient()
19
    {
20
        $client = new \Google_Client();
21
        $client->setScopes([\Google_Service_Calendar::CALENDAR]);
22
        $path = $this->getCredentials();
23
        $client->setAuthConfig($path);
24
25
        return $client;
26
    }
27
28
    private function aclRule($scopeType, $role)
29
    {
30
        $scope = new \Google_Service_Calendar_AclRuleScope();
31
        $scope->setType($scopeType);
32
33
        $rule = new \Google_Service_Calendar_AclRule();
34
        $rule->setRole($role);
35
        $rule->setScope($scope);
36
37
        return $rule;
38
    }
39
40
    private function getCredentials()
41
    {
42
        if (!file_exists(__DIR__.'/../../../app/config/credentials/credentials.json')) {
43
            throw new \Google_Exception('Credentials is not found');
44
        }
45
        $this->path = __DIR__.'/../../../app/config/credentials/credentials.json';
46
47
        return $this->path;
48
    }
49
}
50