Completed
Push — master ( d5972d...c20ba1 )
by Mario
03:00
created

ProjectService   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 84.62%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
c 4
b 0
f 0
lcom 1
cbo 7
dl 0
loc 105
ccs 33
cts 39
cp 0.8462
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getProjectData() 0 16 3
A createProject() 0 10 1
A updateProject() 0 10 1
A deleteProject() 0 16 3
A getProjectUsers() 0 3 1
A getProjectTasks() 0 3 1
A deleteMultipleProjects() 0 3 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\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\UpdateProject;
10
use Marek\Toggable\API\Http\Response\Project\Project as ProjectResponse;
11
use Marek\Toggable\API\Toggl\Values\Project\Project;
12
use Marek\Toggable\Service\AbstractService;
13
14
/**
15
 * Class ProjectService
16
 * @package Marek\Toggable\Service\Project
17
 */
18
class ProjectService extends AbstractService implements \Marek\Toggable\API\Toggl\ProjectServiceInterface
19
{
20
    /**
21
     * @inheritDoc
22
     */
23 2
    public function getProjectData($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...
24
    {
25 2
        if (empty($projectId) || !is_int($projectId)) {
26 1
            throw new InvalidArgumentException(
27 1
                sprintf('$projectId argument not provided in %s', get_class($this))
28 1
            );
29
        }
30
31 1
        $request = new GetProject(
32
            array(
33 1
                'projectId' => $projectId,
34
            )
35 1
        );
36
37 1
        return $this->delegateHydrateAndReturnResponse($request);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 1
    public function createProject(\Marek\Toggable\API\Toggl\Values\Project\Project $project)
44
    {
45 1
        $request = new CreateProject(
46
            array(
47 1
                'data' => $this->extractDataFromObject($project),
48
            )
49 1
        );
50
51 1
        return $this->delegateHydrateAndReturnResponse($request);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57 1
    public function updateProject(\Marek\Toggable\API\Toggl\Values\Project\Project $project)
58
    {
59 1
        $request = new UpdateProject(
60
            array(
61 1
                'data' => $this->extractDataFromObject($project),
62
            )
63 1
        );
64
65 1
        return $this->delegateHydrateAndReturnResponse($request);
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 2
    public function deleteProject($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...
72
    {
73 2
        if (empty($projectId) || !is_int($projectId)) {
74 1
            throw new InvalidArgumentException(
75 1
                sprintf('$projectId argument not provided in %s', get_class($this))
76 1
            );
77
        }
78
79 1
        $request = new DeleteProject(
80
            array(
81 1
                'projectId' => $projectId,
82
            )
83 1
        );
84
85 1
        return $this->delegate($request);
86
    }
87
88
    /**
89
     * @inheritDoc
90
     */
91
    public function getProjectUsers($projectId) {
92
        // TODO: Implement getProjectUsers() method.
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98
    public function getProjectTasks($projectId) {
99
        // TODO: Implement getProjectTasks() method.
100
    }
101
102
    /**
103
     * @inheritDoc
104
     */
105
    public function deleteMultipleProjects(array $projectIds) {
106
        // TODO: Implement deleteMultipleProjects() method.
107
    }
108
109
    /**
110
     * @inheritDoc
111
     */
112 3
    protected function delegateHydrateAndReturnResponse(\Marek\Toggable\API\Http\Request\RequestInterface $request)
113
    {
114 3
        $response = $this->delegate($request);
115
116 3
        return new ProjectResponse(
117
            array(
118 3
                'project' => $this->hydrateDataFromArrayToObject($response, new Project()),
119
            )
120 3
        );
121
    }
122
}
123