Completed
Push — master ( 5832ba...311c48 )
by nonanerz
11s
created

GoogleCalendarManager::getEventList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Services;
4
5
use AppBundle\Entity\DTO\DtoEvent;
6
7
class GoogleCalendarManager
8
{
9
    private $calendar;
10
11
    public function __construct(GoogleClientFactory $factory)
12
    {
13
        $this->calendar = $factory->createCalendar('user', 'owner');
14
    }
15
16 View Code Duplication
    public function createEvent(DtoEvent $dtoEvent, $data = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
        $description = ['user' => $dtoEvent->getUser(), 'description' => $dtoEvent->getDescription()];
19
        $event = new \Google_Service_Calendar_Event();
20
        $event->setSummary($dtoEvent->getSummary());
21
        $event->setDescription(json_encode($description));
22
        $event->setLocation($dtoEvent->getLocation());
23
        $event->setVisibility('public');
24
        $start = new \Google_Service_Calendar_EventDateTime();
25
        $start->setDateTime($dtoEvent->getStart());
26
        $event->setStart($start);
27
        $end = new \Google_Service_Calendar_EventDateTime();
28
        $end->setDateTime($dtoEvent->getEnd());
29
        $event->setEnd($end);
30
31
        return $this->calendar->events->insert('primary', $event, $data);
32
    }
33
34
    public function getEventList($query = [])
35
    {
36
        $events = $this->calendar
37
            ->events
38
            ->listEvents('primary', $query);
39
40
        return [
41
            'pageToken' => $events->getNextPageToken(),
42
            'events' => $events->getItems(),
43
        ];
44
    }
45
46
    public function getEventById($id)
47
    {
48
        $event = $this->calendar->events->get('primary', $id);
49
        if ($event->status == 'cancelled') {
50
            return;
51
        }
52
53
        return $event;
54
    }
55
56
    public function deleteEvent($id)
57
    {
58
        return $this->calendar->events->delete('primary', $id);
59
    }
60
61 View Code Duplication
    public function editEvent(DtoEvent $dtoEvent, $id, $data = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $description = ['user' => $dtoEvent->getUser(), 'description' => $dtoEvent->getDescription()];
64
        $event = $this->getEventById($id);
65
        $event->setSummary($dtoEvent->getSummary());
66
        $event->setDescription(json_encode($description));
67
        $event->setLocation($dtoEvent->getLocation());
68
        $event->setVisibility('public');
69
70
        $start = new \Google_Service_Calendar_EventDateTime();
71
        $start->setDateTime($dtoEvent->getStart());
72
        $event->setStart($start);
73
74
        $end = new \Google_Service_Calendar_EventDateTime();
75
        $end->setDateTime($dtoEvent->getEnd());
76
        $event->setEnd($end);
77
78
        return $this->calendar->events->patch('primary', $id, $event, $data);
79
    }
80
81
    public function clear()
82
    {
83
        $events = $this->calendar
84
            ->events
85
            ->listEvents('primary')
86
            ->getItems();
87
88
        foreach ($events as $event) {
89
            $this->deleteEvent($event->getId());
90
        }
91
    }
92
}
93