Completed
Pull Request — dev (#26)
by nonanerz
04:08
created

GoogleCalendarManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 49.33 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 8
lcom 2
cbo 6
dl 37
loc 75
ccs 0
cts 56
cp 0
rs 10
c 3
b 0
f 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createEvent() 19 19 1
A getEventList() 0 7 1
A getEventById() 0 4 1
A deleteEvent() 0 4 1
A editEvent() 18 18 1
A clear() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace AppBundle\Services;
4
5
use AppBundle\Entity\DTO\DtoEvent;
6
7
class GoogleCalendarManager implements GoogleCalendarInterface
8
{
9
    private $calendar;
10
11
    public function __construct(GoogleClientFactory $factory)
12
    {
13
        $this->calendar = $factory->createCalendar('default', 'reader');
14
    }
15
16 View Code Duplication
    public function createEvent(DtoEvent $dtoEvent)
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
20
        $event->setSummary($dtoEvent->getSummary());
21
        $event->setDescription($dtoEvent->getDescription());
22
        $event->setLocation($dtoEvent->getLocation());
23
        $event->setVisibility('public');
24
25
        $start = new \Google_Service_Calendar_EventDateTime();
26
        $start->setDateTime($dtoEvent->getStart());
27
        $event->setStart($start);
28
29
        $end = new \Google_Service_Calendar_EventDateTime();
30
        $end->setDateTime($dtoEvent->getEnd());
31
        $event->setEnd($end);
32
33
        return $this->calendar->events->insert('primary', $event);
34
    }
35
36
    public function getEventList($calendarId = 'primary')
37
    {
38
        return $this->calendar
39
            ->events
40
            ->listEvents($calendarId)
41
            ->getItems();
42
    }
43
44
    public function getEventById($id)
45
    {
46
        return $this->calendar->events->get('primary', $id);
47
    }
48
49
    public function deleteEvent($id)
50
    {
51
        return $this->calendar->events->delete('primary', $id);
52
    }
53
54 View Code Duplication
    public function editEvent(DtoEvent $dtoEvent, $id)
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...
55
    {
56
        $event = $this->getEventById($id);
57
        $event->setSummary($dtoEvent->getSummary());
58
        $event->setDescription($dtoEvent->getDescription());
59
        $event->setLocation($dtoEvent->getLocation());
60
        $event->setVisibility('public');
61
62
        $start = new \Google_Service_Calendar_EventDateTime();
63
        $start->setDateTime($dtoEvent->getStart());
64
        $event->setStart($start);
65
66
        $end = new \Google_Service_Calendar_EventDateTime();
67
        $end->setDateTime($dtoEvent->getEnd());
68
        $event->setEnd($end);
69
70
        return $this->calendar->events->patch('primary', $id, $event);
71
    }
72
73
    public function clear()
74
    {
75
        $events = $this->getEventList();
76
77
        foreach ($events as $event) {
78
            $this->deleteEvent($event->getId());
79
        }
80
    }
81
}
82