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

ProjectService::delegateHydrateAndReturnResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 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