ProjectService   A
last analyzed

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