Completed
Pull Request — master (#30)
by nonanerz
04:14
created

GoogleClientFactory::createCalendar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
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