Completed
Push — master ( 6c0f1a...ae9b29 )
by Mario
02:55
created

WorkspaceUsersService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
B inviteUsers() 0 32 3
A updateWorkspaceUser() 0 17 1
A deleteWorkspaceUser() 0 10 1
A getWorkspaceUsers() 0 21 2
1
<?php
2
3
namespace Marek\Toggable\Service\WorkspaceUsers;
4
5
use Marek\Toggable\API\Http\Request\WorkspaceUsers\DeleteWorkspaceUser;
6
use Marek\Toggable\API\Http\Request\WorkspaceUsers\GetWorkspaceUsers;
7
use Marek\Toggable\API\Http\Request\WorkspaceUsers\InviteUserToWorkspace;
8
use Marek\Toggable\API\Http\Request\WorkspaceUsers\UpdateWorkspaceUser;
9
use Marek\Toggable\API\Http\Response\WorkspaceUsers\Invitation;
10
use Marek\Toggable\API\Http\Response\WorkspaceUsers\WorkspaceUser;
11
use Marek\Toggable\API\Http\Response\WorkspaceUsers\WorkspaceUsers;
12
use Marek\Toggable\API\Toggl\Values\Notification;
13
use Marek\Toggable\API\Toggl\Values\Workspace\User;
14
use Marek\Toggable\Service\AbstractService;
15
16
/**
17
 * Class WorkspaceUsersService
18
 * @package Marek\Toggable\Service\WorkspaceUsers
19
 */
20
class WorkspaceUsersService extends AbstractService implements \Marek\Toggable\API\Toggl\WorkspaceUsersServiceInterface
21
{
22
    /**
23
     * @inheritDoc
24
     */
25 2
    public function inviteUsers($workspaceId, array $emails)
26
    {
27 2
        $request = new InviteUserToWorkspace(
28
            array(
29 2
                'workspaceId' => $this->validate($workspaceId),
30 1
                'data' => $emails,
31
            )
32
        );
33
34 1
        $response = $this->delegate($request);
35
36 1
        $workspaceUsers = array();
37 1
        foreach($response->body['data'] as $workspaceUser) {
38 1
            $workspaceUsers[] = $this->hydrator->hydrate($workspaceUser, new User());
39
        }
40
41 1
        $notifications = array();
42 1
        foreach($response->body['notifications'] as $notification) {
43 1
            $notifications[] = new Notification(
44
                array(
45 1
                    'message' => $notification,
46
                )
47
            );
48
        }
49
50 1
        return new Invitation(
51
            array(
52 1
                'workspaceUsers' => $workspaceUsers,
53 1
                'notifications' => $notifications,
54
            )
55
        );
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61 2
    public function updateWorkspaceUser($workspaceUserId, \Marek\Toggable\API\Toggl\Values\Workspace\User $user)
62
    {
63 2
        $request = new UpdateWorkspaceUser(
64
            array(
65 2
                'workspaceUserId' => $this->validate($workspaceUserId),
66 1
                'data' => $this->extractDataFromObject($user),
67
            )
68
        );
69
70 1
        $response = $this->delegate($request);
71
72 1
        return new WorkspaceUser(
73
            array(
74 1
                'workspaceUser' => $this->hydrateDataFromArrayToObject($response, new User())
75
            )
76
        );
77
    }
78
79
    /**
80
     * @inheritDoc
81
     */
82 2
    public function deleteWorkspaceUser($workspaceUserId)
83
    {
84 2
        $request = new DeleteWorkspaceUser(
85
            array(
86 2
                'workspaceUserId' => $this->validate($workspaceUserId),
87
            )
88
        );
89
90 1
        return $this->delegate($request);
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96 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...
97
    {
98 2
        $request = new GetWorkspaceUsers(
99
            array(
100 2
                'workspaceId' => $this->validate($workspaceId),
101
            )
102
        );
103
104 1
        $response = $this->delegate($request);
105
106 1
        $workspaceUsers = array();
107 1
        foreach($response->body as $workspaceUser) {
108 1
            $workspaceUsers[] = $this->hydrator->hydrate($workspaceUser, new User());
109
        }
110
111 1
        return new WorkspaceUsers(
112
            array(
0 ignored issues
show
Unused Code introduced by
The call to WorkspaceUsers::__construct() has too many arguments starting with array('workspaceUsers' => $workspaceUsers).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
113 1
                'workspaceUsers' => $workspaceUsers,
114
            )
115
        );
116
    }
117
}
118