WorkspaceUsersService::inviteUsers()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
ccs 20
cts 20
cp 1
rs 8.8571
cc 3
eloc 18
nc 4
nop 2
crap 3
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 1
        );
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 1
        }
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 1
            );
48 1
        }
49
50 1
        return new Invitation(
51
            array(
52 1
                'workspaceUsers' => $workspaceUsers,
53 1
                'notifications' => $notifications,
54
            )
55 1
        );
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 1
        );
69
70 1
        $response = $this->delegate($request);
71
72 1
        return new WorkspaceUser(
73
            array(
74 1
                'workspaceUser' => $this->hydrateDataFromArrayToObject($response, new User())
75 1
            )
76 1
        );
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 1
        );
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 1
        );
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 1
        }
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
                'workspaceUsers' => $workspaceUsers,
114
            )
115 1
        );
116
    }
117
}
118