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

TaskService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 118
Duplicated Lines 41.53 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 0%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createTask() 16 16 1
A getTask() 16 16 1
A updateTask() 17 17 1
A deleteTask() 0 10 1
A updateMultipleTasks() 0 22 2
A deleteMultipleTasks() 0 10 1

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 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