Passed
Push — master ( 9219b1...2632c0 )
by Dmitry
01:25
created

Report::integratedGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 34
rs 9.7
cc 1
nc 1
nop 14

How to fix   Many Parameters   

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
declare(strict_types=1);
4
5
namespace Promopult\TikTokMarketingApi\Service;
6
7
final class Report extends \Promopult\TikTokMarketingApi\AbstractService
8
{
9
10
    /**
11
     * Create an Integrated Report
12
     *
13
     * @param int $advertiserId     Advertiser ID
14
     * @param string $serviceType   Ad service type. Optional values: AUCTION, RESERVATION
15
     * @param string $reportType    Report type
16
     * @param array $dimensions     Grouping conditions. Auction and Reservation Ads support different dimensions.
17
     * @param array $metrics        Metrics to query. Defaut: ["spend," "impressions"]
18
     * @param ?string $startDate    Query start date, format such as: 2020-01-01, required when lifetime = false
19
     * @param ?string $endDate      Query end date, format such as: 2020-01-01, required when lifetime = false
20
     * @param bool $lifetime        Whether to request the lifetime metrics. The lifetime metric name is the same as
21
     *                              the normal one. If lifetime = true, the start_date and end_date parameters will
22
     *                              be ignored.
23
     * @param ?array $filters       Filter criteria. Supported filtering criteria vary according to 'service_type' and
24
     *                              'data_level'
25
     * @param ?string $dataLevel    Reporting data level. Required when report_type is BASIC,AUDIENCE or CATALOG
26
     * @param ?string $orderField   Sort field. All supported metrics (excluding attribute metrics) support sorting,
27
     *                              not sorting by default
28
     * @param ?string $orderType    Sort. Optional value: ASC, DESC. Default value: DESC
29
     * @param ?int $page            Current number of pages. Default value: 1
30
     * @param ?int $pageSize        Pagination size. Default value: 10
31
     *
32
     * @return array
33
     *
34
     * @throws \Throwable
35
     *
36
     * @see https://ads.tiktok.com/marketing_api/docs?id=1685752851588097
37
     */
38
    public function integratedGet(
39
        int $advertiserId,
40
        string $serviceType,
41
        string $reportType,
42
        array $dimensions,
43
        array $metrics,
44
        bool $lifetime = false,
45
        ?string $startDate = null,
46
        ?string $endDate = null,
47
        ?array $filters = null,
48
        ?string $dataLevel = null,
49
        ?string $orderField = null,
50
        ?string $orderType = null,
51
        ?int $page = null,
52
        ?int $pageSize = null
53
    ): array {
54
        return $this->requestApi(
55
            'GET',
56
            '/open_api/v1.2/reports/integrated/get/',
57
            [
58
                'advertiser_id' => $advertiserId,
59
                'service_type' => $serviceType,
60
                'report_type' => $reportType,
61
                'data_level' => $dataLevel,
62
                'dimensions' => $dimensions,
63
                'metrics' => $metrics,
64
                'start_date' => $startDate,
65
                'end_date' => $endDate,
66
                'lifetime' => $lifetime,
67
                'order_field' => $orderField,
68
                'order_type' => $orderType,
69
                'filters' => $filters,
70
                'page' => $page,
71
                'page_size' => $pageSize
72
            ]
73
        );
74
    }
75
}
76