Completed
Pull Request — dev (#25)
by nonanerz
18:41 queued 10:41
created

GoogleClientFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 6
dl 0
loc 45
ccs 0
cts 22
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createCalendar() 0 8 1
A createClient() 0 9 1
A aclRule() 0 11 1
A getCredentials() 0 9 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