Completed
Pull Request — master (#12)
by
unknown
01:42
created

Ads::get()   F

Complexity

Conditions 12
Paths 2048

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 2.9163
c 0
b 0
f 0
cc 12
nc 2048
nop 13

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * @author Dmitry Gladyshev <[email protected]>
4
 * @date 26/08/2016 13:51
5
 */
6
7
namespace Yandex\Direct\Service;
8
9
use Yandex\Direct\Exception\Exception;
10
use Yandex\Direct\Service;
11
12
/**
13
 * Class Ads
14
 * @package Yandex\Direct\Service
15
 */
16
final class Ads extends Service
17
{
18
    /**
19
     * @param $Ads
20
     * @return array
21
     * @throws Exception
22
     *
23
     * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/add-docpage/
24
     */
25
    public function add($Ads)
26
    {
27
        return $this->request([
28
            'method' => 'add',
29
            'params' => [
30
                'Ads' => $Ads
31
            ]
32
        ]);
33
    }
34
35
    /**
36
     * @param $Ads
37
     * @return array
38
     * @throws Exception
39
     *
40
     * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/update-docpage/
41
     */
42
    public function update($Ads)
43
    {
44
        return $this->request([
45
            'method' => 'update',
46
            'params' => [
47
                'Ads' => $Ads
48
            ]
49
        ]);
50
    }
51
52
    /**
53
     * @param $SelectionCriteria
54
     * @return array
55
     * @throws Exception
56
     *
57
     * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/delete-docpage/
58
     */
59
    public function delete($SelectionCriteria)
60
    {
61
        return $this->request([
62
            'method' => 'delete',
63
            'params' => [
64
                'SelectionCriteria' => $SelectionCriteria
65
            ]
66
        ]);
67
    }
68
69
    /**
70
     * @param $SelectionCriteria
71
     * @return array
72
     * @throws Exception
73
     *
74
     * https://tech.yandex.ru/direct/doc/ref-v5/ads/suspend-docpage/
75
     */
76
    public function suspend($SelectionCriteria)
77
    {
78
        return $this->request([
79
            'method' => 'suspend',
80
            'params' => [
81
                'SelectionCriteria' => $SelectionCriteria
82
            ]
83
        ]);
84
    }
85
86
    /**
87
     * @param $SelectionCriteria
88
     * @return array
89
     * @throws Exception
90
     *
91
     * https://tech.yandex.ru/direct/doc/ref-v5/ads/resume-docpage/
92
     */
93
    public function resume($SelectionCriteria)
94
    {
95
        return $this->request([
96
            'method' => 'resume',
97
            'params' => [
98
                'SelectionCriteria' => $SelectionCriteria
99
            ]
100
        ]);
101
    }
102
103
    /**
104
     * @param $SelectionCriteria
105
     * @return array
106
     * @throws Exception
107
     *
108
     * https://tech.yandex.ru/direct/doc/ref-v5/ads/archive-docpage/
109
     */
110
    public function archive($SelectionCriteria)
111
    {
112
        return $this->request([
113
            'method' => 'archive',
114
            'params' => [
115
                'SelectionCriteria' => $SelectionCriteria
116
            ]
117
        ]);
118
    }
119
120
    /**
121
     * @param $SelectionCriteria
122
     * @return array
123
     * @throws Exception
124
     *
125
     * https://tech.yandex.ru/direct/doc/ref-v5/ads/unarchive-docpage/
126
     */
127
    public function unarchive($SelectionCriteria)
128
    {
129
        return $this->request([
130
            'method' => 'unarchive',
131
            'params' => [
132
                'SelectionCriteria' => $SelectionCriteria
133
            ]
134
        ]);
135
    }
136
137
    /**
138
     * @param $SelectionCriteria
139
     * @return array
140
     * @throws Exception
141
     *
142
     * https://tech.yandex.ru/direct/doc/ref-v5/ads/moderate-docpage/
143
     */
144
    public function moderate($SelectionCriteria)
145
    {
146
        return $this->request([
147
            'method' => 'moderate',
148
            'params' => [
149
                'SelectionCriteria' => $SelectionCriteria
150
            ]
151
        ]);
152
    }
153
154
155
    /**
156
     * Возвращает параметры объявлений, отвечающих заданным критериям.
157
     *
158
     * @param $SelectionCriteria
159
     * @param $FieldNames
160
     * @param $TextAdFieldNames
161
     * @param $MobileAppAdFieldNames
162
     * @param $DynamicTextAdFieldNames
163
     * @param $TextImageAdFieldNames
164
     * @param $MobileAppImageAdFieldNames
165
     * @param $TextAdBuilderAdFieldNames
166
     * @param $MobileAppAdBuilderAdFieldNames
167
     * @param $CpcVideoAdBuilderAdFieldNames
168
     * @param $CpmBannerAdBuilderAdFieldNames
169
     * @param $CpmVideoAdBuilderAdFieldNames
170
     * @param $Page
171
     * @return array
172
     * @throws Exception
173
     *
174
     * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/get-docpage/
175
     */
176
    public function get(
177
        $SelectionCriteria,
178
        $FieldNames,
179
        $TextAdFieldNames = null,
180
        $MobileAppAdFieldNames = null,
181
        $DynamicTextAdFieldNames = null,
182
        $TextImageAdFieldNames = null,
183
        $MobileAppImageAdFieldNames = null,
184
        $TextAdBuilderAdFieldNames = null,
185
        $MobileAppAdBuilderAdFieldNames = null,
186
        $CpcVideoAdBuilderAdFieldNames = null,
187
        $CpmBannerAdBuilderAdFieldNames = null,
188
        $CpmVideoAdBuilderAdFieldNames = null,
189
        $Page = null
190
    ) {
191
        $params = [
192
            'SelectionCriteria' => $SelectionCriteria,
193
            'FieldNames' => $FieldNames
194
        ];
195
196
        if ($TextAdFieldNames) {
197
            $params['TextAdFieldNames'] = $TextAdFieldNames;
198
        }
199
200
        if ($MobileAppAdFieldNames) {
201
            $params['MobileAppAdFieldNames'] = $MobileAppAdFieldNames;
202
        }
203
204
        if ($DynamicTextAdFieldNames) {
205
            $params['DynamicTextAdFieldNames'] = $DynamicTextAdFieldNames;
206
        }
207
208
        if ($TextImageAdFieldNames) {
209
            $params['TextImageAdFieldNames'] = $TextImageAdFieldNames;
210
        }
211
212
        if ($MobileAppImageAdFieldNames) {
213
            $params['MobileAppImageAdFieldNames'] = $MobileAppImageAdFieldNames;
214
        }
215
216
        if ($TextAdBuilderAdFieldNames) {
217
            $params['TextAdBuilderAdFieldNames'] = $TextAdBuilderAdFieldNames;
218
        }
219
220
        if ($MobileAppAdBuilderAdFieldNames) {
221
            $params['MobileAppAdBuilderAdFieldNames'] = $MobileAppAdBuilderAdFieldNames;
222
        }
223
224
        if ($CpcVideoAdBuilderAdFieldNames) {
225
            $params['CpcVideoAdBuilderAdFieldNames'] = $CpcVideoAdBuilderAdFieldNames;
226
        }
227
228
        if ($CpmBannerAdBuilderAdFieldNames) {
229
            $params['CpmBannerAdBuilderAdFieldNames'] = $CpmBannerAdBuilderAdFieldNames;
230
        }
231
232
        if ($CpmVideoAdBuilderAdFieldNames) {
233
            $params['CpmVideoAdBuilderAdFieldNames'] = $CpmVideoAdBuilderAdFieldNames;
234
        }
235
236
        if ($Page) {
237
            $params['Page'] = $Page;
238
        }
239
240
        return $this->request([
241
            'method' => 'get',
242
            'params' => $params
243
        ]);
244
    }
245
}
246