Completed
Push — master ( 70ca3b...6984b9 )
by Mario
03:10
created

ProjectService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 13

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 119
wmc 9
lcom 1
cbo 13
ccs 44
cts 44
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getProjectData() 0 10 1
A createProject() 0 10 1
A updateProject() 0 10 1
A deleteProject() 0 10 1
A getProjectUsers() 0 21 2
A getProjectTasks() 0 4 1
A deleteMultipleProjects() 0 10 1
A delegateHydrateAndReturnResponse() 0 10 1
1
<?php
2
3
namespace Marek\Toggable\Service\Project;
4
5
use InvalidArgumentException;
6
use Marek\Toggable\API\Http\Request\Project\BulkDeleteProjects;
7
use Marek\Toggable\API\Http\Request\Project\CreateProject;
8
use Marek\Toggable\API\Http\Request\Project\DeleteProject;
9
use Marek\Toggable\API\Http\Request\Project\GetProject;
10
use Marek\Toggable\API\Http\Request\Project\GetProjectUsers;
11
use Marek\Toggable\API\Http\Request\Project\UpdateProject;
12
use Marek\Toggable\API\Http\Response\Project\Project as ProjectResponse;
13
use Marek\Toggable\API\Http\Response\ProjectUsers\ProjectUser;
14
use Marek\Toggable\API\Toggl\Values\Project\Project;
15
use Marek\Toggable\Service\AbstractService;
16
use Marek\Toggable\API\Http\Response\ProjectUsers\ProjectUsers as ProjectUsersResponse;
17
18
/**
19
 * Class ProjectService
20
 * @package Marek\Toggable\Service\Project
21
 */
22
class ProjectService extends AbstractService implements \Marek\Toggable\API\Toggl\ProjectServiceInterface
23
{
24
    /**
25
     * @inheritDoc
26
     */
27 2
    public function getProjectData($projectId)
28
    {
29 2
        $request = new GetProject(
30
            array(
31 2
                'projectId' => $this->validate($projectId),
32
            )
33 1
        );
34
35 1
        return $this->delegateHydrateAndReturnResponse($request);
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41 1
    public function createProject(\Marek\Toggable\API\Toggl\Values\Project\Project $project)
42
    {
43 1
        $request = new CreateProject(
44
            array(
45 1
                'data' => $this->extractDataFromObject($project),
46
            )
47 1
        );
48
49 1
        return $this->delegateHydrateAndReturnResponse($request);
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55 1
    public function updateProject(\Marek\Toggable\API\Toggl\Values\Project\Project $project)
56
    {
57 1
        $request = new UpdateProject(
58
            array(
59 1
                'data' => $this->extractDataFromObject($project),
60
            )
61 1
        );
62
63 1
        return $this->delegateHydrateAndReturnResponse($request);
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69 2
    public function deleteProject($projectId)
70
    {
71 2
        $request = new DeleteProject(
72
            array(
73 2
                'projectId' => $this->validate($projectId),
74
            )
75 1
        );
76
77 1
        return $this->delegate($request);
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83 2
    public function getProjectUsers($projectId)
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...
84
    {
85 2
        $request = new GetProjectUsers(
86
            array(
87 2
                'projectId' => $this->validate($projectId),
88
            )
89 1
        );
90
91 1
        $response = $this->delegate($request);
92
93 1
        $projectUsers = array();
94 1
        foreach ($response->body as $projectUser) {
95 1
            $projectUsers[] = $this->hydrator->hydrate($projectUser, new ProjectUser());
96 1
        }
97
98 1
        return new ProjectUsersResponse(
99
            array(
100 1
                'projectUsers' => $projectUsers,
101
            )
102 1
        );
103
    }
104
105
    /**
106
     * @inheritDoc
107
     */
108 1
    public function getProjectTasks($projectId)
109
    {
110 1
        throw new \RuntimeException('Not implemented');
111
    }
112
113
    /**
114
     * @inheritDoc
115
     */
116 1
    public function deleteMultipleProjects(array $projectIds)
117
    {
118 1
        $request = new BulkDeleteProjects(
119
            array(
120 1
                'projectsIds' => $projectIds,
121
            )
122 1
        );
123
124 1
        return $this->delegate($request);
125
    }
126
127
    /**
128
     * @inheritDoc
129
     */
130 3
    protected function delegateHydrateAndReturnResponse(\Marek\Toggable\API\Http\Request\RequestInterface $request)
131
    {
132 3
        $response = $this->delegate($request);
133
134 3
        return new ProjectResponse(
135
            array(
136 3
                'project' => $this->hydrateDataFromArrayToObject($response, new Project()),
137
            )
138 3
        );
139
    }
140
}
141