WorkspaceService   C
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 197
Duplicated Lines 18.78 %

Coupling/Cohesion

Components 1
Dependencies 24

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 0 Features 3
Metric Value
wmc 14
c 9
b 0
f 3
lcom 1
cbo 24
dl 37
loc 197
ccs 93
cts 93
cp 1
rs 5.238

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getWorkspaces() 0 17 2
A getWorkspace() 18 18 1
A getWorkspaceUsers() 0 21 2
A getWorkspaceClients() 0 21 2
A getWorkspaceTasks() 0 22 2
A getWorkspaceTags() 0 21 2
A updateWorkspace() 19 19 1
B getWorkspaceProjects() 0 24 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 Marek\Toggable\Service\Workspace;
4
5
use Marek\Toggable\API\Http\Request\Workspace\UpdateWorkspace;
6
use Marek\Toggable\API\Http\Request\Workspace\Workspaces as WorkspacesRequest;
7
use Marek\Toggable\API\Http\Request\Workspace\Workspace as WorkspaceRequest;
8
use Marek\Toggable\API\Http\Request\Workspace\WorkspaceUsers as WorkspaceUsersRequest;
9
use Marek\Toggable\API\Http\Request\Workspace\WorkspaceClients as WorkspaceClientsRequest;
10
use Marek\Toggable\API\Http\Request\Workspace\WorkspaceProjects as WorkspaceProjectsRequest;
11
use Marek\Toggable\API\Http\Request\Workspace\WorkspaceTasks as WorkspaceTasksRequest;
12
use Marek\Toggable\API\Http\Request\Workspace\WorkspaceTags as WorkspaceTagsRequest;
13
use Marek\Toggable\API\Http\Response\Workspace\Workspaces as WorkspacesResponse;
14
use Marek\Toggable\API\Http\Response\Workspace\Workspace as WorkspaceResponse;
15
use Marek\Toggable\API\Http\Response\Workspace\WorkspaceUsers as WorkspaceUsersResponse;
16
use Marek\Toggable\API\Http\Response\Workspace\WorkspaceClients as WorkspaceClientsResponse;
17
use Marek\Toggable\API\Http\Response\Workspace\WorkspaceProjects as WorkspaceProjectsResponse;
18
use Marek\Toggable\API\Http\Response\Workspace\WorkspaceTasks as WorkspaceTasksResponse;
19
use Marek\Toggable\API\Http\Response\Workspace\WorkspaceTags as WorkspaceTagsResponse;
20
use Marek\Toggable\API\Toggl\Values\Client\Client;
21
use Marek\Toggable\API\Toggl\Values\Project\Project;
22
use Marek\Toggable\API\Toggl\Values\Tag\Tag;
23
use Marek\Toggable\API\Toggl\Values\Task\Task;
24
use Marek\Toggable\API\Toggl\Values\User\User;
25
use Marek\Toggable\API\Toggl\Values\Workspace\Workspace;
26
use Marek\Toggable\API\Toggl\Values\Activity;
27
use Marek\Toggable\Service\AbstractService;
28
29
/**
30
 * Class WorkspaceService
31
 * @package Marek\Toggable\Service\Client
32
 */
