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

GrantsClient::deleteGrant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 6
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
namespace Yandex\Metrica\Management;
3
4
/**
5
 * Class GrantsClient
6
 *
7
 * @category Yandex
8
 * @package Metrica
9
 *
10
 * @author   Alexander Khaylo <[email protected]>
11
 * @created  13.02.14 17:43
12
 */
13 View Code Duplication
class GrantsClient 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 grants
18
     *
19
     * @see http://api.yandex.ru/metrika/doc/beta/management/grants/grants.xml
20
     *
21
     * @param int $counterId
22
     * @param array $params
23
     * @return array
24
     */
25 1
    public function getGrants($counterId, $params = [])
26
    {
27 1
        $resource = 'counter/' . $counterId . '/grants';
28 1
        $response = $this->sendGetRequest($resource, $params);
29 1
        $grantResponse = new Models\GetGrantsResponse($response);
30 1
        return $grantResponse->getGrants();
31
    }
32
33
34
    /**
35
     * Add grant to counter
36
     *
37
     * @see http://api.yandex.ru/metrika/doc/beta/management/grants/addgrant.xml
38
     *
39
     * @param int $counterId
40
     * @param Models\Grant $grant
41
     * @return Models\Grant
42
     */
43 1
    public function addGrant($counterId, Models\Grant $grant)
44
    {
45 1
        $resource = 'counter/' . $counterId . '/grants';
46 1
        $response = $this->sendPostRequest($resource, ["grant" => $grant->toArray()]);
47 1
        $grantResponse = new Models\AddGrantResponse($response);
48 1
        return $grantResponse->getGrant();
49
    }
50
51
52
    /**
53
     * Get counter grant
54
     *
55
     * @see http://api.yandex.ru/metrika/doc/beta/management/grants/grantold.xml
56
     *
57
     * @param int $counterId
58
     * @param string $userLogin
59
     * @param array $params
60
     * @return Models\Grant
61
     */
62 1
    public function getGrant($counterId, $userLogin, $params = [])
63
    {
64 1
        $resource = 'counter/' . $counterId . '/grant/' . $userLogin;
65 1
        $response = $this->sendGetRequest($resource, $params);
66 1
        $grantResponse = new Models\GetGrantResponse($response);
67 1
        return $grantResponse->getGrant();
68
    }
69
70
71
    /**
72
     * Update counter grant
73
     *
74
     * @see http://api.yandex.ru/metrika/doc/beta/management/grants/editgrantold.xml
75
     *
76
     * @param int $counterId
77
     * @param string $userLogin
78
     * @param Models\Grant $grant
79
     * @return Models\Grant
80
     */
81 1
    public function updateGrant($counterId, $userLogin, Models\Grant $grant)
82
    {
83 1
        $resource = 'counter/' . $counterId . '/grant/' . $userLogin;
84 1
        $response = $this->sendPutRequest($resource, ["grant" => $grant->toArray()]);
85 1
        $grantResponse = new Models\UpdateGrantResponse($response);
86 1
        return $grantResponse->getGrant();
87
    }
88
89
90
    /**
91
     * Delete counter grant
92
     *
93
     * @see http://api.yandex.ru/metrika/doc/ref/reference/del-counter-grant.xml
94
     *
95
     * @param int $counterId
96
     * @param string $userLogin
97
     * @return array
98
     */
99 1
    public function deleteGrant($counterId, $userLogin)
100
    {
101 1
        $resource = 'counter/' . $counterId . '/grant/' . $userLogin;
102 1
        $response = $this->sendDeleteRequest($resource);
103 1
        return $response;
104
    }
105
}
106