Completed
Pull Request — master (#30)
by
unknown
03:43
created

GoogleCalendarManager::getEventList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
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
        $event = new \Google_Service_Calendar_Event();
19
        $event->setSummary($dtoEvent->getSummary());
20
        $event->setDescription($dtoEvent->getDescription());
21
        $event->setLocation($dtoEvent->getLocation());
22
        $event->setVisibility('public');
23
        $start = new \Google_Service_Calendar_EventDateTime();
24
        $start->setDateTime($dtoEvent->getStart());
25
        $event->setStart($start);
26
        $end = new \Google_Service_Calendar_EventDateTime();
27
        $end->setDateTime($dtoEvent->getEnd());
28
        $event->setEnd($end);
29
30
        return $this->calendar->events->insert('primary', $event, $data);
31
    }
32
33
    public function getEventList($query = [])
34
    {
35
        $events = $this->calendar
36
            ->events
37
            ->listEvents('primary', $query);
38
        return [
39
            'nextPageToken' => $events->getNextPageToken(),
40
            'events' => $events->getItems()
41
        ];
42
    }
43
44
    public function getEventById($id)
45
    {
46
        $event = $this->calendar->events->get('primary', $id);
47
        if ($event->status == 'cancelled') {
48
            return;
49
        }
50
        return $event;
51
    }
52
53
    public function deleteEvent($id)
54
    {
55
        return $this->calendar->events->delete('primary', $id);
56
    }
57
58 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...
59
    {
60
        $event = $this->getEventById($id);
61
        $event->setSummary($dtoEvent->getSummary());
62
        $event->setDescription($dtoEvent->getDescription());
63
        $event->setLocation($dtoEvent->getLocation());
64
        $event->setVisibility('public');
65
66
        $start = new \Google_Service_Calendar_EventDateTime();
67
        $start->setDateTime($dtoEvent->getStart());
68
        $event->setStart($start);
69
70
        $end = new \Google_Service_Calendar_EventDateTime();
71
        $end->setDateTime($dtoEvent->getEnd());
72
        $event->setEnd($end);
73
74
        return $this->calendar->events->patch('primary', $id, $event, $data);
75
    }
76
77
    public function clear()
78
    {
79
        $events = $this->calendar
80
            ->events
81
            ->listEvents('primary')
82
            ->getItems();
83
84
        foreach ($events as $event) {
85
            $this->deleteEvent($event->getId());
86
        }
87
    }
88
}
89