Passed
Push — master ( b8b318...ae3161 )
by Dmitry
13:51
created

Creatives::reportsGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 30
rs 9.7666
cc 1
nc 1
nop 12

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
use Promopult\TikTokMarketingApi\AbstractService;
8
9
final class Creatives extends AbstractService
10
{
11
    /**
12
     * Creative Asset Level reporting is essential to understand how an advertiser's creative assets resonated with
13
     * their target audience. This information can then be used to improve future creatives and refine audiences.
14
     * Developers can return performance metrics at the creative asset level as well as creative asset attributes like
15
     * height, width, and more.
16
     *
17
     * @param int $advertiserId         Advertiser ID
18
     * @param string $materialType      Material type. Optional value: VIDEO, IMAGE
19
     * @param array $infoFields         Use to specify whether to query all data
20
     * @param array $metricFields       The metrics or dimension data that you need
21
     * @param string|null $startDate    Start time, closed interval. Format such as: 2020-01-01 (advertiser time zone)
22
     * @param string|null $endDate      End time, closed interval. Format such as: 2020-01-01 (advertiser time zone)
23
     * @param bool|null $lifetime       Use to specify whether to query all data. If so, you do not need to specify
24
     *                                  start_date and end_date.
25
     * @param array|null $filtering     Filtering criteria
26
     * @param string|null $orderField   Sort fields. Support sorting according to the creation time of the material
27
     *                                  and all the index data. Not sorted by default
28
     * @param string|null $orderType    Sort by. Optional values: ASC, DESC. Default: DESC
29
     * @param int|null $page            Current number of pages. Default value: 1, range: ≥ 1
30
     * @param int|null $pageSize        Page size. Default value: 10, range: 1-1000
31
     *
32
     * @return array
33
     *
34
     * @throws \Throwable
35
     *
36
     * @see https://ads.tiktok.com/marketing_api/docs?id=1701890967858177
37
     */
38
    public function reportsGet(
39
        int $advertiserId,
40
        string $materialType,
41
        array $infoFields,
42
        array $metricFields,
43
        ?string $startDate,
44
        ?string $endDate,
45
        ?bool $lifetime = null,
46
        ?array $filtering = null,
47
        ?string $orderField = null,
48
        ?string $orderType = null,
49
        ?int $page = null,
50
        ?int $pageSize = null
51
    ): array {
52
        return $this->requestApi(
53
            'GET',
54
            '/open_api/v1.2/creative/reports/get/',
55
            [
56
                'advertiser_id' => $advertiserId,
57
                'material_type' => $materialType,
58
                'info_fields' => $infoFields,
59
                'metric_fields' => $metricFields,
60
                'lifetime' => $lifetime,
61
                'start_date' => $startDate,
62
                'end_date' => $endDate,
63
                'filtering' => $filtering,
64
                'order_field' => $orderField,
65
                'order_type' => $orderType,
66
                'page' => $page,
67
                'page_size' => $pageSize,
68
            ]
69
        );
70
    }
71
}
72