Completed
Push — master ( 19c31c...2dfe88 )
by Mario
04:59 queued 02:02
created

TaskService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 7
c 4
b 0
f 1
lcom 1
cbo 12
dl 0
loc 118
ccs 51
cts 51
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createTask() 0 16 1
A getTask() 0 16 1
A updateTask() 0 17 1
A deleteTask() 0 10 1
A updateMultipleTasks() 0 22 2
A deleteMultipleTasks() 0 10 1
1
<?php
2
3
namespace Marek\Toggable\Service\Task;
4
5
use Marek\Toggable\API\Http\Request\Task\BulkDeleteTasks;
6
use Marek\Toggable\API\Http\Request\Task\BulkUpdateTasks;
7
use Marek\Toggable\API\Http\Request\Task\CreateTask;
8
use Marek\Toggable\API\Http\Request\Task\DeleteTask;
9
use Marek\Toggable\API\Http\Request\Task\GetTask;
10
use Marek\Toggable\API\Http\Request\Task\UpdateTask;
11
use Marek\Toggable\API\Http\Response\Task\Task as TaskResponse;
12
use Marek\Toggable\API\Http\Response\Task\Tasks as TasksResponse;
13
use Marek\Toggable\API\Toggl\Values\Task\Task;
14
use Marek\Toggable\Service\AbstractService;
15
16
/**
17
 * Class TaskService
18
 * @package Marek\Toggable\Service\Task
19
 */
20
class TaskService extends AbstractService implements \Marek\Toggable\API\Toggl\TaskServiceInterface
21
{
22
    /**
23
     * @inheritDoc
24
     */
25 1
    public function createTask(\Marek\Toggable\API\Toggl\Values\Task\Task $task)
26
    {
27 1
        $request = new CreateTask(
28
            array(
29 1
                'data' => $this->extractDataFromObject($task),
30
            )
31 1
        );
32
33 1
        $response = $this->delegate($request);
34
35 1
        return new TaskResponse(
36
            array(
37 1
                'task' => $this->hydrateDataFromArrayToObject($response, new Task())
38 1
            )
39 1
        );
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 2
    public function getTask($taskId)
46
    {
47 2
        $request = new GetTask(
48
            array(
49 2
                'taskId' => $this->validate($taskId),
50
            )
51 1
        );
52
53 1
        $response = $this->delegate($request);
54
55 1
        return new TaskResponse(
56
            array(
57 1
                'task' => $this->hydrateDataFromArrayToObject($response, new Task())
58 1
            )
59 1
        );
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 2
    public function updateTask($taskId, \Marek\Toggable\API\Toggl\Values\Task\Task $task)
66
    {
67 2
        $request = new UpdateTask(
68
            array(
69 2
                'taskId' => $this->validate($taskId),
70 1
                'data' => $this->extractDataFromObject($task),
71
            )
72 1
        );
73
74 1
        $response = $this->delegate($request);
75
76 1
        return new TaskResponse(
77
            array(
78 1
                'task' => $this->hydrateDataFromArrayToObject($response, new Task())
79 1
            )
80 1
        );
81
    }
82
83
    /**
84
     * @inheritDoc
85
     */
86 2
    public function deleteTask($taskId)
87
    {
88 2
        $request = new DeleteTask(
89
            array(
90 2
                'taskId' => $this->validate($taskId),
91
            )
92 1
        );
93
94 1
        return $this->delegate($request);
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100 1
    public function updateMultipleTasks($taskIds, \Marek\Toggable\API\Toggl\Values\Task\Task $task)
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...
101
    {
102 1
        $request = new BulkUpdateTasks(
103
            array(
104 1
                'taskIds' => $taskIds,
105 1
                'data' => $this->extractDataFromObject($task),
106
            )
107 1
        );
108
109 1
        $response = $this->delegate($request);
110
111 1
        $tasks = array();
112 1
        foreach ($response->body as $task) {
113 1
            $tasks[] = $this->hydrator->hydrate($task, new Task());
114 1
        }
115
116 1
        return new TasksResponse(
117
            array(
118 1
                'tasks' => $tasks,
119
            )
120 1
        );
121
    }
122
123
    /**
124
     * @inheritDoc
125
     */
126 1
    public function deleteMultipleTasks($taskIds)
127
    {
128 1
        $request = new BulkDeleteTasks(
129
            array(
130 1
                'taskIds' => $taskIds,
131
            )
132 1
        );
133
134 1
        return $this->delegate($request);
135
    }
136
137
}
138