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

GoalsClient::getGoal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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