33
class WorkspaceService extends AbstractService implements \Marek\Toggable\API\Toggl\WorkspaceServiceInterface
34
{
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function getWorkspaces()
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...
39
    {
40 1
        $request = new WorkspacesRequest();
41
42 1
        $response = $this->delegate($request);
43
        
44 1
        $workspaces = array();
45 1
        foreach($response->body as $workspace) {
46 1
            $workspaces[] = $this->hydrator->hydrate($workspace, new Workspace());
47 1
        }
48
49 1
        return new WorkspacesResponse(
50
            array(
51 1
                'workspaces' => $workspaces,
52
            )
53 1
        );
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2 View Code Duplication
    public function getWorkspace($workspaceId)
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...
60
    {
61 2
        $request = new WorkspaceRequest(
62
            array(
63 2
                'workspaceId' => $this->validate($workspaceId),
64
            )
65 1
        );
66
67 1
        $response = $this->delegate($request);
68
69 1
        $workspace = $this->hydrator->hydrate($response->body['data'], new Workspace());
70
71 1
        return new WorkspaceResponse(
72
            array(
73 1
                'workspace' => $workspace,
74
            )
75 1
        );
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 2
    public function getWorkspaceUsers($workspaceId)
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...
82
    {
83 2
        $request = new WorkspaceUsersRequest(
84
            array(
85 2
                'workspaceId' => $this->validate($workspaceId),
86
            )
87 1
        );
88
89 1
        $response = $this->delegate($request);
90
91 1
        $users = array();
92 1
        foreach($response->body as $user) {
93 1
            $users[] = $this->hydrator->hydrate($user, new User());
94 1
        }
95
96 1
        return new WorkspaceUsersResponse(
97
            array(
98 1
                'users' => $users,
99
            )
100 1
        );
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 2
    public function getWorkspaceClients($workspaceId)
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...
107
    {
108 2
        $request = new WorkspaceClientsRequest(
109
            array(
110 2
                'workspaceId' => $this->validate($workspaceId),
111
            )
112 1
        );
113
114 1
        $response = $this->delegate($request);
115
116 1
        $clients = array();
117 1
        foreach($response->body as $client) {
118 1
            $clients[] = $this->hydrator->hydrate($client, new Client());
119 1
        }
120
121 1
        return new WorkspaceClientsResponse(
122
            array(
123 1
                'clients' => $clients,
124
            )
125 1
        );
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131 2
    public function getWorkspaceProjects($workspaceId, $active = Activity::ACTIVE, $actualHours = 'false', $onlyTemplates = 'false')
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...
132
    {
133 2
        $request = new WorkspaceProjectsRequest(
134
            array(
135 2
                'workspaceId'   => $this->validate($workspaceId),
136 1
                'active'        => $active,
137 1
                'actualHours'   => $actualHours,
138 1
                'onlyTemplates' => $onlyTemplates,
139
            )
140 1
        );
141
142 1
        $response = $this->delegate($request);
143
144 1
        $projects = array();
145 1
        foreach($response->body as $project) {
146 1
            $projects[] = $this->hydrator->hydrate($project, new Project());
147 1
        }
148
149 1
        return new WorkspaceProjectsResponse(
150
            array(
151 1
                'projects' => $projects,
152
            )
153 1
        );
154
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159 2
    public function getWorkspaceTasks($workspaceId, $active = Activity::ACTIVE)
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...
160
    {
161 2
        $request = new WorkspaceTasksRequest(
162
            array(
163 2
                'workspaceId'   => $this->validate($workspaceId),
164 1
                'active'        => $active,
165
            )
166 1
        );
167
168 1
        $response = $this->delegate($request);
169
170 1
        $tasks = array();
171 1
        foreach($response->body as $task) {
172 1
            $tasks[] = $this->hydrator->hydrate($task, new Task());
173 1
        }
174
175 1
        return new WorkspaceTasksResponse(
176
            array(
177 1
                'tasks' => $tasks,
178
            )
179 1
        );
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185 2
    public function getWorkspaceTags($workspaceId)
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...
186
    {
187 2
        $request = new WorkspaceTagsRequest(
188
            array(
189 2
                'workspaceId' => $this->validate($workspaceId),
190
            )
191 1
        );
192
193 1
        $response = $this->delegate($request);
194
195 1
        $tags = array();
196 1
        foreach($response->body as $tag) {
197 1
            $tags[] = $this->hydrator->hydrate($tag, new Tag());
198 1
        }
199
200 1
        return new WorkspaceTagsResponse(
201
            array(
202 1
                'tags' => $tags,
203
            )
204 1
        );
205
    }
206
207
    /**
208
     * {@inheritdoc}
209
     */
210 2 View Code Duplication
    public function updateWorkspace($workspaceId, Workspace $workspace)
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...
211
    {
212 2
        $request = new UpdateWorkspace(
213
            array(
214 2
                'workspaceId' => $this->validate($workspaceId),
215 1
                'data' => $this->extractDataFromObject($workspace),
216
            )
217 1
        );
218
219 1
        $response = $this->delegate($request);
220
221 1
        $workspace = $this->hydrator->hydrate($response->body['data'], new Workspace());
222
223 1
        return new WorkspaceResponse(
224
            array(
225 1
                'workspace' => $workspace,
226
            )
227 1
        );
228
    }
229
}
230