Completed
Push — master ( 632b02...a06c21 )
by Mario
06:25
created

TaskService::createTask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 16
loc 16
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 2
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 View Code Duplication
    public function createTask(\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...
26
    {
27
        $request = new CreateTask(
28
            array(
29
                'data' => $this->extractDataFromObject($task),
30
            )
31
        );
32
33
        $response = $this->delegate($request);
34
35
        return new TaskResponse(
36
            array(
37
                'task' => $this->hydrateDataFromArrayToObject($response, new Task())
38
            )
39
        );
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 View Code Duplication
    public function getTask($taskId)
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...
46
    {
47
        $request = new GetTask(
48
            array(
49
                'taskId' => $this->validate($taskId),
50
            )
51
        );
52
53
        $response = $this->delegate($request);
54
55
        return new TaskResponse(
56
            array(
57
                'task' => $this->hydrateDataFromArrayToObject($response, new Task())
58
            )
59
        );
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 View Code Duplication
    public function updateTask($taskId, \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...
66
    {
67
        $request = new UpdateTask(
68
            array(
69
                'taskId' => $this->validate($taskId),
70
                'data' => $task,
71
            )
72
        );
73
74
        $response = $this->delegate($request);
75
76
        return new TaskResponse(
77
            array(
78
                'task' => $this->hydrateDataFromArrayToObject($response, new Task())
79
            )
80
        );
81
    }
82
83
    /**
84
     * @inheritDoc
85
     */
86
    public function deleteTask($taskId)
87
    {
88
        $request = new DeleteTask(
89
            array(
90
                'taskId' => $this->validate($taskId),
91
            )
92
        );
93
94
        return $this->delegate($request);
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100
    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
        $request = new BulkUpdateTasks(
103
            array(
104
                'taskIds' => $taskIds,
105
                'data' => $task,
106
            )
107
        );
108
109
        $response = $this->delegate($request);
110
111
        $tasks = array();
112
        foreach ($response->body as $task) {
113
            $tasks[] = $this->hydrator->hydrate($task, new Task());
114
        }
115
116
        return new TasksResponse(
117
            array(
118
                'tasks' => $tasks,
119
            )
120
        );
121
    }
122
123
    /**
124
     * @inheritDoc
125
     */
126
    public function deleteMultipleTasks($taskIds)
127
    {
128
        $request = new BulkDeleteTasks(
129
            array(
130
                'taskIds' => $taskIds,
131
            )
132
        );
133
134
        return $this->delegate($request);
135
    }
136
137
}
138