Completed
Push — master ( 6984b9...88f0a8 )
by Mario
02:54
created

WorkspaceService::getWorkspaceUsers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

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