Total Complexity | 70 |
Total Lines | 567 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Filter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Filter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class Filter |
||
13 | { |
||
14 | /** |
||
15 | * @param string $clientName |
||
16 | * |
||
17 | * @return string |
||
18 | * |
||
19 | * @throws ClientException |
||
20 | */ |
||
21 | public static function clientName($clientName) |
||
22 | { |
||
23 | if (!is_string($clientName)) { |
||
|
|||
24 | throw new ClientException( |
||
25 | 'Client Name must be a string', |
||
26 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | if ($clientName === '') { |
||
31 | throw new ClientException( |
||
32 | 'Client Name cannot be empty', |
||
33 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
34 | ); |
||
35 | } |
||
36 | |||
37 | return strtolower($clientName); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string $name |
||
42 | * |
||
43 | * @return string |
||
44 | * |
||
45 | * @throws ClientException |
||
46 | */ |
||
47 | public static function name($name) |
||
48 | { |
||
49 | if (!is_string($name)) { |
||
50 | throw new ClientException( |
||
51 | 'Name must be a string', |
||
52 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | if ($name === '') { |
||
57 | throw new ClientException( |
||
58 | 'Name cannot be empty', |
||
59 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | return $name; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param string $value |
||
68 | * |
||
69 | * @return string |
||
70 | * |
||
71 | * @throws ClientException |
||
72 | */ |
||
73 | public static function value($value) |
||
74 | { |
||
75 | if (!is_numeric($value) && !is_string($value)) { |
||
76 | throw new ClientException( |
||
77 | 'Value must be a string or int', |
||
78 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
79 | ); |
||
80 | } |
||
81 | |||
82 | if ($value === '') { |
||
83 | throw new ClientException( |
||
84 | 'Value cannot be empty', |
||
85 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | return $value; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @param $accessKeyId |
||
94 | * @param $accessKeySecret |
||
95 | * |
||
96 | * @return string |
||
97 | * |
||
98 | * @throws ClientException |
||
99 | */ |
||
100 | public static function AccessKey($accessKeyId, $accessKeySecret) |
||
101 | { |
||
102 | if (is_numeric($accessKeyId)) { |
||
103 | $accessKeyId = (string)$accessKeyId; |
||
104 | } |
||
105 | |||
106 | if (is_numeric($accessKeySecret)) { |
||
107 | $accessKeySecret = (string)$accessKeySecret; |
||
108 | } |
||
109 | |||
110 | if (!is_string($accessKeyId)) { |
||
111 | throw new ClientException( |
||
112 | 'AccessKey ID must be a string', |
||
113 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | if ($accessKeyId === '') { |
||
118 | throw new ClientException( |
||
119 | 'AccessKey ID cannot be empty', |
||
120 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
121 | ); |
||
122 | } |
||
123 | |||
124 | if (!is_string($accessKeySecret)) { |
||
125 | throw new ClientException( |
||
126 | 'AccessKey Secret must be a string', |
||
127 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | if ($accessKeySecret === '') { |
||
132 | throw new ClientException( |
||
133 | 'AccessKey Secret cannot be empty', |
||
134 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
135 | ); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @param string $host |
||
141 | * |
||
142 | * @return string |
||
143 | * |
||
144 | * @throws ClientException |
||
145 | */ |
||
146 | public static function host($host) |
||
147 | { |
||
148 | if (!is_string($host)) { |
||
149 | throw new ClientException( |
||
150 | 'Host must be a string', |
||
151 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
152 | ); |
||
153 | } |
||
154 | |||
155 | if ($host === '') { |
||
156 | throw new ClientException( |
||
157 | 'Host cannot be empty', |
||
158 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | return $host; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @param string $product |
||
167 | * |
||
168 | * @return string |
||
169 | * |
||
170 | * @throws ClientException |
||
171 | */ |
||
172 | public static function product($product) |
||
173 | { |
||
174 | if (!is_string($product)) { |
||
175 | throw new ClientException( |
||
176 | 'Product must be a string', |
||
177 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
178 | ); |
||
179 | } |
||
180 | |||
181 | if ($product === '') { |
||
182 | throw new ClientException( |
||
183 | 'Product cannot be empty', |
||
184 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
185 | ); |
||
186 | } |
||
187 | |||
188 | return $product; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param string $regionId |
||
193 | * |
||
194 | * @return string |
||
195 | * |
||
196 | * @throws ClientException |
||
197 | */ |
||
198 | public static function regionId($regionId) |
||
199 | { |
||
200 | if (!is_string($regionId)) { |
||
201 | throw new ClientException( |
||
202 | 'Region ID must be a string', |
||
203 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
204 | ); |
||
205 | } |
||
206 | |||
207 | if ($regionId === '') { |
||
208 | throw new ClientException( |
||
209 | 'Region ID cannot be empty', |
||
210 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
211 | ); |
||
212 | } |
||
213 | |||
214 | return $regionId; |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @param string $pattern |
||
219 | * |
||
220 | * @return string |
||
221 | * |
||
222 | * @throws ClientException |
||
223 | */ |
||
224 | public static function pattern($pattern) |
||
225 | { |
||
226 | if (!is_string($pattern)) { |
||
227 | throw new ClientException( |
||
228 | 'Pattern must be a string', |
||
229 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
230 | ); |
||
231 | } |
||
232 | |||
233 | if ($pattern === '') { |
||
234 | throw new ClientException( |
||
235 | 'Pattern cannot be empty', |
||
236 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
237 | ); |
||
238 | } |
||
239 | |||
240 | return $pattern; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @param string $roleName |
||
245 | * |
||
246 | * @return string |
||
247 | * |
||
248 | * @throws ClientException |
||
249 | */ |
||
250 | public static function roleName($roleName) |
||
251 | { |
||
252 | if (!is_string($roleName)) { |
||
253 | throw new ClientException( |
||
254 | 'Role Name must be a string', |
||
255 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
256 | ); |
||
257 | } |
||
258 | |||
259 | if ($roleName === '') { |
||
260 | throw new ClientException( |
||
261 | 'Role Name cannot be empty', |
||
262 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
263 | ); |
||
264 | } |
||
265 | |||
266 | return $roleName; |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * @param string $scheme |
||
271 | * |
||
272 | * @return string |
||
273 | * |
||
274 | * @throws ClientException |
||
275 | */ |
||
276 | public static function scheme($scheme) |
||
277 | { |
||
278 | if (!is_string($scheme)) { |
||
279 | throw new ClientException( |
||
280 | 'Scheme must be a string', |
||
281 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
282 | ); |
||
283 | } |
||
284 | |||
285 | if ($scheme === '') { |
||
286 | throw new ClientException( |
||
287 | 'Scheme cannot be empty', |
||
288 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
289 | ); |
||
290 | } |
||
291 | |||
292 | return $scheme; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @param $format |
||
297 | * |
||
298 | * @return mixed |
||
299 | * @throws ClientException |
||
300 | */ |
||
301 | public static function format($format) |
||
302 | { |
||
303 | if (!is_string($format)) { |
||
304 | throw new ClientException( |
||
305 | 'Format must be a string', |
||
306 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | if ($format === '') { |
||
311 | throw new ClientException( |
||
312 | 'Format cannot be empty', |
||
313 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
314 | ); |
||
315 | } |
||
316 | |||
317 | return $format; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @param $action |
||
322 | * |
||
323 | * @return mixed |
||
324 | * @throws ClientException |
||
325 | */ |
||
326 | public static function action($action) |
||
327 | { |
||
328 | if (!is_string($action)) { |
||
329 | throw new ClientException( |
||
330 | 'Action must be a string', |
||
331 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
332 | ); |
||
333 | } |
||
334 | |||
335 | if ($action === '') { |
||
336 | throw new ClientException( |
||
337 | 'Action cannot be empty', |
||
338 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
339 | ); |
||
340 | } |
||
341 | |||
342 | return $action; |
||
343 | } |
||
344 | |||
345 | /** |
||
346 | * @param $body |
||
347 | * |
||
348 | * @return mixed |
||
349 | * @throws ClientException |
||
350 | */ |
||
351 | public static function body($body) |
||
352 | { |
||
353 | if (!is_string($body) && !is_numeric($body)) { |
||
354 | throw new ClientException( |
||
355 | 'Body must be a string or int', |
||
356 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
357 | ); |
||
358 | } |
||
359 | |||
360 | if ($body === '') { |
||
361 | throw new ClientException( |
||
362 | 'Body cannot be empty', |
||
363 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
364 | ); |
||
365 | } |
||
366 | |||
367 | return $body; |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @param $endpointType |
||
372 | * |
||
373 | * @return mixed |
||
374 | * @throws ClientException |
||
375 | */ |
||
376 | public static function endpointType($endpointType) |
||
377 | { |
||
378 | if (!is_string($endpointType)) { |
||
379 | throw new ClientException( |
||
380 | 'Endpoint Type must be a string', |
||
381 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
382 | ); |
||
383 | } |
||
384 | |||
385 | if ($endpointType === '') { |
||
386 | throw new ClientException( |
||
387 | 'Endpoint Type cannot be empty', |
||
388 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
389 | ); |
||
390 | } |
||
391 | |||
392 | return $endpointType; |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * @param $method |
||
397 | * |
||
398 | * @return mixed |
||
399 | * @throws ClientException |
||
400 | */ |
||
401 | public static function method($method) |
||
402 | { |
||
403 | if (!is_string($method)) { |
||
404 | throw new ClientException( |
||
405 | 'Method must be a string', |
||
406 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
407 | ); |
||
408 | } |
||
409 | |||
410 | if ($method === '') { |
||
411 | throw new ClientException( |
||
412 | 'Method cannot be empty', |
||
413 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
414 | ); |
||
415 | } |
||
416 | |||
417 | return \strtoupper($method); |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @param $bearerToken |
||
422 | * |
||
423 | * @return mixed |
||
424 | * @throws ClientException |
||
425 | */ |
||
426 | public static function bearerToken($bearerToken) |
||
427 | { |
||
428 | if (!is_string($bearerToken)) { |
||
429 | throw new ClientException( |
||
430 | 'Bearer Token must be a string', |
||
431 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
432 | ); |
||
433 | } |
||
434 | |||
435 | if ($bearerToken === '') { |
||
436 | throw new ClientException( |
||
437 | 'Bearer Token cannot be empty', |
||
438 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
439 | ); |
||
440 | } |
||
441 | |||
442 | return $bearerToken; |
||
443 | } |
||
444 | |||
445 | /** |
||
446 | * @param $publicKeyId |
||
447 | * |
||
448 | * @return mixed |
||
449 | * @throws ClientException |
||
450 | */ |
||
451 | public static function publicKeyId($publicKeyId) |
||
452 | { |
||
453 | if (!is_string($publicKeyId)) { |
||
454 | throw new ClientException( |
||
455 | 'Public Key ID must be a string', |
||
456 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
457 | ); |
||
458 | } |
||
459 | |||
460 | if ($publicKeyId === '') { |
||
461 | throw new ClientException( |
||
462 | 'Public Key ID cannot be empty', |
||
463 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
464 | ); |
||
465 | } |
||
466 | |||
467 | return $publicKeyId; |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * @param $privateKeyFile |
||
472 | * |
||
473 | * @return mixed |
||
474 | * @throws ClientException |
||
475 | */ |
||
476 | public static function privateKeyFile($privateKeyFile) |
||
477 | { |
||
478 | if (!is_string($privateKeyFile)) { |
||
479 | throw new ClientException( |
||
480 | 'Private Key File must be a string', |
||
481 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
482 | ); |
||
483 | } |
||
484 | |||
485 | if ($privateKeyFile === '') { |
||
486 | throw new ClientException( |
||
487 | 'Private Key File cannot be empty', |
||
488 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
489 | ); |
||
490 | } |
||
491 | |||
492 | return $privateKeyFile; |
||
493 | } |
||
494 | |||
495 | /** |
||
496 | * @param $version |
||
497 | * |
||
498 | * @return mixed |
||
499 | * @throws ClientException |
||
500 | */ |
||
501 | public static function version($version) |
||
502 | { |
||
503 | if (!is_string($version)) { |
||
504 | throw new ClientException( |
||
505 | 'Version must be a string', |
||
506 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
507 | ); |
||
508 | } |
||
509 | |||
510 | if ($version === '') { |
||
511 | throw new ClientException( |
||
512 | 'Version cannot be empty', |
||
513 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
514 | ); |
||
515 | } |
||
516 | |||
517 | return $version; |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * @param $serviceCode |
||
522 | * |
||
523 | * @return mixed |
||
524 | * @throws ClientException |
||
525 | */ |
||
526 | public static function serviceCode($serviceCode) |
||
527 | { |
||
528 | if (!is_string($serviceCode)) { |
||
529 | throw new ClientException( |
||
530 | 'Service Code must be a string', |
||
531 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
532 | ); |
||
533 | } |
||
534 | |||
535 | if ($serviceCode === '') { |
||
536 | throw new ClientException( |
||
537 | 'Service Code cannot be empty', |
||
538 | \ALIBABA_CLOUD_INVALID_ARGUMENT |
||
539 | ); |
||
540 | } |
||
541 | |||
542 | return $serviceCode; |
||
543 | } |
||
544 | |||
545 | /** |
||
546 | * @param $connectTimeout |
||
547 | * |
||
548 | * @return mixed |
||
549 | * @throws ClientException |
||
550 | */ |
||
551 | public static function connectTimeout($connectTimeout) |
||
561 | } |
||
562 | |||
563 | /** |
||
564 | * @param $timeout |
||
565 | * |
||
566 | * @return mixed |
||
567 | * @throws ClientException |
||
568 | */ |
||
569 | public static function timeout($timeout) |
||
579 | } |
||
580 | } |
||
581 |