TimeEntryService   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 15

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 0 Features 2
Metric Value
wmc 12
c 9
b 0
f 2
lcom 1
cbo 15
dl 0
loc 168
ccs 67
cts 67
cp 1
rs 9.1666

10 Methods

Rating   Name   Duplication   Size   Complexity  
A createTimeEntry() 0 10 1
A startTimeEntry() 0 10 1
A stopTimeEntry() 0 10 1
A getTimeEntry() 0 10 1
A getRunningTimeEntry() 0 6 1
A updateTimeEntry() 0 11 1
A deleteTimeEntry() 0 10 1
A getTimeEntriesStartedInDateRange() 0 22 2
B bulkUpdateTimeEntriesTags() 0 27 2
A delegateHydrateAndReturnResponse() 0 10 1
1
<?php
2
3
namespace Marek\Toggable\Service\TimeEntry;
4
5
use Marek\Toggable\API\Http\Request\RequestInterface;
6
use Marek\Toggable\API\Http\Request\TimeEntry\BulkUpdateTimeEntriesTags;
7
use Marek\Toggable\API\Http\Request\TimeEntry\CreateTimeEntry;
8
use Marek\Toggable\API\Http\Request\TimeEntry\DeleteTimeEntry;
9
use Marek\Toggable\API\Http\Request\TimeEntry\GetRunningTimeEntry;
10
use Marek\Toggable\API\Http\Request\TimeEntry\GetTimeEntriesStartedInDateRange;
11
use Marek\Toggable\API\Http\Request\TimeEntry\GetTimeEntry;
12
use Marek\Toggable\API\Http\Request\TimeEntry\StartTimeEntry;
13
use Marek\Toggable\API\Http\Request\TimeEntry\StopTimeEntry;
14
use Marek\Toggable\API\Http\Request\TimeEntry\UpdateTimeEntry;
15
use Marek\Toggable\API\Http\Response\TimeEntry\TimeEntries;
16
use Marek\Toggable\API\Http\Response\TimeEntry\TimeEntry as TimeEntryResponse;
17
use Marek\Toggable\API\Toggl\Values\TimeEntry\TimeEntry;
18
use Marek\Toggable\Service\AbstractService;
19
20
/**
21
 * Class TimeEntryService
22
 * @package Marek\Toggable\Service\TimeEntry
23
 */
24
class TimeEntryService extends AbstractService implements \Marek\Toggable\API\Toggl\TimeEntryServiceInterface
25
{
26
    /**
27
     * @inheritDoc
28
     */
29 1
    public function createTimeEntry(\Marek\Toggable\API\Toggl\Values\TimeEntry\TimeEntry $timeEntry)
30
    {
31 1
        $request = new CreateTimeEntry(
32
            array(
33 1
                'data' => $this->extractDataFromObject($timeEntry),
34
            )
35 1
        );
36
37 1
      return $this->delegateHydrateAndReturnResponse($request);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 1
    public function startTimeEntry(\Marek\Toggable\API\Toggl\Values\TimeEntry\TimeEntry $timeEntry)
44
    {
45 1
        $request = new StartTimeEntry(
46
            array(
47 1
                'data' => $this->extractDataFromObject($timeEntry),
48
            )
49 1
        );
50
51 1
        return $this->delegateHydrateAndReturnResponse($request);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57 2
    public function stopTimeEntry($timeEntryId)
58
    {
59 2
        $request = new StopTimeEntry(
60
            array(
61 2
                'timeEntryId' => $this->validate($timeEntryId),
62
            )
63 1
        );
64
65 1
        return $this->delegateHydrateAndReturnResponse($request);
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 2
    public function getTimeEntry($timeEntryId)
72
    {
73 2
        $request = new GetTimeEntry(
74
            array(
75 2
                'timeEntryId' => $this->validate($timeEntryId),
76
            )
77 1
        );
78
79 1
        return $this->delegateHydrateAndReturnResponse($request);
80
    }
81
82
    /**
83
     * @inheritDoc
84
     */
85 1
    public function getRunningTimeEntry()
86
    {
87 1
        $request = new GetRunningTimeEntry();
88
89 1
        return $this->delegateHydrateAndReturnResponse($request);
90
    }
91
92
    /**
93
     * @inheritDoc
94
     */
95 2
    public function updateTimeEntry($timeEntryId, \Marek\Toggable\API\Toggl\Values\TimeEntry\TimeEntry $timeEntry)
96
    {
97 2
        $request = new UpdateTimeEntry(
98
            array(
99 2
                'timeEntryId'   => $this->validate($timeEntryId),
100 1
                'data'          => $this->extractDataFromObject($timeEntry),
101
            )
102 1
        );
103
104 1
        return $this->delegateHydrateAndReturnResponse($request);
105
    }
106
107
    /**
108
     * @inheritDoc
109
     */
110 2
    public function deleteTimeEntry($timeEntryId)
111
    {
112 2
        $request = new DeleteTimeEntry(
113
            array(
114 2
                'timeEntryId'   => $this->validate($timeEntryId),
115
            )
116 1
        );
117
118 1
        return $this->delegate($request);
119
    }
120
121
    /**
122
     * @inheritDoc
123
     */
124 1
    public function getTimeEntriesStartedInDateRange(\DateTime $startDate, \DateTime $endDate)
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...
125
    {
126 1
        $request = new GetTimeEntriesStartedInDateRange(
127
            array(
128 1
                'startDate' => $startDate,
129 1
                'endDate'   => $endDate,
130
            )
131 1
        );
132
133 1
        $response = $this->delegate($request);
134
135 1
        $entries = array();
136 1
        foreach ($response->body as $entry) {
137 1
            $entries[] = $this->hydrator->hydrate($entry, new TimeEntry());
138 1
        }
139
140 1
        return new TimeEntries(
141
            array(
142 1
                'timeEntries' => $entries,
143
            )
144 1
        );
145
    }
146
147
    /**
148
     * @inheritDoc
149
     */
150 1
    public function bulkUpdateTimeEntriesTags(array $timeEntries, array $tags, $tagAction = \Marek\Toggable\API\Toggl\Values\TagAction::ADD)
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...
151
    {
152
        $data = array(
153 1
            'tags' => $tags,
154
            'tag_action' => $tagAction
155 1
        );
156
157 1
        $request = new BulkUpdateTimeEntriesTags(
158
            array(
159 1
                'timeEntryIds'   => $timeEntries,
160 1
                'data'           => $data,
161
            )
162 1
        );
163
164 1
        $response = $this->delegate($request);
165
166 1
        $entries = array();
167 1
        foreach ($response->body['data'] as $entry) {
168 1
            $entries[] = $this->hydrator->hydrate($entry, new TimeEntry());
169 1
        }
170
171 1
        return new TimeEntries(
172
            array(
173 1
                'timeEntries' => $entries,
174
            )
175 1
        );
176
    }
177
178
    /**
179
     * @inheritdoc
180
     */
181 6
    protected function delegateHydrateAndReturnResponse(RequestInterface $request)
182
    {
183 6
        $response = $this->delegate($request);
184
185 6
        return new TimeEntryResponse(
186
            array(
187 6
                'timeEntry' => $this->hydrateDataFromArrayToObject($response, new TimeEntry()),
188
            )
189 6
        );
190
    }
191
}
192