Completed
Push — master ( 427e7d...a0cbad )
by Dmitriy
8s
created

GoalsClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 91
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 5
c 3
b 2
f 0
lcom 0
cbo 6
dl 91
loc 91
ccs 24
cts 24
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getGoals() 7 7 1
A getGoal() 7 7 1
A addGoal() 7 7 1
A updateGoal() 7 7 1
A deleteGoal() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Yandex\Metrica\Management;
3
4
/**
5
 * Class GoalsClient
6
 *
7
 * @category Yandex
8
 * @package Metrica
9
 *
10
 * @author   Alexander Khaylo <[email protected]>
11
 * @created  13.02.14 17:39
12
 */
13 View Code Duplication
class GoalsClient extends ManagementClient
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
16
    /**
17
     * Get counter goals
18
     *
19
     * @see http://api.yandex.ru/metrika/doc/beta/management/goals/goals.xml
20
     *
21
     * @param int $counterId
22
     * @return Models\Goals
23
     */
24 1
    public function getGoals($counterId)
25
    {
26 1
        $resource = 'counter/' . $counterId . '/goals';
27 1
        $response = $this->sendGetRequest($resource);
28 1
        $goalResponse = new Models\GetGoalsResponse($response);
29 1
        return $goalResponse->getGoals();
30
    }
31
32
33
    /**
34
     * Add goal to counter
35
     *
36
     * @see http://api.yandex.ru/metrika/doc/beta/management/goals/addgoal.xml
37
     *
38
     * @param int $counterId
39
     * @param Models\Goal $goal
40
     * @return Models\Goal
41
     */
42 1
    public function addGoal($counterId, Models\Goal $goal)
43
    {
44 1
        $resource = 'counter/' . $counterId . '/goals';
45 1
        $response = $this->sendPostRequest($resource, ["goal" => $goal->toArray()]);
46 1
        $goalResponse = new Models\AddGoalResponse($response);
47 1
        return $goalResponse->getGoal();
48
    }
49
50
51
    /**
52
     * Get counter goal
53
     *
54
     * @see http://api.yandex.ru/metrika/doc/beta/management/goals/goal.xml
55
     *
56
     * @param int $id
57
     * @param int $counterId
58
     * @return Models\Goal
59
     */
60 1
    public function getGoal($id, $counterId)
61
    {
62 1
        $resource = 'counter/' . $counterId . '/goal/' . $id;
63 1
        $response = $this->sendGetRequest($resource);
64 1
        $goalResponse = new Models\GetGoalResponse($response);
65 1
        return $goalResponse->getGoal();
66
    }
67
68
69
    /**
70
     * Update counter goal
71
     *
72
     * @see http://api.yandex.ru/metrika/doc/beta/management/goals/editgoal.xml
73
     *
74
     * @param int $id
75
     * @param int $counterId
76
     * @param Models\Goal $goal
77
     * @return Models\Goal
78
     */
79 1
    public function updateGoal($id, $counterId, Models\Goal $goal)
80
    {
81 1
        $resource = 'counter/' . $counterId . '/goal/' . $id;
82 1
        $response = $this->sendPutRequest($resource, ["goal" => $goal->toArray()]);
83 1
        $goalResponse = new Models\UpdateGoalResponse($response);
84 1
        return $goalResponse->getGoal();
85
    }
86
87
88
    /**
89
     * Delete counter goal
90
     *
91
     * @see http://api.yandex.ru/metrika/doc/ref/reference/del-counter-goal.xml
92
     *
93
     * @param int $id
94
     * @param int $counterId
95
     * @return array
96
     */
97 1
    public function deleteGoal($id, $counterId)
98
    {
99 1
        $resource = 'counter/' . $counterId . '/goal/' . $id;
100 1
        $response = $this->sendDeleteRequest($resource);
101 1
        return $response;
102
    }
103
}
104