Completed
Pull Request — master (#30)
by
unknown
05:34
created

GoogleClientFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 40
ccs 0
cts 27
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createCalendar() 0 8 1
A createClient() 0 8 1
A aclRule() 0 12 1
A __construct() 0 4 1
1
<?php
2
3
namespace AppBundle\Services;
4
5
class GoogleClientFactory
6
{
7
    private $path;
8
9
    public function __construct($path)
10
    {
11
        $this->path = $path;
12
    }
13
14
    public function createCalendar($scopeType, $role)
15
    {
16
        $calendar = new \Google_Service_Calendar($this->createClient());
17
18
        $calendar->acl->insert('primary', $this->aclRule($scopeType, $role));
19
20
        return $calendar;
21
    }
22
23
    private function createClient()
24
    {
25
        $client = new \Google_Client();
26
        $client->setScopes([\Google_Service_Calendar::CALENDAR]);
27
        $client->setAuthConfig($this->path);
28
29
        return $client;
30
    }
31
32
    private function aclRule($scopeType, $role)
33
    {
34
        $scope = new \Google_Service_Calendar_AclRuleScope();
35
        $scope->setType($scopeType);
36
        $scope->setValue('[email protected]');
37
38
        $rule = new \Google_Service_Calendar_AclRule();
39
        $rule->setRole($role);
40
        $rule->setScope($scope);
41
42
        return $rule;
43
    }
44
}
45